php - Mockery: test if argument is an array containing a key/value pair -


how can use mockery , hamcrest assert when method of mock object called, 1 of arguments passed array containing key/value pair?

for example, test code might this:

$mock = m::mock('\jodes\myclass');  $mock   ->shouldreceive('mymethod')         ->once()         ->with(                     arraycontainspair('my_key', 'my_value')                 ); 

i know write closure, wondering if there's way of making read better:

$mock   ->shouldreceive('mymethod')         ->once()         ->with(                 m::on(function($options){                     return                          is_array($options) &&                         isset($options['my_key']) &&                         $options['my_key'] == 'my_val';                 })             ); 

i found answer looking through hamcrest php code here,

the function name given away in doc comment:

 * @factory hasentry 

so code this:

$mock   ->shouldreceive('mymethod')         ->once()         ->with(                     hasentry('my_key', 'my_value')                 ); 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -