【发布时间】:2015-11-07 12:44:31
【问题描述】:
我有一个单元测试来检查如果未安装 openssl_random_pseudo_bytes 是否会引发异常。但是,如果 已 已安装,则当前会被跳过。但是,这对我来说并不令人满意,因为它会导致测试运行不完美。我可以将单元测试设置为通过,但这感觉像是作弊。
有人有什么想法吗?
这是我的测试:
public function testGenerateOpenSSLThrowsExceptionWhenFunctionDoesNotExist()
{
if (function_exists('openssl_random_pseudo_bytes')) {
$this->markTestSkipped('Cannot run test: openssl_random_pseudo_bytes function exists.');
}
$this->_salt->generateFromOpenSSL();
}
【问题讨论】: