Reputation: 3544
On our previous app, using Laravel 5.3, setting processIsolation
to false sped up our tests without causing any errors:
phpunit.xml:
<phpunit backupGlobals="false"
...
processIsolation="false"
stopOnFailure="false">
On our current project, in laravel 5.4, setting processIsolation
to false causes all of our functional tests to fail (though they are indeed faster) (some removed for brevity):
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
They are all 404 errors, or NotFoundHttpException errors.
Our working earlier project was laravel 5.3 and phpunit 5.5; our current broken project is laravel 5.4 and phpunit 5.7. I noticed one change between the two laravels was that the application URL in app.php
changed from
'url' => 'http://localhost'
to
'url' => env('APP_URL', 'http://localhost'),
But changing it back didn't do anything. Please help -- our tests take 10 minutes instead of 10 seconds.
Upvotes: 5
Views: 2940
Reputation: 161
I know this is an ancient post, but I had the same problem, I found this page first and later the solution, so if someone has the same problem and stops here first I hope this solution works for you.
The solution works for me thanks to boydcl at https://github.com/dingo/api/issues/1243
In my case, I was using 'require_once' instead of 'require', this fixed my issue,
$path = __DIR__ . '/../routes/api.php';
if (defined('PHPUNIT_TESTING_SESSION')) {
require $path;
return;
}
require_once $path;
You can add the constant 'PHPUNIT_TESTING_SESSION' in your phpunit.xml like this:
<const name="PHPUNIT_TESTING_SESSION" value="true"/>
Upvotes: 2