Skip to content

Commit

Permalink
Fix the collision printer with PHPUnit 10 (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
mantle-ci committed Apr 23, 2024
1 parent 0cd499a commit 0aa5218
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
32 changes: 32 additions & 0 deletions autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Testkit autoload file
*
* @package Mantle
*/

use NunoMaduro\Collision\Adapters\Phpunit\Subscribers\EnsurePrinterIsRegisteredSubscriber;
use PHPUnit\Event\Facade as PHPUnitFacade;
use PHPUnit\Runner\Version;

/**
* Register the collision printer for PHPUnit 10.
*
* Due to a change in the collision package, the printer must be registered
* manually unless the test suite is manually invoked by the code base (which
* most projects do not use).
*
* The printer code is largely private and not intended to be used by external
* code, so we need to carefully check for the existence of the classes and
* methods we need to use.
*/
if (
class_exists( Version::class )
&& version_compare( Version::id(), '10.0.0', '>=' )
&& empty( getenv( 'COLLISION_DISABLE' ) ) // A kill switch for disabling the printer.
&& class_exists( PHPUnitFacade::class )
&& class_exists( EnsurePrinterIsRegisteredSubscriber::class )
&& method_exists( PHPUnitFacade::class, 'registerSubscriber' )
) {
PHPUnitFacade::instance()->registerSubscriber( new EnsurePrinterIsRegisteredSubscriber() );
}
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
}
}
},
"autoload": {
"files": [
"autoload.php"
]
},
"license": "GPL-2.0-or-later",
"authors": [
{
Expand Down

0 comments on commit 0aa5218

Please sign in to comment.