class AssertingContextualValidator
@internal
Hierarchy
- class \Symfony\Component\Validator\Test\AssertingContextualValidator implements \Symfony\Component\Validator\Validator\ContextualValidatorInterface
Expanded class hierarchy of AssertingContextualValidator
File
-
vendor/
symfony/ validator/ Test/ ConstraintValidatorTestCase.php, line 446
Namespace
Symfony\Component\Validator\TestView source
class AssertingContextualValidator implements ContextualValidatorInterface {
private bool $expectNoValidate = false;
private int $atPathCalls = -1;
private array $expectedAtPath = [];
private int $validateCalls = -1;
private array $expectedValidate = [];
public function __construct(ExecutionContextInterface $context) {
}
public function __destruct() {
if ($this->expectedAtPath) {
throw new ExpectationFailedException('Some expected validation calls for paths were not done.');
}
if ($this->expectedValidate) {
throw new ExpectationFailedException('Some expected validation calls for values were not done.');
}
}
public function atPath(string $path) : static {
throw new \BadMethodCallException();
}
/**
* @return $this
*/
public function doAtPath(string $path) : static {
Assert::assertFalse($this->expectNoValidate, 'No validation calls have been expected.');
if (!isset($this->expectedAtPath[++$this->atPathCalls])) {
throw new ExpectationFailedException(\sprintf('Validation for property path "%s" was not expected.', $path));
}
$expectedPath = $this->expectedAtPath[$this->atPathCalls];
unset($this->expectedAtPath[$this->atPathCalls]);
Assert::assertSame($expectedPath, $path);
return $this;
}
public function validate(mixed $value, Constraint|array|null $constraints = null, string|GroupSequence|array|null $groups = null) : static {
throw new \BadMethodCallException();
}
/**
* @return $this
*/
public function doValidate(mixed $value, Constraint|array|null $constraints = null, string|GroupSequence|array|null $groups = null) : static {
Assert::assertFalse($this->expectNoValidate, 'No validation calls have been expected.');
if (!isset($this->expectedValidate[++$this->validateCalls])) {
return $this;
}
[
$expectedValue,
$expectedGroup,
$expectedConstraints,
$violation,
] = $this->expectedValidate[$this->validateCalls];
unset($this->expectedValidate[$this->validateCalls]);
Assert::assertSame($expectedValue, $value);
$expectedConstraints($constraints);
Assert::assertSame($expectedGroup, $groups);
if (null !== $violation) {
$this->context
->addViolation($violation->getMessage(), $violation->getParameters());
}
return $this;
}
public function validateProperty(object $object, string $propertyName, string|GroupSequence|array|null $groups = null) : static {
throw new \BadMethodCallException();
}
/**
* @return $this
*/
public function doValidateProperty(object $object, string $propertyName, string|GroupSequence|array|null $groups = null) : static {
return $this;
}
public function validatePropertyValue(object|string $objectOrClass, string $propertyName, mixed $value, string|GroupSequence|array|null $groups = null) : static {
throw new \BadMethodCallException();
}
/**
* @return $this
*/
public function doValidatePropertyValue(object|string $objectOrClass, string $propertyName, mixed $value, string|GroupSequence|array|null $groups = null) : static {
return $this;
}
public function getViolations() : ConstraintViolationListInterface {
throw new \BadMethodCallException();
}
public function doGetViolations() : ConstraintViolationListInterface {
return $this->context
->getViolations();
}
public function expectNoValidate() : void {
$this->expectNoValidate = true;
}
public function expectValidation(string $call, ?string $propertyPath, mixed $value, string|GroupSequence|array|null $group, callable $constraints, ?ConstraintViolationInterface $violation = null) : void {
if (null !== $propertyPath) {
$this->expectedAtPath[$call] = $propertyPath;
}
$this->expectedValidate[$call] = [
$value,
$group,
$constraints,
$violation,
];
}
}