您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit中expectDeprecationMessageMatches的使用
发布时间:2021-09-15 17:11:09编辑:雪饮阅读()
expectDeprecationMessageMatches用于通过正则断言匹配到产生的一个DEPRECATED错误。
use PHPUnit\Framework\TestCase;
final class ErrorTest extends TestCase
{
public function testDeprecationCanBeExpected(): void
{
$this->expectDeprecation();
$this->expectDeprecationMessageMatches('/foo/');
\trigger_error('foo', \E_USER_DEPRECATED);
}
}
则运行测试结果自然是断言结果与预期结果不一致了。
use PHPUnit\Framework\TestCase;
final class ErrorTest extends TestCase
{
public function testDeprecationCanBeExpected(): void
{
$this->expectDeprecation();
$this->expectDeprecationMessageMatches('/foo/');
\trigger_error('fox', \E_USER_DEPRECATED);
}
}
关键字词:phpunit,expectDeprecationMessageMatches