我的 PHPUnit 测试有问题。我有这样的方法:
public function bla()
{
$this->blub();
}
$_testObject 是 Foo 的一个模拟实例,如下所示:
public function setUp()
{
$this->_testObject = $this->getMockBuilder('Foo')
->setMethods(array('blub'))
->getMock();
}
我的测试方法是这样的:
/**
* @test
* @covers Foo::bla
*/
public function shouldCallBlubOnce()
{
$this->_testObject->expects($this->once())
->method('blub');
//forgot this one :D
$this->_testObject->bla();
}
该测试的结果提供:
PHPUnit_Framework_ExpectationFailedException :
Expectation failed for method name is equal to <string:blub> when invoked 1 time(s).
Method was expected to be called 1 times, actually called 0 times.
提前致谢。:)