【发布时间】:2011-11-21 05:27:08
【问题描述】:
我的代码中有一个断言。比如:
assert('is_string($var)');
如果我为 PHPUnit 编写一个测试导致此断言失败并显示消息,Warning: assert(): Assertion "is_string($var)" failed in /path/to/file.php on line ###
而且,我的测试也失败了。我尝试将@expectedException PHPUnit_Framework_Error_Warning 添加到文档块according to the documentation,但这无济于事。我需要做什么才能让我的测试预期这个断言会失败?
【问题讨论】:
-
不要。采用 。断言。在 。生产
-
为什么不在您的代码和生产中包含断言,只需设置
assert_options(ASSERT_ACTIVE, 0);?
标签: php unit-testing phpunit assert assertions