0
在处理其他信息而不是消息或代码时,对抛出的异常执行任意断言可能很有用。更好的解决方案对预期异常执行任意断言?
有没有更简单,可读,或更“PHPUnit的推荐方式”来做到这一点,比下面的例子:
public function testTitleShouldNotAcceptArrayAsValue()
{
/* Arrange */
$schema = new sch\ObjectSchema();
/* Expect */
$this->expectException(sch\Exception::class);
try {
/* Act */
$schema->title = [];
} catch (sch\Exception $exception) {
/* Assert */
$this->assertEquals('title', $exception->getProperty());
$this->assertEquals(
[
'properties' => [
'title' => [
'type' => 'string'
]
]
],
$exception->getRules()
);
throw $exception;
}
}