gpt4 book ai didi

laravel-5 - Laravel 测试 : assertJsonFragment fails if multiple levels need to be checked

转载 作者:行者123 更新时间:2023-12-03 06:50:17 28 4
gpt4 key购买 nike

这是回复:

[  
{
"data":{
"locales":{
"translate":[
{
"created_at":"2018-05-28 12:49:53",
"deleted_at":null,
"id":1,
"key":"nl_NL",
"name":"Netherlands (Nederlands)",
"updated_at":"2018-05-28 12:49:53"
}
],
"validate":[
{
"created_at":"2018-05-28 12:49:53",
"deleted_at":null,
"id":2,
"key":"it_IT",
"name":"Italian (Italiano)",
"updated_at":"2018-05-28 12:49:53"
}
]
}
},
"error":false,
"message":null
}
]

我想断言以下片段是响应的一部分:

1) ['translate' => [['key' => 'nl_NL']]]
2) ['validate' => [['key' => 'it_IT']]]

有没有办法断言 translate 数组至少包含一个键为 nl_NL 的元素,并且 validate 包含一个键为 nl_NL 的元素it_IT 的键?

$response->assertSuccessful()->assertJsonFragment([
'translate' => [['key' => 'nl_NL']],
'validate' => [['key' => 'it_IT']
]);

最佳答案

这对于 assertJsonFragment() 来说是不可能的。

你可以这样做:

$this->assertTrue(
collect($response->decodeResponseJson('0.data.locales.translate'))
->pluck('key')->contains('nl_NL')
);

关于laravel-5 - Laravel 测试 : assertJsonFragment fails if multiple levels need to be checked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50579641/

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