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;
}
}