使用时抛出Mockery NoMatchingExpectationException(Mockery :: on(Closure))

时间:2016-08-19 14:16:43

标签: php mockery

我有一个有趣的问题。执行时......

$lenderMailer->shouldReceive('sendDonationMail')->once();

我的测试没有问题。但是,如果我尝试:

$lenderMailer->shouldReceive('sendDonationMail')->once()->with(\Mockery::on(function(){
    return true;
}));

我收到NoMatchingExpectationException。 sendDonationMail方法的签名是

public function sendDonationMail(Lender $lender, Money $donationAmount)

为什么会抛出异常?

1 个答案:

答案 0 :(得分:0)

你必须设置所有参数的期望值,目前你只是用你的闭包来验证$lender参数。

这应该起作用,例如:

$lenderMailer->shouldReceive('sendDonationMail')->once()->with(\Mockery::on(function(){ return true; }), \Mockery::any());