rquadling/phpunit-errorhandler

This package is abandoned and no longer maintained. The author suggests using the digitickets/phpunit-errorhandler package instead.

A simple trait to add to your PHPUnit test allowing you to track and test PHP errors, warnings and notices

4.1.1 2018-09-06 11:35 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:54:58 UTC


README

Travis Build Status Scrutinizer Build Status Scrutinizer Code Coverage GitHub issues

PHP Version Stable Version

Total Packagist Downloads Monthly Packagist Downloads Daily Packagist Downloads

PHPUnit ErrorHandler

An alternative approach to unit testing PHP errors.

Whilst you can use PHPUnit's built-in behaviour of converting all errors, warnings and notices to exceptions, this package allows you to track all PHP errors, including user generated errors, separately.

The code is supplied as a trait and is based upon Error Condition Testing with PHPUnit

Here is an example use case:

<?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();
    }
}

Upgrading from V3.0.0 to V4.0.0

Thanks to imbrish, the upgrade is extremely simple.

In previous versions, you were required to have the following setup logic.

protected function setUp()
{
    // Set the error handler.
    $this->setUpErrorHandler();
}

Now you don't. You can remove the $this->setUpErrorHandler(); call. If you now have an empty setup() function, you can remove that also!