How can I get PHPUnit MockObjects to return different values based on a parameter?

前端 未结 11 1625
忘掉有多难
忘掉有多难 2020-12-04 05:43

I\'ve got a PHPUnit mock object that returns \'return value\' no matter what its arguments:

// From inside a test...
$mock = $this->getMock(\         


        
11条回答
  •  没有蜡笔的小新
    2020-12-04 06:21

    It is not exactly what you ask, but in some cases it can help:

    $mock->expects( $this->any() ) )
     ->method( 'methodToMock' )
     ->will( $this->onConsecutiveCalls( 'one', 'two' ) );
    

    onConsecutiveCalls - returns a list of values in the specified order

提交回复
热议问题