2
class TestMe
{
public function method() { }
}
class TestTest extends PHPUnit_Framework_TestCase
{
public function testA()
{
$stub = $this->getMock ('TestMe');
$stub->expects ($this->exactly(2))->method('method');
}
public function testB()
{
$stub = $this->getMock ('TestMe');
$stub->expects ($this->exactly(2))->method('method');
$stub->method();
}
public function testC()
{
$stub = $this->getMock ('TestMe');
$stub->expects ($this->exactly(2))->method('method');
$stub->method();
$stub->method();
}
public function testD()
{
$stub = $this->getMock ('TestMe');
$stub->expects ($this->exactly(2))->method('method');
$stub->method();
$stub->method();
$stub->method();
}
}
種皮,TESTB,TESTC流逝,僅TESTD失敗,這是奇數。 testA甚至沒有調用方法,所以它應該失敗 - 但它通過了,爲什麼? testB調用方法ONCE,但我們預計TWICE應該失敗 - 但它通過了,爲什麼? testC是好的,沒問題 testD因此無法正常工作,沒問題
也許正好()並不能完全符合我的預期。我使用最新的4.3.4 PhPunit。