2
使用PHPUnit进行测试,我的测试在函数上失败。但我不知道为什么。 的功能,我想嘲笑:Mockery Exception NoMatchingExpectationException PHPUnit测试失败
public function subscribe($email)
{
$message = new SubscribeMessage();
$message->setEmailaddress($email);
$message->setLocale(Locale::getDefault());
$this->getAmqpProducer()->publish($message, 'newsletter-subscribe');
return true;
}
和我的单元测试:
public function testSubscribeSendsAmqpMessage()
{
$email = '[email protected]';
$locale = 'nl';
$this->amqpProducerMock
->shouldReceive('publish')
->once()
->with(
\Mockery::on(
function ($message, $routingkey) use (&$publishedMessage) {
$publishedMessage = $message;
return $routingkey == 'newsletter-subscribe';
}
)
);
$this->service->subscribe($email, $locale);
}
但测试说:
Mockery\Exception\NoMatchingExpectationException : No matching handler found for AcsiRabbitMq\Producer\Producer::publish(AcsiNewsletter\RabbitMq\Message\SubscribeMessage, "newsletter-subscribe"). Either the method was unexpected or its arguments matched no expected argument list for this method
如何解决我的单元测试?或者我如何重构我的测试?
这篇帮助您解决问题?只需检查以便您可以接受帮助他人的答案,或者如果您需要任何其他信息,我可以调整我的答案。 –