Skip to content

Commit

Permalink
Add support for use with PHPUnit Phar
Browse files Browse the repository at this point in the history
When PHPUnit is packaged as a Phar, certain classes are prefixed to prevent conflicts with project dependencies which may use the same files, but in a different version.

For this package, only one referenced class is impacted by this.

The small fix now applied allows for using this package both when running PHPUnit installed via Composer, as well as running Composer installed as a Phar.
  • Loading branch information
jrfnl committed Apr 7, 2021
1 parent 5e5d1b7 commit c9086cf
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Constraint/ArraySubset.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use ArrayObject;
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\SebastianBergmann\Comparator\ComparisonFailure as Phar_ComparisonFailure;
use SebastianBergmann\Comparator\ComparisonFailure;
use SebastianBergmann\RecursionContext\InvalidArgumentException;
use Traversable;

use function array_replace_recursive;
use function class_exists;
use function is_array;
use function iterator_to_array;
use function var_export;
Expand Down Expand Up @@ -81,7 +83,14 @@ public function evaluate($other, string $description = '', bool $returnResult =
return null;
}

$f = new ComparisonFailure(
// Support use of this library when running PHPUnit as a Phar.
if (class_exists(Phar_ComparisonFailure::class) === true) {
$class = Phar_ComparisonFailure::class;
} else {
$class = ComparisonFailure::class;
}

$f = new $class(
$patched,
$other,
var_export($patched, true),
Expand Down

0 comments on commit c9086cf

Please sign in to comment.