How can I use mockery and hamcrest to assert that when a method of a mock object is called, one of the arguments passed to it is an array containing a key/value pair?
For example, my test code might look like this:
$mock = m::mock('\Jodes\MyClass');
$mock ->shouldReceive('myMethod')
->once()
->with(
arrayContainsPair('my_key', 'my_value')
);
I know I could write it with a closure, but I was just wondering if there's another way of making it read slightly better:
$mock ->shouldReceive('myMethod')
->once()
->with(
m::on(function($options){
return
is_array($options) &&
isset($options['my_key']) &&
$options['my_key'] == 'my_val';
})
);