给出了API调用返回的JSON:
{
"data": [
{
"id": 1,
}
],
"meta" {
"foo": "bar"
},
"links": {
"self": "/"
}
执行以下代码时:文章源自玩技e族-https://www.playezu.com/191316.html
$response
->assertOk()
->assertJson(fn (AssertableJson $json) =>
$json
->has('data')
);
我的测试失败,出现以下错误:文章源自玩技e族-https://www.playezu.com/191316.html
Unexpected properties were found on the root level.
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
-Array &0 ()
+Array &0 (
+ 1 => 'links'
+ 2 => 'meta'
+)
我认为断言只会检查响应中是否存在“data”键。
使用时 $json->;hasAll(['data',meta',links'])
测试成功。文章源自玩技e族-https://www.playezu.com/191316.html
培训软件测试文章源自玩技e族-https://www.playezu.com/191316.html 文章源自玩技e族-https://www.playezu.com/191316.html