【发布时间】:2017-10-27 13:01:56
【问题描述】:
我正在尝试构建一个使用 laravel 的应用程序。有一个测试目录,我用它来测试应用程序。
但我在 app/MyApp/Service 目录中有一个服务。这是目录结构。
app/MyApp/Service
|-->Services
|-->Interfaces
|-->Test
|------->OLSServiceTest.php
这里是 OLSServiceTest.php 内容
<?php
namespace App\MyApp\Service\Test;
class OLSServiceTest extends TestCase
{
public function testInfo()
{
$this->assertTrue(true);
}
public function testLogin()
{
$this->assertTrue(false);
}
/**
* Creates the application.
*
* Needs to be implemented by subclasses.
*
* @return \Symfony\Component\HttpKernel\HttpKernelInterface
*/
public function createApplication()
{
// TODO: Implement createApplication() method.
}
}
然后我尝试手动运行测试
$ vendor/phpunit/phpunit/phpunit App\\MyApp\\Service\\Test\\OLSServiceTest
但是得到这个错误:
[Symfony\Component\Debug\Exception\FatalErrorException]
无法声明类 App\MyApp\Service\Test\OLSServiceTest,因为 该名称已被使用致命错误:无法声明类 App\MyApp\Service\Test\OLSServiceTest,因为名字已经在 在第 29 行的 /var/www/app/MyApp/Service/Test/OLSServiceTest.php 中使用
我做错了什么?
【问题讨论】:
-
您在该命名空间中还有其他同名的类吗?您可以尝试使用类的不同名称吗?
-
没办法,当我更改名称时,我收到新名称的错误。
-
您是否尝试过使用路径而不是命名空间来运行测试?供应商/phpunit/phpunit/phpunit app/MyApp/Service/Test/OLSServiceTest.php ?
-
当我尝试使用路径时工作,比你非常多@shivanshupatel
-
酷我已经发布了同样的事情它的答案你可以将它标记为正确,如果它有效:) 祝你好运