Skip to content

Commit c9086cf

Browse files
committed
Add support for use with PHPUnit Phar
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.
1 parent 5e5d1b7 commit c9086cf

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Constraint/ArraySubset.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
use ArrayObject;
88
use PHPUnit\Framework\Constraint\Constraint;
99
use PHPUnit\Framework\ExpectationFailedException;
10+
use PHPUnit\SebastianBergmann\Comparator\ComparisonFailure as Phar_ComparisonFailure;
1011
use SebastianBergmann\Comparator\ComparisonFailure;
1112
use SebastianBergmann\RecursionContext\InvalidArgumentException;
1213
use Traversable;
1314

1415
use function array_replace_recursive;
16+
use function class_exists;
1517
use function is_array;
1618
use function iterator_to_array;
1719
use function var_export;
@@ -81,7 +83,14 @@ public function evaluate($other, string $description = '', bool $returnResult =
8183
return null;
8284
}
8385

84-
$f = new ComparisonFailure(
86+
// Support use of this library when running PHPUnit as a Phar.
87+
if (class_exists(Phar_ComparisonFailure::class) === true) {
88+
$class = Phar_ComparisonFailure::class;
89+
} else {
90+
$class = ComparisonFailure::class;
91+
}
92+
93+
$f = new $class(
8594
$patched,
8695
$other,
8796
var_export($patched, true),

0 commit comments

Comments
 (0)