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

Commit a264e76

Browse filesBrowse files
author
Amrouche Hamza
committed
fix - #20685: add class name to the cache key
1 parent b699e4b commit a264e76
Copy full SHA for a264e76

File tree

7 files changed

+102
-5
lines changed
Filter options

7 files changed

+102
-5
lines changed
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Tests\Constraints\Fixtures;
13+
14+
use Symfony\Component\Validator\Constraints as Assert;
15+
16+
class ChildA
17+
{
18+
/**
19+
* @Assert\Valid
20+
* @Assert\NotBlank
21+
*/
22+
public $name;
23+
}
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Tests\Constraints\Fixtures;
13+
14+
use Symfony\Component\Validator\Constraints as Assert;
15+
16+
class ChildB
17+
{
18+
/**
19+
* @Assert\Valid
20+
* @Assert\NotBlank
21+
*/
22+
public $name;
23+
}

‎src/Symfony/Component/Validator/Tests/Fixtures/Entity.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Fixtures/Entity.php
+40-1Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,20 @@ class Entity extends EntityParent implements EntityInterfaceB
3333
* @Assert\Choice(choices={"A", "B"}, message="Must be one of %choices%")
3434
*/
3535
public $firstName;
36+
/**
37+
* @Assert\Valid
38+
*/
39+
public $childA;
40+
/**
41+
* @Assert\Valid
42+
*/
43+
public $childB;
3644
protected $lastName;
3745
public $reference;
3846
public $reference2;
3947
private $internal;
4048
public $data = 'Overridden data';
4149
public $initialized = false;
42-
4350
public function __construct($internal = null)
4451
{
4552
$this->internal = $internal;
@@ -97,4 +104,36 @@ public function validateMe(ExecutionContextInterface $context)
97104
public static function validateMeStatic($object, ExecutionContextInterface $context)
98105
{
99106
}
107+
108+
/**
109+
* @return mixed
110+
*/
111+
public function getChildA()
112+
{
113+
return $this->childA;
114+
}
115+
116+
/**
117+
* @param mixed $childA
118+
*/
119+
public function setChildA($childA)
120+
{
121+
$this->childA = $childA;
122+
}
123+
124+
/**
125+
* @return mixed
126+
*/
127+
public function getChildB()
128+
{
129+
return $this->childB;
130+
}
131+
132+
/**
133+
* @param mixed $childB
134+
*/
135+
public function setChildB($childB)
136+
{
137+
$this->childB = $childB;
138+
}
100139
}

‎src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Validator\Constraints\NotNull;
2020
use Symfony\Component\Validator\Constraints\Range;
2121
use Symfony\Component\Validator\Constraints\IsTrue;
22+
use Symfony\Component\Validator\Constraints\Valid;
2223
use Symfony\Component\Validator\Mapping\ClassMetadata;
2324
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
2425
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
@@ -67,6 +68,8 @@ public function testLoadClassMetadata()
6768
'message' => 'Must be one of %choices%',
6869
'choices' => array('A', 'B'),
6970
)));
71+
$expected->addPropertyConstraint('childA', new Valid());
72+
$expected->addPropertyConstraint('childB', new Valid());
7073
$expected->addGetterConstraint('lastName', new NotNull());
7174
$expected->addGetterConstraint('valid', new IsTrue());
7275
$expected->addGetterConstraint('permissions', new IsTrue());
@@ -137,6 +140,8 @@ public function testLoadClassMetadataAndMerge()
137140
'message' => 'Must be one of %choices%',
138141
'choices' => array('A', 'B'),
139142
)));
143+
$expected->addPropertyConstraint('childA', new Valid());
144+
$expected->addPropertyConstraint('childB', new Valid());
140145
$expected->addGetterConstraint('lastName', new NotNull());
141146
$expected->addGetterConstraint('valid', new IsTrue());
142147
$expected->addGetterConstraint('permissions', new IsTrue());

‎src/Symfony/Component/Validator/Tests/Validator/RecursiveContextualValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Validator/RecursiveContextualValidatorTest.php
Whitespace-only changes.

‎src/Symfony/Component/Validator/Tests/Validator/RecursiveValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Validator/RecursiveValidatorTest.php
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Symfony\Component\Validator\ConstraintValidatorFactory;
1616
use Symfony\Component\Validator\Context\ExecutionContextFactory;
1717
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
18+
use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildA;
19+
use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildB;
1820
use Symfony\Component\Validator\Tests\Fixtures\Entity;
1921
use Symfony\Component\Validator\Validator\RecursiveValidator;
2022

@@ -34,7 +36,12 @@ protected function createValidator(MetadataFactoryInterface $metadataFactory, ar
3436
public function testEmptyGroupsArrayDoesNotTriggerDeprecation()
3537
{
3638
$entity = new Entity();
37-
39+
$childA = new ChildA();
40+
$childB = new ChildB();
41+
$childA->name = false;
42+
$childB->name = 'fake';
43+
$entity->childA = array($childA);
44+
$entity->childB = array($childB);
3845
$validatorContext = $this->getMock('Symfony\Component\Validator\Validator\ContextualValidatorInterface');
3946
$validatorContext
4047
->expects($this->once())

‎src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public function validateProperty($object, $propertyName, $groups = null)
224224
$this->validateGenericNode(
225225
$propertyValue,
226226
$object,
227-
$cacheKey.':'.$propertyName,
227+
$cacheKey.':'.get_class($object).':'.$propertyName,
228228
$propertyMetadata,
229229
$propertyPath,
230230
$groups,
@@ -280,7 +280,7 @@ public function validatePropertyValue($objectOrClass, $propertyName, $value, $gr
280280
$this->validateGenericNode(
281281
$value,
282282
$object,
283-
$cacheKey.':'.$propertyName,
283+
$cacheKey.':'.get_class($object).':'.$propertyName,
284284
$propertyMetadata,
285285
$propertyPath,
286286
$groups,
@@ -589,7 +589,7 @@ private function validateClassNode($object, $cacheKey, ClassMetadataInterface $m
589589
$this->validateGenericNode(
590590
$propertyValue,
591591
$object,
592-
$cacheKey.':'.$propertyName,
592+
$cacheKey.':'.get_class($object).':'.$propertyName,
593593
$propertyMetadata,
594594
PropertyPath::append($propertyPath, $propertyName),
595595
$groups,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.