Hi, I'm trying to test all the routes on my api but only the first request gets 200, all following requests get 404, but when I run any test individually (phpunit --filter test_something) they work.
<?php
class ProgramTest extends TestCase {
/** @test */
public function it_returns_index() {
$this->get('api/v1/test')
->assertReturnOk(['limit' => 10]);
}
/** @test */
public function it_returns_show() {
$this->get('api/v1/test/12')
->seeJson(['id' => 12]);
}
}
PHPUnit 4.8.23 by Sebastian Bergmann and contributors.
.F
Time: 2.33 seconds, Memory: 20.25Mb
There was 1 failure:
1) ProgramTest::it_returns_show
Invalid JSON was returned from the route. Perhaps an exception was thrown?
You don't have to access phpunit's xpath because your TestCase class boots up with an application instance, so you already have access to App::environment() Facade or even better you have access to app()->environment() helper, so your code can be simpler like this:
foreach (File::allFiles(__DIR__ . '/Routes') as $partial) {
if (app()->environment('testing')) {
require $partial->getPathname();
} else {
require_once $partial->getPathname();
}
}