digitickets / phpunit-errorhandler
一个简单的特性,可以添加到您的PHPUnit测试中,以便您跟踪和测试PHP错误、警告和通知
4.1.1
2018-09-06 11:35 UTC
Requires
- php: >=7
Requires (Dev)
- phpunit/phpunit: ^6
README
PHPUnit ErrorHandler
单元测试PHP错误的替代方法。
虽然您可以使用PHPUnit内置的行为将所有错误、警告和通知转换为异常,但此包允许您单独跟踪所有PHP错误,包括用户生成的错误。
代码以特性形式提供,并基于使用PHPUnit测试错误条件
以下是一个示例用例
<?php use DigiTickets\PHPUnit\ErrorHandler; class TestErrorHandling extends \PHPUnit\Framework\TestCase { use ErrorHandler; public function testSomethingGeneratedAnError() { // Run something that will produce an error, warning or notice. // For example, a E_USER_NOTICE of 'Incompatible type ignored' can be tested as follows: $this->assertError('Incompatible type ignored', E_USER_NOTICE); } public function testSomethingDidNotGenerateAnError() { // Run something that should not produce an error, warning or notice. $this->assertNoErrors(); } }
从V3.0.0升级到V4.0.0
感谢imbrish,升级非常简单。
在先前版本中,您需要以下设置逻辑。
protected function setUp()
{
// Set the error handler.
$this->setUpErrorHandler();
}
现在您不需要了。您可以移除对$this->setUpErrorHandler();
的调用。如果您现在有一个空的setup()
函数,也可以将其删除!