From c9086cf785e29460a383201fa78ac95090fd7db7 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 11 Dec 2020 23:27:28 +0100 Subject: [PATCH] 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. --- src/Constraint/ArraySubset.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Constraint/ArraySubset.php b/src/Constraint/ArraySubset.php index 68bcf71..bb26d0e 100644 --- a/src/Constraint/ArraySubset.php +++ b/src/Constraint/ArraySubset.php @@ -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; @@ -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),