【问题标题】:Mockery NoMatchingExpectationException thrown when using with(Mockery::on(Closure))使用 with(Mockery::on(Closure)) 时抛出 Mockery NoMatchingExpectationException
【发布时间】:2016-12-26 17:56:52
【问题描述】:

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

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

我的测试顺利通过。但是,如果我尝试:

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

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

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

知道为什么会抛出异常吗?

【问题讨论】:

  • 真正的sendDonationMail方法的签名是什么?
  • 为问题添加了签名。

标签: php mockery


【解决方案1】:

您必须为所有参数设置期望值,目前您仅使用闭包验证 $lender 参数。

这应该例如:

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

【讨论】:

    猜你喜欢
    • 2014-09-05
    • 2013-08-26
    • 2017-04-30
    • 2014-03-25
    • 2016-10-26
    • 2022-01-04
    • 2016-10-01
    • 1970-01-01
    • 2014-12-24
    相关资源
    最近更新 更多