【发布时间】:2017-12-07 12:40:45
【问题描述】:
我正在测试,如果输入必须失败,handleMatchResults 将抛出 RouteNotFoundException。这是实际测试的代码:
public function test_not_found_match_throws_NotFoundException()
{
$this->expectException(RouteNotFoundException::class);
$request = $this->prophet->prophesize(ServerRequest::class);
$this->router->handleMatchResults([0, []], $request->reveal());
}
一切都按预期进行,我的测试通过了,但是,当我运行 phpunit --coverage-text (或任何其他覆盖类型)时,我得到了这个测试的最后一行,以及另一个类似测试的最后一行,无法访问/未执行。我可以理解那些没有被执行,因为如果代码是正确的,这个测试的最后一行将永远不会被执行,因为
$this->router->handleMatchResults([0, []], $request->reveal());
总是会抛出异常并且函数的执行会结束。那么,如何实现 100% 的课程覆盖率?
【问题讨论】:
标签: php phpunit code-coverage