我有这个警卫:
protected function validateRemove($key)
{
if (!isset($this->collection[$key])) {
throw new CategoryCollectionBadItemException();
}
}
和测试:
/**
* @test
* @expectedException InfluenceDecision\Domain\Exception\Category\CategoryCollectionBadItemException
*/
public function removeMethodMustThrowExceptionWithInvalidKey()
{
$this->categoryCollection->add(
new Category(
null,
'test category'
)
);
$this->categoryCollection->remove(1);
}
CategoryCollection remove 方法调用 validateRemove 方法
测试工作正常,但覆盖率不是 100%,因为测试无法访问 validateRemove 方法的最后一行:
什么是适当的解决方案?