【发布时间】:2018-01-19 08:53:35
【问题描述】:
在处理消息或代码以外的其他信息时,对抛出的异常执行任意断言可能很有用。
是否有比以下示例更简单、可读或更“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;
}
}
【问题讨论】:
标签: php unit-testing exception phpunit