Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Validator] add class name to the cache key #20745

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Validator\Tests\Constraints\Fixtures;

use Symfony\Component\Validator\Constraints as Assert;

class ChildA
{
/**
* @Assert\Valid
* @Assert\NotNull
* @Assert\NotBlank
*/
public $name;
/**
* @var ChildB
* @Assert\Valid
* @Assert\NotNull
*/
public $childB;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Validator\Tests\Constraints\Fixtures;

use Symfony\Component\Validator\Constraints as Assert;

class ChildB
{
/**
* @Assert\Valid
* @Assert\NotBlank
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use another assertion to be sure that there is no collision.

*/
public $name;
/**
* @var ChildA
* @Assert\Valid
* @Assert\NotBlank
*/
public $childA;
}
41 changes: 40 additions & 1 deletion 41 src/Symfony/Component/Validator/Tests/Fixtures/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ class Entity extends EntityParent implements EntityInterfaceB
* @Assert\Choice(choices={"A", "B"}, message="Must be one of %choices%")
*/
public $firstName;
/**
* @Assert\Valid
*/
public $childA;
/**
* @Assert\Valid
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line should be kept

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

public $childB;
protected $lastName;
public $reference;
public $reference2;
private $internal;
public $data = 'Overridden data';
public $initialized = false;

public function __construct($internal = null)
{
$this->internal = $internal;
Expand Down Expand Up @@ -97,4 +104,36 @@ public function validateMe(ExecutionContextInterface $context)
public static function validateMeStatic($object, ExecutionContextInterface $context)
{
}

/**
* @return mixed
*/
public function getChildA()
{
return $this->childA;
}

/**
* @param mixed $childA
*/
public function setChildA($childA)
{
$this->childA = $childA;
}

/**
* @return mixed
*/
public function getChildB()
{
return $this->childB;
}

/**
* @param mixed $childB
*/
public function setChildB($childB)
{
$this->childB = $childB;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\Constraints\Range;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
Expand Down Expand Up @@ -67,6 +68,8 @@ public function testLoadClassMetadata()
'message' => 'Must be one of %choices%',
'choices' => array('A', 'B'),
)));
$expected->addPropertyConstraint('childA', new Valid());
$expected->addPropertyConstraint('childB', new Valid());
$expected->addGetterConstraint('lastName', new NotNull());
$expected->addGetterConstraint('valid', new IsTrue());
$expected->addGetterConstraint('permissions', new IsTrue());
Expand Down Expand Up @@ -137,6 +140,8 @@ public function testLoadClassMetadataAndMerge()
'message' => 'Must be one of %choices%',
'choices' => array('A', 'B'),
)));
$expected->addPropertyConstraint('childA', new Valid());
$expected->addPropertyConstraint('childB', new Valid());
$expected->addGetterConstraint('lastName', new NotNull());
$expected->addGetterConstraint('valid', new IsTrue());
$expected->addGetterConstraint('permissions', new IsTrue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Symfony\Component\Validator\ConstraintValidatorFactory;
use Symfony\Component\Validator\Context\ExecutionContextFactory;
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildA;
use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildB;
use Symfony\Component\Validator\Tests\Fixtures\Entity;
use Symfony\Component\Validator\Validator\RecursiveValidator;

Expand All @@ -34,6 +36,45 @@ protected function createValidator(MetadataFactoryInterface $metadataFactory, ar
public function testEmptyGroupsArrayDoesNotTriggerDeprecation()
{
$entity = new Entity();
$childA = new ChildA();
$childB = new ChildB();
$childA->name = false;
$childB->name = 'fake';
$entity->childA = array($childA);
$entity->childB = array($childB);
$validatorContext = $this->getMock('Symfony\Component\Validator\Validator\ContextualValidatorInterface');
$validatorContext
->expects($this->once())
->method('validate')
->with($entity, null, array())
->willReturnSelf();

$validator = $this
->getMockBuilder('Symfony\Component\Validator\Validator\RecursiveValidator')
->disableOriginalConstructor()
->setMethods(array('startContext'))
->getMock();
$validator
->expects($this->once())
->method('startContext')
->willReturn($validatorContext);

$validator->validate($entity, null, array());
}

public function testRelationBetweenChildAAndChildB()
{
$entity = new Entity();
$childA = new ChildA();
$childB = new ChildB();

$childA->childB = $childB;
$childB->childA = $childA;

$childA->name = false;
$childB->name = 'fake';
$entity->childA = array($childA);
$entity->childB = array($childB);

$validatorContext = $this->getMock('Symfony\Component\Validator\Validator\ContextualValidatorInterface');
$validatorContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function validateProperty($object, $propertyName, $groups = null)
$this->validateGenericNode(
$propertyValue,
$object,
$cacheKey.':'.$propertyName,
$cacheKey.':'.get_class($object).':'.$propertyName,
$propertyMetadata,
$propertyPath,
$groups,
Expand Down Expand Up @@ -280,7 +280,7 @@ public function validatePropertyValue($objectOrClass, $propertyName, $value, $gr
$this->validateGenericNode(
$value,
$object,
$cacheKey.':'.$propertyName,
$cacheKey.':'.get_class($object).':'.$propertyName,
$propertyMetadata,
$propertyPath,
$groups,
Expand Down Expand Up @@ -589,7 +589,7 @@ private function validateClassNode($object, $cacheKey, ClassMetadataInterface $m
$this->validateGenericNode(
$propertyValue,
$object,
$cacheKey.':'.$propertyName,
$cacheKey.':'.get_class($object).':'.$propertyName,
$propertyMetadata,
PropertyPath::append($propertyPath, $propertyName),
$groups,
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.