function IsIdentical::evaluate
Evaluates the constraint for parameter $other.
If $returnResult is set to false (the default), an exception is thrown in case of a failure. null is returned otherwise.
If $returnResult is true, the result of the evaluation is returned as a boolean value instead: true in case of success, false in case of a failure.
Throws
Overrides Constraint::evaluate
File
-
vendor/
phpunit/ phpunit/ src/ Framework/ Constraint/ IsIdentical.php, line 47
Class
- IsIdentical
- @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Namespace
PHPUnit\Framework\ConstraintCode
public function evaluate(mixed $other, string $description = '', bool $returnResult = false) : ?bool {
$success = $this->value === $other;
if ($returnResult) {
return $success;
}
if (!$success) {
$f = null;
// if both values are strings, make sure a diff is generated
if (is_string($this->value) && is_string($other)) {
$f = new ComparisonFailure($this->value, $other, sprintf("'%s'", $this->value), sprintf("'%s'", $other));
}
// if both values are array or enums, make sure a diff is generated
if (is_array($this->value) && is_array($other) || $this->value instanceof UnitEnum && $other instanceof UnitEnum) {
$f = new ComparisonFailure($this->value, $other, Exporter::export($this->value, true), Exporter::export($other, true));
}
$this->fail($other, $description, $f);
}
return null;
}