function ObjectEquals::matches
Throws
ActualValueIsNotAnObjectException
ComparisonMethodDoesNotAcceptParameterTypeException
ComparisonMethodDoesNotDeclareBoolReturnTypeException
ComparisonMethodDoesNotDeclareExactlyOneParameterException
ComparisonMethodDoesNotDeclareParameterTypeException
ComparisonMethodDoesNotExistException
Overrides Constraint::matches
File
-
vendor/
phpunit/ phpunit/ src/ Framework/ Constraint/ Object/ ObjectEquals.php, line 49
Class
- ObjectEquals
- @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Namespace
PHPUnit\Framework\ConstraintCode
protected function matches(mixed $other) : bool {
if (!is_object($other)) {
throw new ActualValueIsNotAnObjectException();
}
$object = new ReflectionObject($other);
if (!$object->hasMethod($this->method)) {
throw new ComparisonMethodDoesNotExistException($other::class, $this->method);
}
$method = $object->getMethod($this->method);
if (!$method->hasReturnType()) {
throw new ComparisonMethodDoesNotDeclareBoolReturnTypeException($other::class, $this->method);
}
$returnType = $method->getReturnType();
if (!$returnType instanceof ReflectionNamedType) {
throw new ComparisonMethodDoesNotDeclareBoolReturnTypeException($other::class, $this->method);
}
if ($returnType->allowsNull()) {
throw new ComparisonMethodDoesNotDeclareBoolReturnTypeException($other::class, $this->method);
}
if ($returnType->getName() !== 'bool') {
throw new ComparisonMethodDoesNotDeclareBoolReturnTypeException($other::class, $this->method);
}
if ($method->getNumberOfParameters() !== 1 || $method->getNumberOfRequiredParameters() !== 1) {
throw new ComparisonMethodDoesNotDeclareExactlyOneParameterException($other::class, $this->method);
}
$parameter = $method->getParameters()[0];
if (!$parameter->hasType()) {
throw new ComparisonMethodDoesNotDeclareParameterTypeException($other::class, $this->method);
}
$type = $parameter->getType();
if (!$type instanceof ReflectionNamedType) {
throw new ComparisonMethodDoesNotDeclareParameterTypeException($other::class, $this->method);
}
$typeName = $type->getName();
if ($typeName === 'self') {
$typeName = $other::class;
}
if (!$this->expected instanceof $typeName) {
throw new ComparisonMethodDoesNotAcceptParameterTypeException($other::class, $this->method, $this->expected::class);
}
return $other->{$this->method}($this->expected);
}