2013-05-02 55 views
2

大家好我怎样才能使它在PHPUnit模拟方法返回其传递的参数?如何返回模拟方法的参数?

E.g:

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

回答

5

由于每PHPUnit manual

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

谢谢,这是更多的优化。 – Darren 2013-05-03 23:19:58

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

谢谢,并获得成功,这是很酷它是在一个封闭。 – Darren 2013-05-02 17:17:07

+0

我已经搜索这样的解决方案嘲笑。像魅力一样工作。谢谢! – 2015-01-08 10:19:14

相关问题