Assert key => value pair exists with the arrays of array
The following array is returned (not http call):
[
[
'order_id' => '123',
],
[
'order_id' => '124',
],
]
how do I assert that 'order_id' => '124' exists within the returned array?
@dmag may be like this?
$array = [
[
'order_id' => '123',
],
[
'order_id' => '124',
],
];
$collection = collect($array)->pluck('order_id')->toArray(); // or collect($array)->flatten()->all();
dd(in_array('124', $collection));
if (collect($arr)->firstWhere('order_id', '123'))
@Sinnbeck I was hoping there was phpunit specific assertion for that, which I wasn't aware of.
@dmag Not to my knowledge. But you can easily convert it to an assertion
$this->assertNotNull(collect($arr)->firstWhere('order_id', '123'));
Please or to participate in this conversation.