8
也許我錯過了一個細節,但我爲單身_clone方法編寫了一個小測試用例,但它沒有在代碼覆蓋率報告中顯示出來。phpunit - @覆蓋標記不起作用
/**
* @covers ErrorHandling::__clone
*/
public function test__cloneNotCloneable(){
$class = new ReflectionClass('ErrorHandling');
$method = $class->getMethod('__clone');
self::assertTrue($method->isFinal(), '__clone method is not final.');
self::assertTrue($method->isPrivate(), '__clone method is not private.');
}
__clone方法是常規(邪惡)單例的普通私有/最終__clone()。
/**
* Define __clone as final and private to dissallow cloning.
*/
private final function __clone(){}
我知道這可能就是因爲這個矯枉過正測試,但代碼覆蓋報告是有點「做得好」作業的圖形表示的。有沒有辦法將這種方法標記爲覆蓋代碼覆蓋率報告?
我沒有看到[手冊](http://www.phpunit.de/manual/3.3/en/code-coverage-analysis.html#code-coverage-analysis.specifying-covered-methods .tables.annotations),我可以使用@covers ClassName ::標籤,它將顯示所有私有方法。如果有辦法只指定一種方法,我還是很好奇。 –
stefgosselin
2011-05-19 07:03:30
@David的回答是正確的,但我建議你自己創建onc信任。沒有單身人士使得測試非常簡單;)http://butunclebob.com/ArticleS.UncleBob.SingletonVsJustCreateOne – edorian 2011-05-21 21:25:13