chiefguru's avatar

Default Feature Test fails with 404 error

I have a clean L8 installation running under MAMP 6.0 on a Mac and I'm using PHPStorm as IDE.

When I try and run the test tests/Feature/ExampleTest.php from within Storm, the assertion fails with a 404 error. It also fails when run from artisan, so my Storm config isn't the issue.

My APP_URL is set correctly to run the app APP_URL=http://localhost:8888/Laravel8/simple-site/public/ in the browser. If I simplify the URL to http://localhost:8888/ the test works.

I'm tearing what little hair I have out over this, what basic, simple, in your face configuration have I overlooked.

Testing started at 10:20 am ... /Applications/MAMP/bin/php/php7.4.9/bin/php /Users/brett/Working/WebHome/Laravel8/simple-site/vendor/phpunit/phpunit/phpunit --configuration /Users/brett/Working/WebHome/Laravel8/simple-site/phpunit.xml /Users/brett/Working/WebHome/Laravel8/simple-site/tests/Feature --teamcity PHPUnit 9.4.2 by Sebastian Bergmann and contributors.

Expected status code 200 but received 404. Failed asserting that 200 is identical to 404. /Users/brett/Working/WebHome/Laravel8/simple-site/vendor/laravel/framework/src/Illuminate/Testing/TestResponse.php:186 /Users/brett/Working/WebHome/Laravel8/simple-site/tests/Feature/ExampleTest.php:19

0 likes
2 replies
chiefguru's avatar

192-168-1-6:simple-site brett$ ./vendor/phpunit/phpunit/phpunit PHPUnit 9.4.2 by Sebastian Bergmann and contributors.

.F 2 / 2 (100%)

Time: 00:01.491, Memory: 20.00 MB

There was 1 failure:

  1. Tests\Feature\ExampleTest::testBasicTest Expected status code 200 but received 404. Failed asserting that 200 is identical to 404.

/Users/brett/Working/WebHome/Laravel8/simple-site/vendor/laravel/framework/src/Illuminate/Testing/TestResponse.php:186 /Users/brett/Working/WebHome/Laravel8/simple-site/tests/Feature/ExampleTest.php:19

FAILURES! Tests: 2, Assertions: 2, Failures: 1.

and if I use artisan

192-168-1-6:simple-site brett$ php artisan test

PASS Tests\Unit\ExampleTest ✓ basic test

FAIL Tests\Feature\ExampleTest ⨯ basic test

• Tests\Feature\ExampleTest > basic test Expected status code 200 but received 404. Failed asserting that 200 is identical to 404.

at tests/Feature/ExampleTest.php:19 15▕ public function testBasicTest() 16▕ { 17▕ $response = $this->get('/'); 18▕ ➜ 19▕ $response->assertStatus(200); 20▕ } 21▕ } 22▕

Tests: 1 failed, 1 passed Time: 0.47s

Please or to participate in this conversation.