我正在尝试测试我的api上的所有路由,但只有第一个请求获得200,所有其他后续请求获得404.但是如果我使用(phpunit --filter test_something)单独运行任何测试,它就可以工作。 / p>
<?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?
答案 0 :(得分:2)
我认为你需要解决Routes.php中的问题。我在下面的链接中看到过类似的问题。希望这能解决你。完成的路线修改如下面的链接
$phpunit = simplexml_load_file('phpunit.xml');
foreach (File::allFiles(__DIR__ . '/Routes') as $partial) {
if ($phpunit->php->xpath('env[@name="APP_ENV"]')[0]['value'] == 'testing') {
require $partial->getPathname();
} else {
require_once $partial->getPathname();
}
}
https://laracasts.com/discuss/channels/testing/test-api-404-on-multiple-requests