Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Validator] Handling of lists slightly changed from 4.2.5 to 4.2.6 #33903

Closed
rejinka opened this issue Oct 8, 2019 · 3 comments
Closed

[Validator] Handling of lists slightly changed from 4.2.5 to 4.2.6 #33903

rejinka opened this issue Oct 8, 2019 · 3 comments

Comments

@rejinka
Copy link

rejinka commented Oct 8, 2019

Symfony version(s) affected: >=4.2.6,>=4.3.0

Description
Please read the text in context of the part "how to reproduce".

In Symfony 4.2.5, it was not necessary to add the Valid-Constraint to a list to get the objects in this list to be validated (e.g. would result in a NotNull-Violation, if the name was null). In 4.2.6 this is now necessary.

I didn't found anything about this behavior-change. Therefore i searched the documentation, the UPGRADE- and CHANGELOG-files and the tests in the validator-component. Also i don't know, whether this should be handled as a BC-break or a Bugfix (as it always was necessary to use the Valid-Constraint, if the relation was 1:1).

How to reproduce

<?php
declare(strict_types = 1);

namespace Tests;

use Doctrine\Common\Annotations\AnnotationReader;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Validator\ValidatorBuilder;

class Parent_425
{

    /**
     * @Assert\All(
     *     @Assert\Type(Child_::class)
     * )
     */
    public $children;

}

class Parent_426
{

    /**
     * @Assert\All(
     *     @Assert\Type(Child_::class)
     * )
     * @Assert\Valid
     */
    public $children;

}

class Child_
{

    /**
     * @Assert\NotNull
     */
    public $name = null;

}


class Valid extends TestCase
{

    /**
     * @var ValidatorInterface
     */
    private $validator;

    protected function setUp()
    {
        $this->validator = (new ValidatorBuilder())
            ->addLoader(
                new AnnotationLoader(
                    new AnnotationReader(

                    )
                )
            )
            ->getValidator();
    }

    /**
     * @test
     */
    public function valid_constraint_not_needed_in_425()
    {
        $parent = new Parent_425();
        $parent->children = [new Child_()];

        $violations = $this->validator->validate($parent);

        self::assertSame(1, $violations->count(), sprintf('Not correct in %s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION));
    }

    /**
     * @test
     */
    public function valid_constraint_needed_since_426()
    {
        $parent = new Parent_426();
        $parent->children = [new Child_()];

        $violations = $this->validator->validate($parent);

        self::assertSame(1, $violations->count(), sprintf('Not correct in %s:%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION));
    }

}
@rejinka rejinka changed the title [Validator] Handling of lists slightly changed from 4.2 to 4.3 [Validator] Handling of lists slightly changed from 4.2.5 to 4.2.6 Oct 8, 2019
@rejinka
Copy link
Author

rejinka commented Oct 8, 2019

Okay, i took another look and my test breaks with 4.2.6

@xabbuh
Copy link
Member

xabbuh commented Oct 8, 2019

I think this is due to the changes made in #29800. /cc @corphi

@HeahDude
Copy link
Contributor

HeahDude commented Apr 8, 2020

This is indeed due to #29800. We should close here, as there is nothing more to fix.

@xabbuh xabbuh closed this as completed Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants