4

Hi all how can I make it so in PHPUnit a mocked method returns its passed argument?

E.g:

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

2 回答 2

10

根据PHPUnit 手册

$stub->expects($this->any())
     ->method('doSomething')
     ->will($this->returnArgument(0));
于 2013-05-03T21:06:42.653 回答
6
$redirector->expects($this->once())
           ->method('gotoUrl')
           ->will($this->returnCallback(function() {
                $args = func_get_args();
                return $args[0]; // or w/e
            ));
于 2013-05-02T01:32:56.880 回答