2013-05-02 53 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

相關問題