Laravel在自定义目录中进行测试 - 获取错误“该名称已被使用”

时间:2017-05-26 15:10:12

标签: php laravel lumen

我正在尝试构建一个使用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的\元器件\调试\异常\ FatalErrorException]
  无法声明类App \ MyApp \ Service \ Test \ OLSServiceTest,因为   该名称已被使用

     

致命错误:无法声明类   App \ MyApp \ Service \ Test \ OLSServiceTest,因为名称已经在   在第29行的/var/www/app/MyApp/Service/Test/OLSServiceTest.php中使用

我做错了什么?

1 个答案:

答案 0 :(得分:1)

好像你正试图用错误的命令运行测试。尝试使用Vendor bin目录中的PHPUnit我认为它将解决您的问题。

vendor/bin/phpunit app/MyApp/Service/Test/OLSServiceTest.php