Collision is an error reporting tool for PHP command line applications. It ships as a dev dependency for Laravel starting back in Laravel 5.6, but I recently noticed the package’s author mention the PHPUnit adapter:
— NUNO MADURO (@enunomaduro) December 30, 2019
While collision ships with Laravel, you need to configure the listener if you want to use it with PHPUnit. I thought I’d quickly demonstrate setting it up with Laravel.
Here’s the default PHPUnit experience when you have an exception during a test. You might notice that the first place you want to look is the top of the exception stack, so you have to scroll up to see it:
To get a much better experience, add the Collision printer class to your Laravel project’s
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"bootstrap="vendor/autoload.php"colors="true"printerClass="NunoMaduro\Collision\Adapters\Phpunit\Printer"><!-- ... --></phpunit>
Now you get a nice clean view of where the exception occurred after the full stack trace:
Boom! Collision provides a much better experience while running PHPUnit tests via the command line!
To learn more about this package, check it out on GitHub at nunomaduro/collision.