在我们之前的应用程序中,使用 Laravel 5.3,设置 processIsolation
false 加速了我们的测试而不会导致任何错误:
phpunit.xml:
<phpunit backupGlobals="false"
...
processIsolation="false"
stopOnFailure="false">
在我们当前的项目中,在 laravel 5.4 中,设置
processIsolation
为 false 导致我们所有的功能测试失败(尽管它们确实更快)(为简洁起见,删除了一些):5) Tests\Feature\CallsToActionApiControllerTest::testUsers
Symfony\Component\HttpKernel\Exception\NotFoundHttpException:
/johnny/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:161
/johnny/vendor/laravel/framework/src/Illuminate/Routing/Router.php:533
/johnny/vendor/laravel/framework/src/Illuminate/Routing/Router.php:512
/johnny/vendor/laravel/framework/src/Illuminate/Routing/Router.php:498
/johnny/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:174
/johnny/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
/johnny/vendor/barryvdh/laravel-cors/src/HandleCors.php:34
/johnny/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:148
...
/johnny/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
/johnny/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:149
/johnny/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
/johnny/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:234
/johnny/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:206
/johnny/tests/Functional/CallsToAction/CallsToActionApiControllerTest.php:142
...
7) Tests\Feature\EmailEndpointControllerTest::testCaptureEventsWithBlankRequest
Expected status code 200 but received 404.
Failed asserting that false is true.
/johnny/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:55
/johnny/tests/Functional/Email/EmailActionApiControllerTest.php:88
8) Tests\Feature\EmailEndpointControllerTest::testUnsubscribe
Expected status code 200 but received 404.
Failed asserting that false is true.
/johnny/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:55
/johnny/tests/Functional/Email/EmailActionApiControllerTest.php:96
9) Tests\Feature\EmailEndpointControllerTest::testUnsubscribeWithAlreadyUnsubscribedEmail
Expected status code 200 but received 404.
Failed asserting that false is true.
/johnny/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:55
/johnny/tests/Functional/Email/EmailActionApiControllerTest.php:108
ERRORS!
Tests: 72, Assertions: 79, Errors: 21, Failures: 9.
Script ./vendor/bin/phpunit handling the test event returned with error code 2
它们都是 404 错误,或 NotFoundHttpException 错误。
我们早期的项目是 laravel 5.3 和 phpunit 5.5;我们当前损坏的项目是 laravel 5.4 和 phpunit 5.7。我注意到两个 Laravel 之间的一个变化是
app.php
中的应用程序 URL从改变'url' => 'http://localhost'
到
'url' => env('APP_URL', 'http://localhost'),
但是把它改回来没有任何作用。请帮忙——我们的测试需要 10 分钟而不是 10 秒。
最佳答案
我知道这是一个古老的帖子,但我遇到了同样的问题,我先找到了这个页面,然后找到了解决方案,所以如果有人遇到同样的问题并先停在这里,我希望这个解决方案对你有用。
感谢 ,该解决方案对我有用boydcl 在
https://github.com/dingo/api/issues/1243
就我而言,我使用的是“require_once”而不是“require”,这解决了我的问题,
$path = __DIR__ . '/../routes/api.php';
if (defined('PHPUNIT_TESTING_SESSION')) {
require $path;
return;
}
require_once $path;
您可以像这样在 phpunit.xml 中添加常量“PHPUNIT_TESTING_SESSION”:<const name="PHPUNIT_TESTING_SESSION" value="true"/>
关于php - 在 phpunit.xml 中将进程隔离设置为 false 会导致 Laravel 功能测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43242806/