diff --git a/src/Symfony/Component/Validator/Constraints/GroupSequenceProvider.php b/src/Symfony/Component/Validator/Constraints/GroupSequenceProvider.php
index c6650842d7..457155981a 100644
--- a/src/Symfony/Component/Validator/Constraints/GroupSequenceProvider.php
+++ b/src/Symfony/Component/Validator/Constraints/GroupSequenceProvider.php
@@ -18,14 +18,5 @@ namespace Symfony\Component\Validator\Constraints;
*/
class GroupSequenceProvider
{
- /**
- * True if the group sequence provider should be used
- * @var boolean
- */
- public $active;
- public function __construct(array $options)
- {
- $this->active = (bool)$options['value'];
- }
}
diff --git a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php
index a59092ba7f..5c258dd2e4 100644
--- a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php
+++ b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php
@@ -307,7 +307,7 @@ class ClassMetadata extends ElementMetadata
*/
public function setGroupSequenceProvider($active)
{
- if ($this->hasGroupSequenceProvider()) {
+ if ($this->hasGroupSequence()) {
throw new GroupDefinitionException('Defining a group sequence provider is not allowed with a static group sequence');
}
diff --git a/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php
index b67c9d7bcd..30642a0474 100644
--- a/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php
+++ b/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php
@@ -40,7 +40,7 @@ class AnnotationLoader implements LoaderInterface
if ($constraint instanceof GroupSequence) {
$metadata->setGroupSequence($constraint->groups);
} elseif ($constraint instanceof GroupSequenceProvider) {
- $metadata->setGroupSequenceProvider($constraint->active);
+ $metadata->setGroupSequenceProvider(true);
} elseif ($constraint instanceof Constraint) {
$metadata->addConstraint($constraint);
}
diff --git a/src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php
index 0e3bedeaca..4c185c604d 100644
--- a/src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php
+++ b/src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php
@@ -44,7 +44,7 @@ class XmlFileLoader extends FileLoader
$xml = $this->classes[$metadata->getClassName()];
foreach ($xml->{'group-sequence-provider'} as $provider) {
- $metadata->setGroupSequenceProvider((bool)$provider['active']);
+ $metadata->setGroupSequenceProvider(true);
}
foreach ($this->parseConstraints($xml->constraint) as $constraint) {
diff --git a/src/Symfony/Component/Validator/Mapping/Loader/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd b/src/Symfony/Component/Validator/Mapping/Loader/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd
index 60a91be73e..6d5d3b5f95 100644
--- a/src/Symfony/Component/Validator/Mapping/Loader/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd
+++ b/src/Symfony/Component/Validator/Mapping/Loader/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd
@@ -66,7 +66,6 @@
Defines the name of the group sequence provider for a class.
]]>
-
diff --git a/tests/Symfony/Tests/Component/Validator/Fixtures/Entity.php b/tests/Symfony/Tests/Component/Validator/Fixtures/Entity.php
index 62aaa15ea4..e6c6316930 100644
--- a/tests/Symfony/Tests/Component/Validator/Fixtures/Entity.php
+++ b/tests/Symfony/Tests/Component/Validator/Fixtures/Entity.php
@@ -11,9 +11,8 @@ use Symfony\Component\Validator\GroupSequenceProviderInterface;
/**
* @Symfony\Tests\Component\Validator\Fixtures\ConstraintA
* @Assert\GroupSequence({"Foo", "Entity"})
- * @Assert\GroupSequenceProvider("Symfony\Tests\Component\Validator\Fixtures\GroupSequenceProvider")
*/
-class Entity extends EntityParent implements EntityInterface, GroupSequenceProviderInterface
+class Entity extends EntityParent implements EntityInterface
{
/**
* @Assert\NotNull
@@ -51,14 +50,4 @@ class Entity extends EntityParent implements EntityInterface, GroupSequenceProvi
{
return $this->lastName;
}
-
- public function setGroups($groups)
- {
- $this->groups = $groups;
- }
-
- public function getValidationGroups()
- {
- return $this->groups;
- }
}
diff --git a/tests/Symfony/Tests/Component/Validator/Fixtures/GroupSequenceProviderEntity.php b/tests/Symfony/Tests/Component/Validator/Fixtures/GroupSequenceProviderEntity.php
new file mode 100644
index 0000000000..9516c476d3
--- /dev/null
+++ b/tests/Symfony/Tests/Component/Validator/Fixtures/GroupSequenceProviderEntity.php
@@ -0,0 +1,27 @@
+groups = $groups;
+ }
+
+ public function getValidationGroups()
+ {
+ return $this->groups;
+ }
+}
diff --git a/tests/Symfony/Tests/Component/Validator/Mapping/ClassMetadataTest.php b/tests/Symfony/Tests/Component/Validator/Mapping/ClassMetadataTest.php
index 646c06e08a..a3f68f8f30 100644
--- a/tests/Symfony/Tests/Component/Validator/Mapping/ClassMetadataTest.php
+++ b/tests/Symfony/Tests/Component/Validator/Mapping/ClassMetadataTest.php
@@ -30,6 +30,7 @@ class ClassMetadataTest extends \PHPUnit_Framework_TestCase
{
const CLASSNAME = 'Symfony\Tests\Component\Validator\Fixtures\Entity';
const PARENTCLASS = 'Symfony\Tests\Component\Validator\Fixtures\EntityParent';
+ const PROVIDERCLASS = 'Symfony\Tests\Component\Validator\Fixtures\GroupSequenceProviderEntity';
protected $metadata;
@@ -192,7 +193,29 @@ class ClassMetadataTest extends \PHPUnit_Framework_TestCase
$this->metadata->setGroupSequence(array('Foo', $this->metadata->getDefaultGroup(), Constraint::DEFAULT_GROUP));
}
- public function testGroupSequenceProvider()
+ public function testGroupSequenceFailesIfGroupSequenceProviderIsSet()
+ {
+ $metadata = new ClassMetadata(self::PROVIDERCLASS);
+ $metadata->setGroupSequenceProvider(true);
+
+ try {
+ $metadata->setGroupSequence(array('GroupSequenceProviderEntity', 'Foo'));
+ $this->fail();
+ } catch(GroupDefinitionException $e) {}
+ }
+
+ public function testGroupSequenceProviderFailesIfGroupSequenceIsSet()
+ {
+ $metadata = new ClassMetadata(self::PROVIDERCLASS);
+ $metadata->setGroupSequence(array('GroupSequenceProviderEntity', 'Foo'));
+
+ try {
+ $metadata->setGroupSequenceProvider(true);
+ $this->fail();
+ } catch(GroupDefinitionException $e) {}
+ }
+
+ public function testGroupSequenceProviderFailesIfDomainClassIsInvalid()
{
$metadata = new ClassMetadata('stdClass');
@@ -200,8 +223,12 @@ class ClassMetadataTest extends \PHPUnit_Framework_TestCase
$metadata->setGroupSequenceProvider(true);
$this->fail();
} catch(GroupDefinitionException $e) {}
+ }
- $this->metadata->setGroupSequenceProvider(true);
- $this->assertTrue($this->metadata->hasGroupSequenceProvider());
+ public function testGroupSequenceProvider()
+ {
+ $metadata = new ClassMetadata(self::PROVIDERCLASS);
+ $metadata->setGroupSequenceProvider(true);
+ $this->assertTrue($metadata->hasGroupSequenceProvider());
}
}
diff --git a/tests/Symfony/Tests/Component/Validator/Mapping/Loader/AnnotationLoaderTest.php b/tests/Symfony/Tests/Component/Validator/Mapping/Loader/AnnotationLoaderTest.php
index cf9f30669f..2a6e5dbf54 100644
--- a/tests/Symfony/Tests/Component/Validator/Mapping/Loader/AnnotationLoaderTest.php
+++ b/tests/Symfony/Tests/Component/Validator/Mapping/Loader/AnnotationLoaderTest.php
@@ -73,7 +73,6 @@ class AnnotationLoaderTest extends \PHPUnit_Framework_TestCase
'choices' => array('A', 'B'),
)));
$expected->addGetterConstraint('lastName', new NotNull());
- $expected->setGroupSequenceProvider(true);
// load reflection class so that the comparison passes
$expected->getReflectionClass();
@@ -138,7 +137,6 @@ class AnnotationLoaderTest extends \PHPUnit_Framework_TestCase
'choices' => array('A', 'B'),
)));
$expected->addGetterConstraint('lastName', new NotNull());
- $expected->setGroupSequenceProvider(true);
// load reflection class so that the comparison passes
$expected->getReflectionClass();
@@ -146,4 +144,17 @@ class AnnotationLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expected, $metadata);
}
+ public function testLoadGroupSequenceProviderAnnotation()
+ {
+ $loader = new AnnotationLoader(new AnnotationReader());
+
+ $metadata = new ClassMetadata('Symfony\Tests\Component\Validator\Fixtures\GroupSequenceProviderEntity');
+ $loader->loadClassMetadata($metadata);
+
+ $expected = new ClassMetadata('Symfony\Tests\Component\Validator\Fixtures\GroupSequenceProviderEntity');
+ $expected->setGroupSequenceProvider(true);
+ $expected->getReflectionClass();
+
+ $this->assertEquals($expected, $metadata);
+ }
}
diff --git a/tests/Symfony/Tests/Component/Validator/Mapping/Loader/XmlFileLoaderTest.php b/tests/Symfony/Tests/Component/Validator/Mapping/Loader/XmlFileLoaderTest.php
index 5aa47b001e..8afae6c1ef 100644
--- a/tests/Symfony/Tests/Component/Validator/Mapping/Loader/XmlFileLoaderTest.php
+++ b/tests/Symfony/Tests/Component/Validator/Mapping/Loader/XmlFileLoaderTest.php
@@ -67,6 +67,18 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
'choices' => array('A', 'B'),
)));
$expected->addGetterConstraint('lastName', new NotNull());
+
+ $this->assertEquals($expected, $metadata);
+ }
+
+ public function testLoadGroupSequenceProvider()
+ {
+ $loader = new XmlFileLoader(__DIR__.'/constraint-mapping.xml');
+ $metadata = new ClassMetadata('Symfony\Tests\Component\Validator\Fixtures\GroupSequenceProviderEntity');
+
+ $loader->loadClassMetadata($metadata);
+
+ $expected = new ClassMetadata('Symfony\Tests\Component\Validator\Fixtures\GroupSequenceProviderEntity');
$expected->setGroupSequenceProvider(true);
$this->assertEquals($expected, $metadata);
diff --git a/tests/Symfony/Tests/Component/Validator/Mapping/Loader/YamlFileLoaderTest.php b/tests/Symfony/Tests/Component/Validator/Mapping/Loader/YamlFileLoaderTest.php
index a1d54e5b9c..2d1d458efe 100644
--- a/tests/Symfony/Tests/Component/Validator/Mapping/Loader/YamlFileLoaderTest.php
+++ b/tests/Symfony/Tests/Component/Validator/Mapping/Loader/YamlFileLoaderTest.php
@@ -85,6 +85,18 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
'choices' => array('A', 'B'),
)));
$expected->addGetterConstraint('lastName', new NotNull());
+
+ $this->assertEquals($expected, $metadata);
+ }
+
+ public function testLoadGroupSequenceProvider()
+ {
+ $loader = new YamlFileLoader(__DIR__.'/constraint-mapping.yml');
+ $metadata = new ClassMetadata('Symfony\Tests\Component\Validator\Fixtures\GroupSequenceProviderEntity');
+
+ $loader->loadClassMetadata($metadata);
+
+ $expected = new ClassMetadata('Symfony\Tests\Component\Validator\Fixtures\GroupSequenceProviderEntity');
$expected->setGroupSequenceProvider(true);
$this->assertEquals($expected, $metadata);
diff --git a/tests/Symfony/Tests/Component/Validator/Mapping/Loader/constraint-mapping.xml b/tests/Symfony/Tests/Component/Validator/Mapping/Loader/constraint-mapping.xml
index 7c1eeeeb32..916394b1bd 100644
--- a/tests/Symfony/Tests/Component/Validator/Mapping/Loader/constraint-mapping.xml
+++ b/tests/Symfony/Tests/Component/Validator/Mapping/Loader/constraint-mapping.xml
@@ -8,9 +8,6 @@
-
-
-
@@ -80,4 +77,11 @@
+
+
+
+
+
+
+
diff --git a/tests/Symfony/Tests/Component/Validator/Mapping/Loader/constraint-mapping.yml b/tests/Symfony/Tests/Component/Validator/Mapping/Loader/constraint-mapping.yml
index 1ea139b153..cd4b9355e1 100644
--- a/tests/Symfony/Tests/Component/Validator/Mapping/Loader/constraint-mapping.yml
+++ b/tests/Symfony/Tests/Component/Validator/Mapping/Loader/constraint-mapping.yml
@@ -2,7 +2,6 @@ namespaces:
custom: Symfony\Tests\Component\Validator\Fixtures\
Symfony\Tests\Component\Validator\Fixtures\Entity:
- group_sequence_provider: true
constraints:
# Custom constraint
- Symfony\Tests\Component\Validator\Fixtures\ConstraintA: ~
@@ -40,3 +39,6 @@ Symfony\Tests\Component\Validator\Fixtures\Entity:
getters:
lastName:
- NotNull: ~
+
+Symfony\Tests\Component\Validator\Fixtures\GroupSequenceProviderEntity:
+ group_sequence_provider: true
diff --git a/tests/Symfony/Tests/Component/Validator/ValidatorTest.php b/tests/Symfony/Tests/Component/Validator/ValidatorTest.php
index 3726761571..a9fdc267e0 100644
--- a/tests/Symfony/Tests/Component/Validator/ValidatorTest.php
+++ b/tests/Symfony/Tests/Component/Validator/ValidatorTest.php
@@ -17,6 +17,7 @@ require_once __DIR__.'/Fixtures/FailingConstraintValidator.php';
require_once __DIR__.'/Fixtures/FakeClassMetadataFactory.php';
use Symfony\Tests\Component\Validator\Fixtures\Entity;
+use Symfony\Tests\Component\Validator\Fixtures\GroupSequenceProviderEntity;
use Symfony\Tests\Component\Validator\Fixtures\FakeClassMetadataFactory;
use Symfony\Tests\Component\Validator\Fixtures\FailingConstraint;
use Symfony\Component\Validator\Validator;
@@ -124,7 +125,7 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase
public function testValidate_groupSequenceProvider()
{
- $entity = new Entity();
+ $entity = new GroupSequenceProviderEntity();
$metadata = new ClassMetadata(get_class($entity));
$metadata->addPropertyConstraint('firstName', new FailingConstraint(array(
'groups' => 'First',