Say we have the following array, $myArray, to check as per var_export:
array (
0 => AnObject::__set_state(array(
'id' => 10,
'name' => 'foo'
)),
1 => AnObject::__set_state(array(
'id' => 23,
'name' => 'bar'
)),
2 => AnObject::__set_state(array(
'id' => 55,
'name' => 'baz'
)),
)
The assertion should pass if this array contains an AnObject which has a name of 'bar'.
I know that if I knew the position of the AnObject value, I could use:
$this->assertAttributeSame('bar', 'name', $myArray[1]);
Is there some way to use $this->assertThat(), or another type of contains to check the entire array and return true of one of the objects has the attribute that matches?
There is no such built-in assertion and I cannot think of any possibility to combine them to get the expected result.
What I recommend you – is to create a helper method that accepts an array and does the necessary check in a loop.
Other solution is to create completely new assertion just for this case, but I think it is an overkill for this task 😉