Skip to content

[Validator] Validator ignores $constraints argument #28257

@BoShurik

Description

@BoShurik

Symfony version(s) affected: 4.1.3

Description
When passing constraint to validate method I've got violations from annotation constrains.

How to reproduce
https://github.com/BoShurik/symfony-validator-issue

class Foo
{
    /**
     * @var Bar[]
     *
     * @Assert\Valid()
     */
    public $bars;

    public function __construct()
    {
        $this->bars = [
            new Bar(),
            new Bar(),
        ];
    }
}
$violations = $this->validator->validate($model->bars, new Count([
    'min' => 3,
    'max' => 3,
]));
/** @var ConstraintViolationInterface $violation */
foreach ($violations as $violation) {
    dump(sprintf('%s: %s', $violation->getPropertyPath(), $violation->getMessage()));
}

/*
    Got:
    ": This collection should contain exactly 3 elements."
    "[0].name: This value should not be blank." <- not expected
    "[1].name: This value should not be blank." <- not expected
 */

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions