Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. IsIdentical.php

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

ExpectationFailedException

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\Constraint

Code

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;
}
RSS feed
Powered by Drupal