【问题标题】:How to test a specific argument of a mocked PHPUnit method如何测试模拟 PHPUnit 方法的特定参数
【发布时间】:2013-04-05 07:06:48
【问题描述】:

我的方法有3个参数,但我只想测试arg3,arg1和arg2没关系:

$observer = $this->getMock('SomeObserverClass', array('myMethod'));
$observer->expects($this->once())
         ->method('myMethod')
         ->with(null, null, $this->equalTo($arg3));

将它们设置为 null 或 !$this->empty() 不起作用。

方法的签名:

public function myMethod(Integer $arg1, String $arg2, String $arg3) {...}

【问题讨论】:

    标签: mocking arguments phpunit


    【解决方案1】:

    您可以使用anything 匹配器。试试:

    $observer->expects($this->once())
         ->method('myMethod')
         ->with($this->anything(), $this->anything(), $this->equalTo($arg3));
    

    【讨论】:

    • 感谢您的回答。我会尽快尝试。
    猜你喜欢
    • 2019-03-13
    • 2017-02-27
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    • 1970-01-01
    • 1970-01-01
    • 2010-09-23
    • 1970-01-01
    相关资源
    最近更新 更多