给出了API调用返回的JSON:
{
"data": [
{
"id": 1,
}
],
"meta" {
"foo": "bar"
},
"links": {
"self": "/"
}
执行以下代码时:
$response
->assertOk()
->assertJson(fn (AssertableJson $json) =>
$json
->has('data')
);
我的测试失败,出现以下错误:
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']) 测试成功。
培训软件测试
