Ho una classe che ho bisogno di prendere in giro:Mockery - call_user_func_array() si aspetta parametro 1 per essere un callback valida
class MessagePublisher
{
/**
* @param \PhpAmqpLib\Message\AMQPMessage $msg
* @param string $exchange - if not provided then one passed in constructor is used
* @param string $routing_key
* @param bool $mandatory
* @param bool $immediate
* @param null $ticket
*/
public function publish(AMQPMessage $msg, $exchange = "", $routing_key = "", $mandatory = false, $immediate = false, $ticket = null)
{
if (empty($exchange)) {
$exchange = $this->exchangeName;
}
$this->channel->basic_publish($msg, $exchange, $routing_key, $mandatory, $immediate, $ticket);
}
}
Sto usando Mockery 0.7.2
$mediaPublisherMock = \Mockery::mock('MessagePublisher')
->shouldReceive('publish')
->withAnyArgs()
->times(3)
->andReturn(null);
purtroppo i miei test fallito , a causa di questo errore
call_user_func_array() si aspetta parametro 1 per essere un callback valida, classe 'Mockery \ Expec zione' non ha un metodo 'pubblicare' in /vendor/mockery/mockery/library/Mockery/CompositeExpectation.php on line 54
ho cercato di eseguire il debug ho scoperto che i test non riesce in questo codice
public function __call($method, array $args)
{
foreach ($this->_expectations as $expectation) {
call_user_func_array(array($expectation, $method), $args);
}
return $this;
}
dove
metodo $ = 'pubblicare'
$ args = array()
$ aspettativa è istanza di oggetto Expectation derisione \()
Sto usando php 5.3.10 - Qualche idea di cosa c'è che non va?
o dividere il codice in due righe: $ mediaPublisherMock = \ Mockery :: mock ('MessagePublisher'); $ mediaPublisherMock> shouldReceive ('publish') -> withAnyArgs() -> times (3) -> andReturn (null); Questa era la mia soluzione. –
Uomo .... sei un risparmiatore di vita. -> getMock() è esattamente quello che mi manca da 2 giorni –