我正在制作一个API测试函数,其中包括在同一测试中发送两次post请求。
第一个请求成功并且没有问题,我可以毫无问题地断言响应。 但是,在第二个请求中,找不到路由,响应会立即返回404 error
。 即使我使用相同的请求。
以下是测试函数的外观:
public function tesAbc(ApiTester $I)
{
$I->haveHttpHeader('Accept', 'application/json');
$request = [
'username' => 'abc',
'password' => 'testABc',
'data' => [
'param1' => '123',
'param2' => '456'
]
];
/* the first request, response always 200 */
$I->sendPOST('confirmation/slot', $request);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
/* the second request, response always 404 */
$I->sendPOST('confirmation/slot', $request);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->dontSeeResponseJsonMatchesJsonPath('$.data[*]');
}
问题是你使用了相对的 URIconfirmation/slot
。
第一个请求转到/confirmation/slot
然后第二个请求与此相关,它转到'/confirmation/confirmation/slot。
解决方案很简单,在 URI 中使用前导/:
$I->sendPOST('/confirmation/slot', $request);