我有这样的代码:
class ToBeTested
{
function simpleMethod($param)
{
if(0 === $param)
{
trigger_error("Param is 0!", E_USER_WARNING);
return false;
}
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
并测试此代码:
class SimpleTest extends PHPUnit_Framework_TestCase
{
function testSimpleMethod()
{
$toBeTestedObject = new ToBeTested();
$this->assertFalse($toBeTestedObject->simpleMethod(0));
}
}
Run Code Online (Sandbox Code Playgroud)
我知道如何测试,如果错误被触发($this->setExpectedException()),但我不知道如何在trigger_error()函数后执行代码.
请记住,在PHPUnit E_USER_WARNING中没有转换为PHPUnit_Framework_Error_Warning(可以禁用),但它被转换为PHPUnit_Framework_Error(不能被禁用).