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

Breadcrumb

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

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\Test
View 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,
        ];
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AssertingContextualValidator::$atPathCalls private property
AssertingContextualValidator::$expectedAtPath private property
AssertingContextualValidator::$expectedValidate private property
AssertingContextualValidator::$expectNoValidate private property
AssertingContextualValidator::$validateCalls private property
AssertingContextualValidator::atPath public function Appends the given path to the property path of the context. Overrides ContextualValidatorInterface::atPath
AssertingContextualValidator::doAtPath public function
AssertingContextualValidator::doGetViolations public function
AssertingContextualValidator::doValidate public function
AssertingContextualValidator::doValidateProperty public function
AssertingContextualValidator::doValidatePropertyValue public function
AssertingContextualValidator::expectNoValidate public function
AssertingContextualValidator::expectValidation public function
AssertingContextualValidator::getViolations public function Returns the violations that have been generated so far in the context
of the validator.
Overrides ContextualValidatorInterface::getViolations
AssertingContextualValidator::validate public function Validates a value against a constraint or a list of constraints. Overrides ContextualValidatorInterface::validate
AssertingContextualValidator::validateProperty public function Validates a property of an object against the constraints specified
for this property.
Overrides ContextualValidatorInterface::validateProperty
AssertingContextualValidator::validatePropertyValue public function Validates a value against the constraints specified for an object's
property.
Overrides ContextualValidatorInterface::validatePropertyValue
AssertingContextualValidator::__construct public function
AssertingContextualValidator::__destruct public function
RSS feed
Powered by Drupal