0
假設我有模板方法設計模式實現的代碼。我想在我的模板方法中測試方法調用的順序和計數。我嘗試使用PHPUnit模擬。我的源代碼如下所示:使用PHPUnit模擬對象測試模板方法設計模式實現
class Foo {
public function __construct() {}
public function foobar() {
$this->foo();
$this->bar();
}
protected function foo() {}
protected function bar() {}
}
class FooTest extends PHPUnit_Framework_TestCase {
public function testFoo() {
$fooMock = $this->getMock('Foo', array('foo', 'bar'));
$fooMock->foobar();
$fooMock->expects($this->once())->method('foo');
$fooMock->expects($this->once())->method('bar');
}
}
因此,我有這樣的錯誤:
PHPUnit_Framework_ExpectationFailedException :
Expectation failed for method name is equal to <string:foo> when invoked 1 time(s).
Method was expected to be called 1 times, actually called 0 times.
是否可以算使用模擬對象在這樣的情況方法調用?