gpt4 book ai didi

laravel - 在多个请求上测试 Api 404

转载 作者:行者123 更新时间:2023-12-02 04:58:48 27 4
gpt4 key购买 nike

我正在尝试测试我的 api 上的所有路由,但只有第一个请求得到 200,所有其他后续请求得到 404。但是如果我使用 (phpunit --filter test_something) 单独运行任何测试,它就会起作用。

<?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?

最佳答案

我认为您需要解决 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

关于laravel - 在多个请求上测试 Api 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37358894/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com