PHPUnit如果抛出异常则.. else

时间:2017-09-22 10:37:49

标签: php exception exception-handling phpunit

我想检查我的PHPUnit测试是否抛出异常,如果是,测试应该是正确的,如果没有其他代码:

if ($this->expectException(InvalidArgumentException::class))
{
    // Test correct

} else {

     ...
    $this->assertEquals($f1, $f2);
    // Test correct

}

我该如何处理?

1 个答案:

答案 0 :(得分:0)

你只是说:

$this->expectException(InvalidArgumentException::class);

然后调用抛出异常的代码。如果在测试结束时没有抛出任何异常,它将失败。