如何返回模拟方法的参数?

时间:2013-05-02 00:39:02

标签: php mocking phpunit

大家好我怎么能在PHPUnit中这样做,一个模拟方法返回它传递的参数?

E.g:

$redirector->expects( $this->once() )->method('gotoUrl')->will( $this->returnValue($argument) );

2 个答案:

答案 0 :(得分:7)

根据PHPUnit manual

$stub->expects($this->any())
     ->method('doSomething')
     ->will($this->returnArgument(0));

答案 1 :(得分:5)

$redirector->expects($this->once())
           ->method('gotoUrl')
           ->will($this->returnCallback(function() {
                $args = func_get_args();
                return $args[0]; // or w/e
            ));