Skip to content

Commit f095ae4

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 2563d11 commit f095ae4

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,10 +7,12 @@
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
use function array_replace_recursive;
15+
use function class_exists;
1416
use function is_array;
1517
use function iterator_to_array;
1618
use function var_export;
@@ -76,7 +78,14 @@ public function evaluate($other, string $description = '', bool $returnResult =
7678
return null;
7779
}
7880

79-
$f = new ComparisonFailure(
81+
// Support use of this library when running PHPUnit as a Phar.
82+
if (class_exists(Phar_ComparisonFailure::class) === true) {
83+
$class = Phar_ComparisonFailure::class;
84+
} else {
85+
$class = ComparisonFailure::class;
86+
}
87+
88+
$f = new $class(
8089
$patched,
8190
$other,
8291
var_export($patched, true),

0 commit comments

Comments
 (0)