diff --git a/lib/phpunit/classes/constraint_object_is_equal_with_exceptions.php b/lib/phpunit/classes/constraint_object_is_equal_with_exceptions.php index 9407b7a2b91..44dda06ce92 100644 --- a/lib/phpunit/classes/constraint_object_is_equal_with_exceptions.php +++ b/lib/phpunit/classes/constraint_object_is_equal_with_exceptions.php @@ -39,6 +39,19 @@ class phpunit_constraint_object_is_equal_with_exceptions extends PHPUnit\Framewo */ protected $keys = array(); + /** + * @var mixed $value Need to keep it here because it became private for PHPUnit 7.x and up + */ + protected $capturedvalue; + + /** + * Override constructor to capture value + */ + public function __construct($value, float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false) { + parent::__construct($value, $delta, $maxDepth, $canonicalize, $ignoreCase); + $this->capturedvalue = $value; + } + /** * Add an exception for the named key to use a different comparison * method. Any assertion provided by PHPUnit\Framework\Assert is @@ -69,13 +82,13 @@ class phpunit_constraint_object_is_equal_with_exceptions extends PHPUnit\Framewo */ public function evaluate($other, $description = '', $shouldreturnesult = false) { foreach ($this->keys as $key => $comparison) { - if (isset($other->$key) || isset($this->value->$key)) { + if (isset($other->$key) || isset($this->capturedvalue->$key)) { // One of the keys is present, therefore run the comparison. - PHPUnit\Framework\Assert::$comparison($this->value->$key, $other->$key); + PHPUnit\Framework\Assert::$comparison($this->capturedvalue->$key, $other->$key); // Unset the keys, otherwise the standard evaluation will take place. unset($other->$key); - unset($this->value->$key); + unset($this->capturedvalue->$key); } }