Repository: symfony/symfony
File: src/Symfony/Component/Validator/Tests/Validator/RecursiveValidatorTest.php (PHP)

Code before:

final class TestConstraintHashesDoNotCollideValidator extends ConstraintValidator
{
    public function validate($value, Constraint $constraint): void
    {
        if (!$value instanceof Entity) {
            throw new \LogicException();
        }

        $this->context->getValidator()
            ->inContext($this->context)
            ->atPath('data')
            ->validate($value, new NotNull())
            ->validate($value, new NotNull())
            ->validate($value, new IsFalse());

        $this->context->getValidator()
            ->inContext($this->context)
            ->validate($value, null, new GroupSequence(['should_pass']))
            ->validate($value, null, new GroupSequence(['should_fail']));
    }

    public function testValidatePropertyWithExistenceCheckThrowsOnNonExistentProperty()
    {
        $this->expectException(ValidatorException::class);
        $this->expectExceptionMessage('The property "nonExistent" does not exist');

        $translator = new IdentityTranslator();
        $translator->setLocale('en');

        $contextFactory = new ExecutionContextFactory($translator);
        $validatorFactory = new ConstraintValidatorFactory();

        $validator = new RecursiveValidator($contextFactory, $this->metadataFactory, $validatorFactory, [], null, true);

        $entity = new Entity();
        $validator->validateProperty($entity, 'nonExistent');
    }

    public function testValidatePropertyValueWithExistenceCheckThrowsOnNonExistentProperty()
    {
        $this->expectException(ValidatorException::class);
        $this->expectExceptionMessage('The property "nonExistent" does not exist');

        $translator = new IdentityTranslator();
        $translator->setLocale('en');

        $contextFactory = new ExecutionContextFactory($translator);
        $validatorFactory = new ConstraintValidatorFactory();

        $validator = new RecursiveValidator($contextFactory, $this->metadataFactory, $validatorFactory, [], null, true);

Review comment (suggestion):
```suggestion
        $this->expectExceptionMessage('The property "nonExistent" has not metadata associated and may not exist.');
```

Code after:

final class TestConstraintHashesDoNotCollideValidator extends ConstraintValidator
{
    public function validate($value, Constraint $constraint): void
    {
        if (!$value instanceof Entity) {
            throw new \LogicException();
        }

        $this->context->getValidator()
            ->inContext($this->context)
            ->atPath('data')
            ->validate($value, new NotNull())
            ->validate($value, new NotNull())
            ->validate($value, new IsFalse());

        $this->context->getValidator()
            ->inContext($this->context)
            ->validate($value, null, new GroupSequence(['should_pass']))
            ->validate($value, null, new GroupSequence(['should_fail']));
    }

    public function testValidatePropertyWithExistenceCheckThrowsOnNonExistentProperty()
    {
        $this->expectException(ValidatorException::class);
        $this->expectExceptionMessage('The property "nonExistent" has not metadata associated and may not exist.');

        $translator = new IdentityTranslator();
        $translator->setLocale('en');

        $contextFactory = new ExecutionContextFactory($translator);
        $validatorFactory = new ConstraintValidatorFactory();

        $validator = new RecursiveValidator($contextFactory, $this->metadataFactory, $validatorFactory, [], null, true);

        $entity = new Entity();
        $validator->validateProperty($entity, 'nonExistent');
    }

    public function testValidatePropertyValueWithExistenceCheckThrowsOnNonExistentProperty()
    {
        $this->expectException(ValidatorException::class);
        $this->expectExceptionMessage('The property "nonExistent" does not exist');

        $translator = new IdentityTranslator();
        $translator->setLocale('en');

        $contextFactory = new ExecutionContextFactory($translator);
        $validatorFactory = new ConstraintValidatorFactory();

        $validator = new RecursiveValidator($contextFactory, $this->metadataFactory, $validatorFactory, [], null, true);