Laravel测试在运行整个测试套件时不起作用,ReflectionException:类配置不存在

时间:2018-11-20 12:19:29

标签: php laravel phpunit lumen

我目前正在为我的流明API开发一个测试套件。我正在将lumen 5.6与phpunit 7一起使用。

我进行了以下测试:

use PHPUnit\Framework\TestCase;

class ExportControllerTest extends TestCase
{

    public function testGetHeader()
    {
        $controller = app()->make("App\Http\Controllers\ExportController");
        $header = $controller->getHeader();
        self::assertNotNull($header);

        self::assertEquals($header[0], "title");
    }

 }

使用TestCase.php

namespace Tests;

abstract class TestCase extends \Laravel\Lumen\Testing\TestCase
{
    /**
     * Creates the application.
     *
     * @return \Laravel\Lumen\Application
     */
    public function createApplication()
    {
        return require __DIR__.'/../bootstrap/app.php';
    }

}

当我分别使用以下命令运行测试时,它运行良好:

  

phpunit --bootstrap path_to_project \ bootstrap \ app.php-配置   path_to_project \ phpunit.xml   path_to_project \ tests \ app \ Http \ Controllers \ ExportControllerTest.php

B,但是当我尝试使用以下命令运行整个测试套件时:

  

phpunit --bootstrap path_to_project \ bootstrap \ app.php-配置   path_to_project \ phpunit.xml path_to_project \ tests

我收到以下错误:

ReflectionException : Class config does not exist
 path_to_project\vendor\laravel\framework\src\Illuminate\Container\Container.php:767
 path_to_project\vendor\laravel\framework\src\Illuminate\Container\Container.php:646
 path_to_project\vendor\laravel\framework\src\Illuminate\Container\Container.php:601
 path_to_project\vendor\laravel\lumen-framework\src\Application.php:223
 path_to_project\vendor\laravel\framework\src\Illuminate\Container\Container.php:1210
 path_to_project\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:259
 path_to_project\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:89
 path_to_project\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:65
 path_to_project\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:327
 path_to_project\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:223
 path_to_project\app\Services\RawQueryService.php:114
 path_to_project\app\Services\RawQueryService.php:81
 path_to_project\app\Services\RawQueryService.php:37
 path_to_project\app\Services\SearchService.php:56
 path_to_project\app\Http\Controllers\ExportController.php:83
 path_to_project\tests\app\Http\Controllers\ExportControllerTest.php:19

配置phpunit.xml在哪里:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="bootstrap/app.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Application test Suite">
            <directory suffix="Test.php">./tests</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
        <env name="DB_PORT" value="11009"/>
        <env name="DB_DATABASE" value="test"/>
        <env name="DB_HOST" value="localhost"/>
        <env name="DB_USERNAME" value="null"/>
        <env name="DB_PASSWORD" value="null"/>
    </php>
</phpunit>

.env文件中的所有属性都不包含空格,正如我注意到的那样,通常将其列为导致此错误的原因。

任何人都知道什么可能导致此问题?

提前谢谢!

0 个答案:

没有答案