Skip to content

Commit 10fdc38

Browse files
Merge branch '3.1'
* 3.1: fix typo add "provides" for psr/cache-implementation [Validator][GroupSequence] fixed GroupSequence validation ignores PropertyMetadata of parent classes [FrameworkBundle][Security] Remove useless mocks Add symfony/inflector to composer.json "replaces" [DoctrineBridge] Enhance exception message in EntityUserProvider added friendly exception when constraint validator does not exist or it is not enabled remove duplicate instruction [FrameworkBundle] Remove TranslatorBagInterface check [FrameworkBundle] Remove duplicated code in RouterDebugCommand [Validator] fixed duplicate constraints with parent class interfaces SecurityBundle:BasicAuthenticationListener: removed a default argument on getting a header value
2 parents 6688894 + 96cad1c commit 10fdc38

File tree

6 files changed

+55
-23
lines changed

6 files changed

+55
-23
lines changed

Mapping/ClassMetadata.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ public function mergeConstraints(ClassMetadata $source)
308308
$member = clone $member;
309309

310310
foreach ($member->getConstraints() as $constraint) {
311+
$member->constraintsByGroup[$this->getDefaultGroup()][] = $constraint;
311312
$constraint->addImplicitGroupName($this->getDefaultGroup());
312313
}
313314

Mapping/Factory/LazyLoadingMetadataFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ public function getMetadataFor($value)
114114
$metadata->mergeConstraints($this->getMetadataFor($parent->name));
115115
}
116116

117-
// Include constraints from all implemented interfaces
117+
// Include constraints from all implemented interfaces that have not been processed via parent class yet
118118
foreach ($metadata->getReflectionClass()->getInterfaces() as $interface) {
119-
if ('Symfony\Component\Validator\GroupSequenceProviderInterface' === $interface->name) {
119+
if ('Symfony\Component\Validator\GroupSequenceProviderInterface' === $interface->name || ($parent && $parent->implementsInterface($interface->name))) {
120120
continue;
121121
}
122122
$metadata->mergeConstraints($this->getMetadataFor($interface->name));

Tests/Fixtures/Entity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @Assert\GroupSequence({"Foo", "Entity"})
2020
* @Assert\Callback({"Symfony\Component\Validator\Tests\Fixtures\CallbackClass", "callback"})
2121
*/
22-
class Entity extends EntityParent implements EntityInterface
22+
class Entity extends EntityParent
2323
{
2424
/**
2525
* @Assert\NotNull

Tests/Fixtures/EntityParent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\Validator\Constraints\NotNull;
1515

16-
class EntityParent
16+
class EntityParent implements EntityInterface
1717
{
1818
protected $firstName;
1919
private $internal;

Tests/Mapping/ClassMetadataTest.php

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,41 @@ public function testMergeConstraintsMergesMemberConstraints()
138138
$this->metadata->mergeConstraints($parent);
139139
$this->metadata->addPropertyConstraint('firstName', new ConstraintA());
140140

141+
$constraintA1 = new ConstraintA(array('groups' => array(
142+
'Default',
143+
'EntityParent',
144+
'Entity',
145+
)));
146+
$constraintA2 = new ConstraintA(array('groups' => array(
147+
'Default',
148+
'Entity',
149+
)));
150+
141151
$constraints = array(
142-
new ConstraintA(array('groups' => array(
143-
'Default',
144-
'EntityParent',
145-
'Entity',
146-
))),
147-
new ConstraintA(array('groups' => array(
148-
'Default',
149-
'Entity',
150-
))),
152+
$constraintA1,
153+
$constraintA2,
154+
);
155+
156+
$constraintsByGroup = array(
157+
'Default' => array(
158+
$constraintA1,
159+
$constraintA2,
160+
),
161+
'EntityParent' => array(
162+
$constraintA1,
163+
),
164+
'Entity' => array(
165+
$constraintA1,
166+
$constraintA2,
167+
),
151168
);
152169

153170
$members = $this->metadata->getPropertyMetadata('firstName');
154171

155172
$this->assertCount(1, $members);
156173
$this->assertEquals(self::PARENTCLASS, $members[0]->getClassName());
157174
$this->assertEquals($constraints, $members[0]->getConstraints());
175+
$this->assertEquals($constraintsByGroup, $members[0]->constraintsByGroup);
158176
}
159177

160178
public function testMemberMetadatas()

Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ class LazyLoadingMetadataFactoryTest extends \PHPUnit_Framework_TestCase
2020
{
2121
const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
2222
const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent';
23+
const INTERFACECLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityInterface';
2324

24-
public function testLoadClassMetadata()
25+
public function testLoadClassMetadataWithInterface()
2526
{
2627
$factory = new LazyLoadingMetadataFactory(new TestLoader());
2728
$metadata = $factory->getMetadataFor(self::PARENTCLASS);
2829

2930
$constraints = array(
31+
new ConstraintA(array('groups' => array('Default', 'EntityInterface', 'EntityParent'))),
3032
new ConstraintA(array('groups' => array('Default', 'EntityParent'))),
3133
);
3234

@@ -41,12 +43,13 @@ public function testMergeParentConstraints()
4143
$constraints = array(
4244
new ConstraintA(array('groups' => array(
4345
'Default',
46+
'EntityInterface',
4447
'EntityParent',
4548
'Entity',
4649
))),
4750
new ConstraintA(array('groups' => array(
4851
'Default',
49-
'EntityInterface',
52+
'EntityParent',
5053
'Entity',
5154
))),
5255
new ConstraintA(array('groups' => array(
@@ -63,26 +66,36 @@ public function testWriteMetadataToCache()
6366
$cache = $this->getMock('Symfony\Component\Validator\Mapping\Cache\CacheInterface');
6467
$factory = new LazyLoadingMetadataFactory(new TestLoader(), $cache);
6568

66-
$constraints = array(
69+
$parentClassConstraints = array(
70+
new ConstraintA(array('groups' => array('Default', 'EntityInterface', 'EntityParent'))),
6771
new ConstraintA(array('groups' => array('Default', 'EntityParent'))),
6872
);
73+
$interfaceConstraints = array(new ConstraintA(array('groups' => array('Default', 'EntityInterface'))));
6974

7075
$cache->expects($this->never())
7176
->method('has');
72-
$cache->expects($this->once())
77+
$cache->expects($this->exactly(2))
7378
->method('read')
74-
->with($this->equalTo(self::PARENTCLASS))
79+
->withConsecutive(
80+
array($this->equalTo(self::PARENTCLASS)),
81+
array($this->equalTo(self::INTERFACECLASS))
82+
)
7583
->will($this->returnValue(false));
76-
$cache->expects($this->once())
84+
$cache->expects($this->exactly(2))
7785
->method('write')
78-
->will($this->returnCallback(function ($metadata) use ($constraints) {
79-
$this->assertEquals($constraints, $metadata->getConstraints());
80-
}));
86+
->withConsecutive(
87+
$this->callback(function ($metadata) use ($interfaceConstraints) {
88+
return $interfaceConstraints == $metadata->getConstraints();
89+
}),
90+
$this->callback(function ($metadata) use ($parentClassConstraints) {
91+
return $parentClassConstraints == $metadata->getConstraints();
92+
})
93+
);
8194

8295
$metadata = $factory->getMetadataFor(self::PARENTCLASS);
8396

8497
$this->assertEquals(self::PARENTCLASS, $metadata->getClassName());
85-
$this->assertEquals($constraints, $metadata->getConstraints());
98+
$this->assertEquals($parentClassConstraints, $metadata->getConstraints());
8699
}
87100

88101
public function testReadMetadataFromCache()

0 commit comments

Comments
 (0)