MDL-67673 phpunit: phpunit_constraint_object_is_equal_with_exceptions

Constraints are now declared final, so we cannot extend them anymore.

Hence, instead of extending PHPUnit\Framework\Constraint\IsEqual we
are just wrapping it into our constraint.
This commit is contained in:
Eloy Lafuente (stronk7)
2020-10-21 12:45:59 +02:00
parent f6711bb394
commit 80be8d2204
@@ -32,7 +32,7 @@
* @copyright 2015 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class phpunit_constraint_object_is_equal_with_exceptions extends PHPUnit\Framework\Constraint\IsEqual {
class phpunit_constraint_object_is_equal_with_exceptions extends PHPUnit\Framework\Constraint\Constraint {
/**
* @var array $keys The list of exceptions.
@@ -44,12 +44,17 @@ class phpunit_constraint_object_is_equal_with_exceptions extends PHPUnit\Framewo
*/
protected $capturedvalue;
/**
* @var \PHPUnit\Framework\Constraint\IsEqual $isequal original constraint to be used internally.
*/
protected $isequal;
/**
* 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->isequal = new \PHPUnit\Framework\Constraint\IsEqual($value, $delta, $maxDepth, $canonicalize, $ignoreCase);
$this->capturedvalue = $value;
}
@@ -93,8 +98,13 @@ class phpunit_constraint_object_is_equal_with_exceptions extends PHPUnit\Framewo
}
}
// Run the parent evaluation (isEqual).
return parent::evaluate($other, $description, $shouldreturnesult);
// Run the IsEqual evaluation.
return $this->isequal->evaluate($other, $description, $shouldreturnesult);
}
// \PHPUnit\Framework\Constraint\IsEqual wrapping.
public function toString(): string {
return $this->isequal->toString();
}
}