对于这种情况和测试接口我会写至少3个测试:
protected setUp() {
$this->_object = $this->getMockForAbstractClass(
'PickupPoint_Abstract', array(), '', false
);
}
public function testInstanceOf() {
$this->assertInstanceOf('PickupPoint_Abstract', $this->_object);
}
public function testMethodsExistance() {
$methods = get_class_methods($this->_object);
$this->assertTrue(in_array('getPickupPoints', $methods));
$this->assertTrue(in_array('getPickupPointDetails', $methods));
$this->assertTrue(in_array('__construct', $methods));
}
public function testMethodCount() {
$methods = get_class_methods($this->_object);
/**
* PHPUnit add seven own methods in 3.6.11 + __clone + count of these methods
*/
$this->assertEquals(11, count($methods));
}
借助这些测试,你会避免错别字,检查所需的方法存及其是否有新的方法将被添加,这个测试将被打破,因为方法的数量已经改变了,这就是我们想要的行为。
这对我来说很好。我总是使用这个接口的测试,但我认为它可以用于抽象类!
这不是一个抽象类,而是一个接口。抽象类定义了两个方法存根和实现的方法。 – halfdan 2010-09-15 08:51:47
可能的重复http://stackoverflow.com/questions/190295/phpunit-testing-abstract-classes – 2010-09-15 08:52:09