From 1ddb42dcdcb3aff234899af8ab67e0258d5ef786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Morales=20Valldep=C3=A9rez?= Date: Thu, 9 Jan 2014 20:50:52 +0100 Subject: [PATCH 1/3] [Validator] added improve support for collection validation --- .../Constraints/AbstractComposite.php | 134 ++++ .../AbstractCompositeValidator.php | 47 ++ .../Component/Validator/Constraints/All.php | 40 +- .../Validator/Constraints/AllValidator.php | 28 +- .../Component/Validator/Constraints/Each.php | 27 + .../Validator/Constraints/EachValidator.php | 40 ++ .../Component/Validator/Constraints/None.php | 35 + .../Validator/Constraints/NoneValidator.php | 55 ++ .../Component/Validator/Constraints/Some.php | 90 +++ .../Validator/Constraints/SomeValidator.php | 74 ++ .../Validator/Constraints/Unique.php | 34 + .../Validator/Constraints/UniqueValidator.php | 55 ++ .../Component/Validator/ExecutionContext.php | 12 + .../Constraints/AbstractCompositeTest.php | 207 ++++++ .../Validator/Tests/Constraints/EachTest.php | 44 ++ .../Tests/Constraints/EachValidatorTest.php | 118 +++ .../Validator/Tests/Constraints/NoneTest.php | 44 ++ .../Tests/Constraints/NoneValidatorTest.php | 279 +++++++ .../Validator/Tests/Constraints/SomeTest.php | 44 ++ .../Tests/Constraints/SomeValidatorTest.php | 679 ++++++++++++++++++ .../Tests/Constraints/UniqueTest.php | 30 + .../Tests/Constraints/UniqueValidatorTest.php | 159 ++++ .../Tests/Fixtures/EntityCollection.php | 31 + .../Component/Validator/ValidationVisitor.php | 12 + src/Symfony/Component/Validator/composer.json | 3 +- 25 files changed, 2262 insertions(+), 59 deletions(-) create mode 100644 src/Symfony/Component/Validator/Constraints/AbstractComposite.php create mode 100644 src/Symfony/Component/Validator/Constraints/AbstractCompositeValidator.php create mode 100644 src/Symfony/Component/Validator/Constraints/Each.php create mode 100644 src/Symfony/Component/Validator/Constraints/EachValidator.php create mode 100644 src/Symfony/Component/Validator/Constraints/None.php create mode 100644 src/Symfony/Component/Validator/Constraints/NoneValidator.php create mode 100644 src/Symfony/Component/Validator/Constraints/Some.php create mode 100644 src/Symfony/Component/Validator/Constraints/SomeValidator.php create mode 100644 src/Symfony/Component/Validator/Constraints/Unique.php create mode 100644 src/Symfony/Component/Validator/Constraints/UniqueValidator.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/AbstractCompositeTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/EachTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/EachValidatorTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/NoneTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/NoneValidatorTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/SomeTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/SomeValidatorTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Fixtures/EntityCollection.php diff --git a/src/Symfony/Component/Validator/Constraints/AbstractComposite.php b/src/Symfony/Component/Validator/Constraints/AbstractComposite.php new file mode 100644 index 000000000000..8f6591b02e99 --- /dev/null +++ b/src/Symfony/Component/Validator/Constraints/AbstractComposite.php @@ -0,0 +1,134 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Constraints; + +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\Exception\ConstraintDefinitionException; + +/** + * @Annotation + * + * @author Marc Morales Valldepérez + * @author Marc Morera Merino + */ +abstract class AbstractComposite extends Constraint +{ + + /** + * @var array + * + * Set of constraints + */ + public $constraints = array(); + + + /** + * {@inheritDoc} + */ + public function __construct($options = null) + { + parent::__construct($options); + + if (!is_array($this->constraints)) { + $this->constraints = array($this->constraints); + } + + /** + * We consider explicid groups are defined if are not default one + */ + $areExplicitGroupsDefined = ( $this->groups != array(self::DEFAULT_GROUP) ); + + /** + * Each constraint contained + */ + foreach ($this->constraints as $constraint) { + if (!$constraint instanceof Constraint) { + throw new ConstraintDefinitionException(sprintf('The value %s is not an instance of Constraint in constraint %s', $constraint, __CLASS__)); + } + + if ($constraint instanceof Valid) { + throw new ConstraintDefinitionException(sprintf('The constraint Valid cannot be nested inside constraint %s. You can only declare the Valid constraint directly on a field or method.', __CLASS__)); + } + + /** + * If explicid groups are defined + */ + if ($areExplicitGroupsDefined) { + /** + * If constraint has explicid groups defined + * + * In that case, the groups of the nested constraint need to be + * a subset of the groups of the outer constraint. + */ + if ($constraint->groups != array(self::DEFAULT_GROUP)) { + /** + * If are not a subset + */ + if ($constraint->groups != array_intersect($constraint->groups, $this->groups)) { + throw new ConstraintDefinitionException(sprintf('The groups defined in Constraint %s must be a subset of the groups defined in the Constraint %s', $constraint, __CLASS__)); + } + + /** + * Otherwise, we add all defined groups here + */ + } else { + foreach ($this->groups as $group) { + $constraint->addImplicitGroupName($group); + } + } + + /** + * Otherwise, we merge current groups with constraint + */ + } else { + $this->groups = array_unique(array_merge($this->groups, $constraint->groups)); + } + } + } + + + /** + * Adds the given group if this constraint is in the Default group + * + * Also propagate same method to nested Constraints + * + * @param string $group + * + * @api + */ + public function addImplicitGroupName($group) + { + parent::addImplicitGroupName($group); + + foreach ($this->constraints as $constraint) { + $constraint->addImplicitGroupName($group); + } + } + + + /** + * {@inheritDoc} + */ + public function getDefaultOption() + { + return 'constraints'; + } + + + /** + * {@inheritDoc} + */ + public function getRequiredOptions() + { + return array('constraints'); + } +} diff --git a/src/Symfony/Component/Validator/Constraints/AbstractCompositeValidator.php b/src/Symfony/Component/Validator/Constraints/AbstractCompositeValidator.php new file mode 100644 index 000000000000..d425191f3b57 --- /dev/null +++ b/src/Symfony/Component/Validator/Constraints/AbstractCompositeValidator.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Constraints; + +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; + +/** + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + */ +abstract class AbstractCompositeValidator extends ConstraintValidator +{ + + /** + * {@inheritDoc} + */ + abstract public function doValidate($value, Constraint $constraint); + + + /** + * {@inheritDoc} + */ + public function validate($value, Constraint $constraint) + { + if (null === $value) { + return; + } + + if (!is_array($value) && !$value instanceof \Traversable) { + throw new UnexpectedTypeException($value, 'array or Traversable'); + } + + $this->doValidate($value, $constraint); + } +} diff --git a/src/Symfony/Component/Validator/Constraints/All.php b/src/Symfony/Component/Validator/Constraints/All.php index 537168625ca0..42a7344be0d2 100644 --- a/src/Symfony/Component/Validator/Constraints/All.php +++ b/src/Symfony/Component/Validator/Constraints/All.php @@ -11,8 +11,7 @@ namespace Symfony\Component\Validator\Constraints; -use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\Exception\ConstraintDefinitionException; +use Symfony\Component\Validator\Constraints\Each; /** * @Annotation @@ -20,40 +19,11 @@ * @author Bernhard Schussek * * @api + * + * @deprecated Deprecated in 2.5, to be removed in 3.0. Use + * {@link \Symfony\Component\Validator\Constraints\Each} instead. */ -class All extends Constraint +class All extends Each { - public $constraints = array(); - - /** - * {@inheritDoc} - */ - public function __construct($options = null) - { - parent::__construct($options); - - if (!is_array($this->constraints)) { - $this->constraints = array($this->constraints); - } - - foreach ($this->constraints as $constraint) { - if (!$constraint instanceof Constraint) { - throw new ConstraintDefinitionException(sprintf('The value %s is not an instance of Constraint in constraint %s', $constraint, __CLASS__)); - } - - if ($constraint instanceof Valid) { - throw new ConstraintDefinitionException(sprintf('The constraint Valid cannot be nested inside constraint %s. You can only declare the Valid constraint directly on a field or method.', __CLASS__)); - } - } - } - - public function getDefaultOption() - { - return 'constraints'; - } - public function getRequiredOptions() - { - return array('constraints'); - } } diff --git a/src/Symfony/Component/Validator/Constraints/AllValidator.php b/src/Symfony/Component/Validator/Constraints/AllValidator.php index c38f19a6669c..b5dfc81a5913 100644 --- a/src/Symfony/Component/Validator/Constraints/AllValidator.php +++ b/src/Symfony/Component/Validator/Constraints/AllValidator.php @@ -12,35 +12,17 @@ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\ConstraintValidator; -use Symfony\Component\Validator\Exception\UnexpectedTypeException; +use Symfony\Component\Validator\Constraints\EachValidator; /** * @author Bernhard Schussek * * @api + * + * @deprecated Deprecated in 2.5, to be removed in 3.0. Use + * {@link \Symfony\Component\Validator\Constraints\EachValidator} instead. */ -class AllValidator extends ConstraintValidator +class AllValidator extends EachValidator { - /** - * {@inheritDoc} - */ - public function validate($value, Constraint $constraint) - { - if (null === $value) { - return; - } - - if (!is_array($value) && !$value instanceof \Traversable) { - throw new UnexpectedTypeException($value, 'array or Traversable'); - } - - $group = $this->context->getGroup(); - foreach ($value as $key => $element) { - foreach ($constraint->constraints as $constr) { - $this->context->validateValue($element, $constr, '['.$key.']', $group); - } - } - } } diff --git a/src/Symfony/Component/Validator/Constraints/Each.php b/src/Symfony/Component/Validator/Constraints/Each.php new file mode 100644 index 000000000000..c47874f28de0 --- /dev/null +++ b/src/Symfony/Component/Validator/Constraints/Each.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Constraints; + +use Symfony\Component\Validator\Constraints\AbstractComposite; + +/** + * @Annotation + * + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + * + */ +class Each extends AbstractComposite +{ +} \ No newline at end of file diff --git a/src/Symfony/Component/Validator/Constraints/EachValidator.php b/src/Symfony/Component/Validator/Constraints/EachValidator.php new file mode 100644 index 000000000000..8ef1647050b1 --- /dev/null +++ b/src/Symfony/Component/Validator/Constraints/EachValidator.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Constraints; + +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; +use Symfony\Component\Validator\Constraints\AbstractCompositeValidator; + +/** + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + */ +class EachValidator extends AbstractCompositeValidator +{ + + /** + * {@inheritDoc} + */ + public function doValidate($value, Constraint $constraint) + { + $group = $this->context->getGroup(); + + foreach ($value as $key => $element) { + foreach ($constraint->constraints as $constr) { + $this->context->validateValue($element, $constr, '[' . $key . ']', $group); + } + } + } +} diff --git a/src/Symfony/Component/Validator/Constraints/None.php b/src/Symfony/Component/Validator/Constraints/None.php new file mode 100644 index 000000000000..3adeeb7c8b97 --- /dev/null +++ b/src/Symfony/Component/Validator/Constraints/None.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Constraints; + +use Symfony\Component\Validator\Constraints\AbstractComposite; +use Symfony\Component\Validator\Exception\MissingOptionsException; + + +/** + * @Annotation + * + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + */ +class None extends AbstractComposite +{ + + /** + * @var string + * + * Message for notice Violation + */ + public $violationMessage = 'None of this collection should pass validation.'; +} diff --git a/src/Symfony/Component/Validator/Constraints/NoneValidator.php b/src/Symfony/Component/Validator/Constraints/NoneValidator.php new file mode 100644 index 000000000000..2fd70bee02dd --- /dev/null +++ b/src/Symfony/Component/Validator/Constraints/NoneValidator.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Constraints; + +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; +use Symfony\Component\Validator\Constraints\AbstractCompositeValidator; +use Symfony\Component\Validator\Exception\ConstraintDefinitionException; + + +/** + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + */ +class NoneValidator extends AbstractCompositeValidator +{ + + /** + * {@inheritDoc} + */ + public function doValidate($value, Constraint $constraint) + { + $group = $this->context->getGroup(); + + $totalIterations = count($value) * count($constraint->constraints); + + foreach ($value as $key => $element) { + foreach ($constraint->constraints as $constr) { + $this->context->validateValue($element, $constr, '[' . $key . ']', $group); + } + } + + $constraintsSuccess = $totalIterations - (int) $this->context->getViolations()->count(); + + /** + * We clear all violations as just current Validator should add real Violations + */ + $this->context->clearViolations(); + + if ($constraintsSuccess > 0){ + $this->context->addViolation($constraint->violationMessage); + } + } +} diff --git a/src/Symfony/Component/Validator/Constraints/Some.php b/src/Symfony/Component/Validator/Constraints/Some.php new file mode 100644 index 000000000000..12953fc83d94 --- /dev/null +++ b/src/Symfony/Component/Validator/Constraints/Some.php @@ -0,0 +1,90 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Constraints; + +use Symfony\Component\Validator\Constraints\AbstractComposite; +use Symfony\Component\Validator\Exception\MissingOptionsException; + + +/** + * @Annotation + * + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + */ +class Some extends AbstractComposite +{ + + /** + * @var string + * + * Message for notice Min Violation + */ + public $minMessage = 'At least {{ limit }} element of this collection should pass validation.|At least {{ limit }} elements or more of this collection should pass validation.'; + + /** + * @var string + * + * Message for notice Max Violation + */ + public $maxMessage = '{{ limit }} or less element of this collection should pass validation.'; + + /** + * @var string + * + * Message for notice Exactly Violation + */ + public $exactlyMessage = 'Exactly {{ limit }} element of this collection should pass validation.|Exactly {{ limit }} elements of this collection should pass validation'; + + /** + * @var int + * + * Min number of Succeds expected + */ + public $min; + + /** + * @var int + * + * Max number of Succeds expected + */ + public $max; + + /** + * @var int + * + * Exactly number of Succeds expected + */ + public $exactly; + + /** + * {@inheritDoc} + */ + public function __construct($options = null) + { + parent::__construct($options); + + if ( (isset($this->min) || isset($this->max)) && isset($this->exactly)) { + throw new MissingOptionsException(sprintf('"min" or "max" and "exactly" must not be given at the same time: %s', __CLASS__), array('min', 'max', 'exactly')); + } + + if (!isset($this->min) && !isset($this->exactly)){ + $this->min = 1; + } + + if ( isset($this->max) && ($this->min > $this->max)) { + throw new MissingOptionsException(sprintf('"min" must not be given great than "max": %s', __CLASS__), array('min', 'max')); + } + } +} diff --git a/src/Symfony/Component/Validator/Constraints/SomeValidator.php b/src/Symfony/Component/Validator/Constraints/SomeValidator.php new file mode 100644 index 000000000000..560f51d992f0 --- /dev/null +++ b/src/Symfony/Component/Validator/Constraints/SomeValidator.php @@ -0,0 +1,74 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Constraints; + +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; +use Symfony\Component\Validator\Constraints\AbstractCompositeValidator; +use Symfony\Component\Validator\Exception\ConstraintDefinitionException; + + +/** + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + */ +class SomeValidator extends AbstractCompositeValidator +{ + + /** + * {@inheritDoc} + */ + public function doValidate($value, Constraint $constraint) + { + $group = $this->context->getGroup(); + + $totalIterations = count($value) * count($constraint->constraints); + + foreach ($value as $key => $element) { + foreach ($constraint->constraints as $constr) { + $this->context->validateValue($element, $constr, '[' . $key . ']', $group); + } + } + + $constraintsSuccess = $totalIterations - (int) $this->context->getViolations()->count(); + + /** + * We clear all violations as just current Validator should add real Violations + */ + $this->context->clearViolations(); + + if (isset($constraint->exactly) && $constraintsSuccess != $constraint->exactly){ + + $this->context->addViolation($constraint->exactlyMessage, array( + '{{ limit }}' => $constraint->exactly, + ), null, true); + + return; + } + + if (isset($constraint->min) && $constraintsSuccess < $constraint->min){ + $this->context->addViolation($constraint->minMessage, array( + '{{ limit }}' => $constraint->min, + )); + + return; + } + + if (isset($constraint->max) && $constraintsSuccess > $constraint->max){ + $this->context->addViolation($constraint->maxMessage, array( + '{{ limit }}' => $constraint->max, + ), null, true); + } + } +} diff --git a/src/Symfony/Component/Validator/Constraints/Unique.php b/src/Symfony/Component/Validator/Constraints/Unique.php new file mode 100644 index 000000000000..b06cf42f619d --- /dev/null +++ b/src/Symfony/Component/Validator/Constraints/Unique.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Constraints; + + +use Symfony\Component\Validator\Constraint; + +/** + * @Annotation + * + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + */ +class Unique extends Constraint +{ + + /** + * @var string + * + * Message for notice Exactly Violation + */ + public $uniqueMessage = 'This collection has repeated elements'; +} diff --git a/src/Symfony/Component/Validator/Constraints/UniqueValidator.php b/src/Symfony/Component/Validator/Constraints/UniqueValidator.php new file mode 100644 index 000000000000..3b7af6074b87 --- /dev/null +++ b/src/Symfony/Component/Validator/Constraints/UniqueValidator.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Constraints; + +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\Constraints\AbstractCompositeValidator; + +/** + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + */ +class UniqueValidator extends AbstractCompositeValidator +{ + + /** + * {@inheritDoc} + */ + public function doValidate($value, Constraint $constraint) + { + if ($this->findRepeated($value)){ + + $this->context->addViolation($constraint->uniqueMessage, $params=array()); + } + } + + /** + * Given a set of iterable elements, just checks if all elements are once + * + * @param Mixed $elements Elements to check + * + * @return boolean Elements in collection are once + */ + private function findRepeated($elements) + { + $arrayUnique = array(); + + foreach ($elements as $element) { + + $arrayUnique[serialize($element)] = $element; + } + + return (count($arrayUnique) < count($elements)); + } +} diff --git a/src/Symfony/Component/Validator/ExecutionContext.php b/src/Symfony/Component/Validator/ExecutionContext.php index 31a959187e35..9e9dc5c2bdc1 100644 --- a/src/Symfony/Component/Validator/ExecutionContext.php +++ b/src/Symfony/Component/Validator/ExecutionContext.php @@ -140,6 +140,18 @@ public function getViolations() return $this->globalContext->getViolations(); } + /** + * Clears violation stack + * + * @return ExecutionContext self Object + */ + public function clearViolations() + { + $this->globalContext->clearViolations(); + + return $this; + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AbstractCompositeTest.php b/src/Symfony/Component/Validator/Tests/Constraints/AbstractCompositeTest.php new file mode 100644 index 000000000000..ba018c7656e1 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/AbstractCompositeTest.php @@ -0,0 +1,207 @@ + + * + * 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; + +use Symfony\Component\Validator\Constraints\AbstractComposite; +use Symfony\Component\Validator\Constraint; + +/** + * @author Marc Morales Valldepérez + * @author Marc Morera Merino + */ +class AbstractCompositeTest extends \PHPUnit_Framework_TestCase +{ + + /** + * @var Constraint + * + * Constraint + */ + private $simpleConstraint; + + + /** + * Setup method + */ + public function setUp() + { + parent::setUp(); + + $this->simpleConstraint = $this + ->getMockBuilder('Symfony\Component\Validator\Constraint') + ->disableOriginalConstructor() + ->setMethods(null) + ->getMock(); + } + + + /** + * Collection groups: none + * Constraint groups: none + * + * Collection groups result: [Default] + * Constraint groups result: [Default] + */ + public function testEmptyGroups() + { + $composite = $this + ->getMockBuilder('Symfony\Component\Validator\Constraints\AbstractComposite') + ->setConstructorArgs(array( + 'constraints' => array( + $this->simpleConstraint + ), + )) + ->setMethods(null) + ->getMock(); + + $this->assertEquals(array_values($composite->groups), array( + $composite::DEFAULT_GROUP, + )); + + $constraint = $this->simpleConstraint; + $this->assertEquals(array_values($this->simpleConstraint->groups), array( + $constraint::DEFAULT_GROUP, + )); + } + + + /** + * Collection groups: [Default, Group1] + * Constraint groups: none + * + * Collection groups result: [Default, Group1] + * Constraint groups result: [Default, Group1] + */ + public function testCollectionGroups() + { + $composite = $this + ->getMockBuilder('Symfony\Component\Validator\Constraints\AbstractComposite') + ->setConstructorArgs(array( + array( + 'constraints' => array( + $this->simpleConstraint + ), + 'groups' => array( + 'Default', + 'Group1', + ), + ) + )) + ->setMethods(null) + ->getMock(); + + $this->assertEquals(array_values($composite->groups), array( + $composite::DEFAULT_GROUP, + 'Group1' + )); + + $constraint = $this->simpleConstraint; + $this->assertEquals(array_values($this->simpleConstraint->groups), array( + $constraint::DEFAULT_GROUP, + 'Group1' + )); + } + + + /** + * Collection groups: none + * Constraint groups: [Default, Group1] + * + * Collection groups result: [Default, Group1] + * Constraint groups result: [Default, Group1] + */ + public function testConstraintsGroups() + { + $this->simpleConstraint = $this + ->getMockBuilder('Symfony\Component\Validator\Constraint') + ->setConstructorArgs(array( + array( + 'groups' => array( + 'Default', + 'Group1', + ), + ) + )) + ->setMethods(null) + ->getMock(); + + $composite = $this + ->getMockBuilder('Symfony\Component\Validator\Constraints\AbstractComposite') + ->setConstructorArgs(array( + array( + 'constraints' => array( + $this->simpleConstraint + ), + ) + )) + ->setMethods(null) + ->getMock(); + + $this->assertEquals(array_values($composite->groups), array( + $composite::DEFAULT_GROUP, + 'Group1' + )); + + $constraint = $this->simpleConstraint; + $this->assertEquals(array_values($this->simpleConstraint->groups), array( + $constraint::DEFAULT_GROUP, + 'Group1' + )); + } + + + /** + * Collection groups: none + * Constraint groups: [Default, Group1] + * + * Collection groups result: [Default, Group1] + * Constraint groups result: [Default, Group1] + */ + public function testBothGroups() + { + $this->simpleConstraint = $this + ->getMockBuilder('Symfony\Component\Validator\Constraint') + ->setConstructorArgs(array( + array( + 'groups' => array( + 'Default', + 'Group1', + ), + ) + )) + ->setMethods(null) + ->getMock(); + + $composite = $this + ->getMockBuilder('Symfony\Component\Validator\Constraints\AbstractComposite') + ->setConstructorArgs(array( + array( + 'constraints' => array( + $this->simpleConstraint + ), + ) + )) + ->setMethods(null) + ->getMock(); + + $this->assertEquals(array_values($composite->groups), array( + $composite::DEFAULT_GROUP, + 'Group1' + )); + + $constraint = $this->simpleConstraint; + $this->assertEquals(array_values($this->simpleConstraint->groups), array( + $constraint::DEFAULT_GROUP, + 'Group1' + )); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EachTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EachTest.php new file mode 100644 index 000000000000..0e7fe1bb7e24 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/EachTest.php @@ -0,0 +1,44 @@ + + * + * 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; + +use Symfony\Component\Validator\Constraints\Each; +use Symfony\Component\Validator\Constraints\Valid; + +/** + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + */ +class EachTest extends \PHPUnit_Framework_TestCase +{ + /** + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException + */ + public function testRejectNonConstraints() + { + new Each(array( + 'foo', + )); + } + + /** + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException + */ + public function testRejectValidConstraint() + { + new Each(array( + new Valid(), + )); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EachValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EachValidatorTest.php new file mode 100644 index 000000000000..3836baf37cba --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/EachValidatorTest.php @@ -0,0 +1,118 @@ + + * + * 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; + +use Symfony\Component\Validator\ExecutionContext; +use Symfony\Component\Validator\Constraints\Range; +use Symfony\Component\Validator\Constraints\NotNull; +use Symfony\Component\Validator\Constraints\Each; +use Symfony\Component\Validator\Constraints\EachValidator; + +/** + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + */ +class EachValidatorTest extends \PHPUnit_Framework_TestCase +{ + protected $context; + protected $validator; + + protected function setUp() + { + $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); + $this->validator = new EachValidator(); + $this->validator->initialize($this->context); + + $this->context->expects($this->any()) + ->method('getGroup') + ->will($this->returnValue('MyGroup')); + } + + protected function tearDown() + { + $this->validator = null; + $this->context = null; + } + + public function testNullIsValid() + { + $this->context->expects($this->never()) + ->method('addViolation'); + + $this->validator->validate(null, new Each(new Range(array('min' => 4)))); + } + + /** + * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException + */ + public function testThrowsExceptionIfNotTraversable() + { + $this->validator->validate('foo.barbar', new Each(new Range(array('min' => 4)))); + } + + /** + * @dataProvider getValidArguments + */ + public function testWalkSingleConstraint($array) + { + $constraint = new Range(array('min' => 4)); + + $i = 1; + + foreach ($array as $key => $value) { + $this->context->expects($this->at($i++)) + ->method('validateValue') + ->with($value, $constraint, '['.$key.']', 'MyGroup'); + } + + $this->context->expects($this->never()) + ->method('addViolation'); + + $this->validator->validate($array, new Each($constraint)); + } + + /** + * @dataProvider getValidArguments + */ + public function testWalkMultipleConstraints($array) + { + $constraint1 = new Range(array('min' => 4)); + $constraint2 = new NotNull(); + + $constraints = array($constraint1, $constraint2); + $i = 1; + + foreach ($array as $key => $value) { + $this->context->expects($this->at($i++)) + ->method('validateValue') + ->with($value, $constraint1, '['.$key.']', 'MyGroup'); + $this->context->expects($this->at($i++)) + ->method('validateValue') + ->with($value, $constraint2, '['.$key.']', 'MyGroup'); + } + + $this->context->expects($this->never()) + ->method('addViolation'); + + $this->validator->validate($array, new Each($constraints)); + } + + public function getValidArguments() + { + return array( + array(array(5, 6, 7)), + array(new \ArrayObject(array(5, 6, 7))), + ); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NoneTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NoneTest.php new file mode 100644 index 000000000000..36c1632579aa --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/NoneTest.php @@ -0,0 +1,44 @@ + + * + * 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; + +use Symfony\Component\Validator\Constraints\None; +use Symfony\Component\Validator\Constraints\Valid; + +/** + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + */ +class NoneTest extends \PHPUnit_Framework_TestCase +{ + /** + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException + */ + public function testRejectNonConstraints() + { + new None(array( + 'foo', + )); + } + + /** + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException + */ + public function testRejectValidConstraint() + { + new None(array( + new Valid(), + )); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NoneValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NoneValidatorTest.php new file mode 100644 index 000000000000..0e4a6d9b4403 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/NoneValidatorTest.php @@ -0,0 +1,279 @@ + + * + * 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; + +use Symfony\Component\Validator\ExecutionContext; +use Symfony\Component\Validator\Constraints\Range; +use Symfony\Component\Validator\Constraints\NotNull; +use Symfony\Component\Validator\Constraints\None; +use Symfony\Component\Validator\Constraints\NoneValidator; +use Symfony\Component\Validator\Tests\Fixtures\FakeMetadataFactory; +use Symfony\Component\Validator\ValidationVisitor; +use Symfony\Component\Validator\DefaultTranslator; +use Symfony\Component\Validator\ConstraintValidatorFactory; +use Symfony\Component\Validator\Mapping\ClassMetadata; +use Symfony\Component\Validator\Tests\Fixtures\EntityCollection; + +/** + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + */ +class NoneValidatorTest extends \PHPUnit_Framework_TestCase +{ + + /** + * @var ExecutionContext + * + * Context mockup + */ + protected $context; + + /** + * @var SomeValidator + * + * Validator instance + */ + protected $validator; + + /** + * Set up method + */ + protected function setUp() + { + + $this->context = $this + ->getMockBuilder('Symfony\Component\Validator\ExecutionContext') + ->disableOriginalConstructor() + ->setMethods(array()) + ->getMock(); + + $this->validator = new NoneValidator(); + $this->validator->initialize($this->context); + } + + /** + * Tear down method + */ + protected function tearDown() + { + $this->validator = null; + $this->context = null; + } + + /** + * Tests that if null, just valid + */ + public function testNullIsValid() + { + $this->context + ->expects($this->never()) + ->method('addViolation'); + + $this->validator->validate( + null, + new None( + array( + 'constraints' => array( + new Range(array('min' => 10)) + ), + ) + ) + ); + } + + /** + * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException + */ + public function testThrowsExceptionIfNotTraversable() + { + $this->validator->validate('foo.barbar', new None(new Range(array('min' => 4)))); + } + + /** + * Validates success + * + * @dataProvider getValidArguments + */ + public function testSuccessValidate($array) + { + $constraintViolationList = $this + ->getMockBuilder('Symfony\Component\Validator\ConstraintViolationList') + ->disableOriginalConstructor() + ->setMethods(array('count')) + ->getMock(); + + $constraintViolationList + ->expects($this->once()) + ->method('count') + ->will($this->returnValue(6)); + + $this->context + ->expects($this->never()) + ->method('addViolation'); + + $this->context + ->expects($this->once()) + ->method('getViolations') + ->will($this->returnValue($constraintViolationList)); + + $constraint1 = new Range(array('min' => 8)); + $constraint2 = new Range(array('min' => 9)); + + $this->setValidateValueAssertions($array, $constraint1, $constraint2); + + $this->validator->validate( + $array, + new None( + array( + 'constraints' => array( + $constraint1, + $constraint2, + ), + ) + ) + ); + } + + /** + * Validates not success + * + * @dataProvider getValidArguments + */ + public function testNotSuccessValidate($array) + { + $constraintViolationList = $this + ->getMockBuilder('Symfony\Component\Validator\ConstraintViolationList') + ->disableOriginalConstructor() + ->setMethods(array('count')) + ->getMock(); + + $constraintViolationList + ->expects($this->once()) + ->method('count') + ->will($this->returnValue(2)); + + $this->context + ->expects($this->once()) + ->method('addViolation'); + + $this->context + ->expects($this->once()) + ->method('getViolations') + ->will($this->returnValue($constraintViolationList)); + + $constraint1 = new Range(array('min' => 2)); + $constraint2 = new Range(array('min' => 7)); + + $this->setValidateValueAssertions($array, $constraint1, $constraint2); + + $this->validator->validate( + $array, + new None( + array( + 'constraints' => array( + $constraint1, + $constraint2, + ), + ) + ) + ); + } + + + + /** + * Adds validateValue assertions + */ + protected function setValidateValueAssertions($array, $constraint1, $constraint2) + { + $iteration = 1; + + foreach ($array as $key => $value) { + + $this + ->context + ->expects($this->at($iteration++)) + ->method('validateValue') + ->with($value, $constraint1, '['.$key.']'); + + $this + ->context + ->expects($this->at($iteration++)) + ->method('validateValue') + ->with($value, $constraint2, '['.$key.']'); + } + } + + /** + * Functional test, validating None constraint + * + * Using exactly + */ + public function testFunctionalSuccessExactly() + { + $metadataFactory = new FakeMetadataFactory(); + $visitor = new ValidationVisitor('Root', $metadataFactory, new ConstraintValidatorFactory(), new DefaultTranslator()); + $metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\EntityCollection'); + $metadata->addPropertyConstraint('collection', new None( + array( + 'constraints' => array( + new Range(array('min' => 4)), + new Range(array('min' => 5)), + new Range(array('min' => 6)), + ), + ) + ) + ); + $metadataFactory->addMetadata($metadata); + $visitor->validate(new EntityCollection(), 'Default', ''); + $this->assertCount(0, $visitor->getViolations()); + } + + /** + * Functional test, not validating None constraint + * + * Using exactly + */ + public function testFunctionalNotSuccessExactly() + { + $metadataFactory = new FakeMetadataFactory(); + $visitor = new ValidationVisitor('Root', $metadataFactory, new ConstraintValidatorFactory(), new DefaultTranslator()); + $metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\EntityCollection'); + $metadata->addPropertyConstraint('collection', new None( + array( + 'constraints' => array( + new Range(array('min' => 1)), + new Range(array('min' => 2)), + new Range(array('min' => 3)), + ), + ) + ) + ); + $metadataFactory->addMetadata($metadata); + $visitor->validate(new EntityCollection(), 'Default', ''); + $this->assertCount(1, $visitor->getViolations()); + } + + + /** + * Data provider + */ + public function getValidArguments() + { + return array( + array(array(5, 6, 7)), + array(new \ArrayObject(array(5, 6, 7))), + ); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/SomeTest.php b/src/Symfony/Component/Validator/Tests/Constraints/SomeTest.php new file mode 100644 index 000000000000..a2a182f691ce --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/SomeTest.php @@ -0,0 +1,44 @@ + + * + * 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; + +use Symfony\Component\Validator\Constraints\Some; +use Symfony\Component\Validator\Constraints\Valid; + +/** + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + */ +class SomeTest extends \PHPUnit_Framework_TestCase +{ + /** + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException + */ + public function testRejectNonConstraints() + { + new Some(array( + 'foo', + )); + } + + /** + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException + */ + public function testRejectValidConstraint() + { + new Some(array( + new Valid(), + )); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/SomeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/SomeValidatorTest.php new file mode 100644 index 000000000000..f09aa1d9ad54 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/SomeValidatorTest.php @@ -0,0 +1,679 @@ + + * + * 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; + +use Symfony\Component\Validator\ExecutionContext; +use Symfony\Component\Validator\Constraints\Range; +use Symfony\Component\Validator\Constraints\NotNull; +use Symfony\Component\Validator\Constraints\Some; +use Symfony\Component\Validator\Constraints\SomeValidator; +use Symfony\Component\Validator\Tests\Fixtures\FakeMetadataFactory; +use Symfony\Component\Validator\ValidationVisitor; +use Symfony\Component\Validator\DefaultTranslator; +use Symfony\Component\Validator\ConstraintValidatorFactory; +use Symfony\Component\Validator\Mapping\ClassMetadata; +use Symfony\Component\Validator\Tests\Fixtures\EntityCollection; + +/** + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + */ +class SomeValidatorTest extends \PHPUnit_Framework_TestCase +{ + + /** + * @var ExecutionContext + * + * Context mockup + */ + protected $context; + + /** + * @var SomeValidator + * + * Validator instance + */ + protected $validator; + + /** + * Set up method + */ + protected function setUp() + { + + $this->context = $this + ->getMockBuilder('Symfony\Component\Validator\ExecutionContext') + ->disableOriginalConstructor() + ->setMethods(array()) + ->getMock(); + + $this->validator = new SomeValidator(); + $this->validator->initialize($this->context); + } + + /** + * Tear down method + */ + protected function tearDown() + { + $this->validator = null; + $this->context = null; + } + + /** + * Tests that if null, just valid + */ + public function testNullIsValid() + { + $this->context + ->expects($this->never()) + ->method('addViolation'); + + $this->validator->validate( + null, + new Some( + array( + 'constraints' => array( + new Range(array('min' => 4)) + ), + 'min' => 1 + ) + ) + ); + } + + /** + * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException + */ + public function testThrowsExceptionIfNotTraversable() + { + $this->validator->validate('foo.barbar', new Some(new Range(array('min' => 4)))); + } + + /** + * @expectedException \Symfony\Component\Validator\Exception\MissingOptionsException + */ + public function testThrowsExceptionMinAndExactly() + { + $this->validator->validate( + null, + new Some( + array( + 'constraints' => array( + new Range(array('min' => 4)) + ), + 'min' => 1, + 'exactly' => 2 + ) + ) + ); + } + + /** + * @expectedException \Symfony\Component\Validator\Exception\MissingOptionsException + */ + public function testThrowsExceptionMaxAndExactly() + { + $this->validator->validate( + null, + new Some( + array( + 'constraints' => array( + new Range(array('min' => 4)) + ), + 'max' => 1, + 'exactly' => 2 + ) + ) + ); + } + + /** + * @expectedException \Symfony\Component\Validator\Exception\MissingOptionsException + */ + public function testThrowsExceptionMinGreatThanMax() + { + $this->validator->validate( + null, + new Some( + array( + 'constraints' => array( + new Range(array('min' => 4)) + ), + 'min' => 3, + 'max' => 1 + ) + ) + ); + } + + /** + * Testing when min and max are defined + */ + public function testMinAndMax() + { + $this->validator->validate( + null, + new Some( + array( + 'constraints' => array( + new Range(array('min' => 4)) + ), + 'min'=>1, + 'max'=>10, + ) + ) + ); + } + + /** + * Testing when min, max and exactly are defined + * + * @expectedException \Symfony\Component\Validator\Exception\MissingOptionsException + */ + public function testMinAndMaxAndExactly() + { + $this->validator->validate( + null, + new Some( + array( + 'constraints' => array( + new Range(array('min' => 4)) + ), + 'min'=>1, + 'max'=>10, + 'exactly'=>10, + ) + ) + ); + } + + /** + * Testing when just max is defined + */ + public function testMax() + { + $this->validator->validate( + null, + new Some( + array( + 'constraints' => array( + new Range(array('min' => 4)) + ), + 'max'=>10, + ) + ) + ); + } + + /** + * Validates success min + * + * @dataProvider getValidArguments + */ + public function testSuccessMinValidate($array) + { + $constraintViolationList = $this + ->getMockBuilder('Symfony\Component\Validator\ConstraintViolationList') + ->disableOriginalConstructor() + ->setMethods(array('count')) + ->getMock(); + + $constraintViolationList + ->expects($this->once()) + ->method('count') + ->will($this->returnValue(2)); + + $this->context + ->expects($this->once()) + ->method('getViolations') + ->will($this->returnValue($constraintViolationList)); + + $this->context + ->expects($this->never()) + ->method('addViolation'); + + $constraint1 = new Range(array('min' => 2)); + $constraint2 = new Range(array('min' => 7)); + + $this->setValidateValueAssertions($array, $constraint1, $constraint2); + + $this->validator->validate( + $array, + new Some( + array( + 'constraints' => array( + $constraint1, + $constraint2, + ), + 'min' => 3 + ) + )); + } + + /** + * Not validates success min + * + * @dataProvider getValidArguments + */ + public function testNotSuccessMinValidate($array) + { + $constraintViolationList = $this + ->getMockBuilder('Symfony\Component\Validator\ConstraintViolationList') + ->disableOriginalConstructor() + ->setMethods(array('count')) + ->getMock(); + + $constraintViolationList + ->expects($this->once()) + ->method('count') + ->will($this->returnValue(2)); + + $this->context + ->expects($this->once()) + ->method('addViolation'); + + $this->context + ->expects($this->once()) + ->method('getViolations') + ->will($this->returnValue($constraintViolationList)); + + $constraint1 = new Range(array('min' => 2)); + $constraint2 = new Range(array('min' => 7)); + + $this->setValidateValueAssertions($array, $constraint1, $constraint2); + + $this->validator->validate( + $array, + new Some( + array( + 'constraints' => array( + $constraint1, + $constraint2, + ), + 'min' => 5 + ) + ) + ); + } + + /** + * Validates success min + * + * @dataProvider getValidArguments + */ + public function testSuccessMinMaxValidate($array) + { + $constraintViolationList = $this + ->getMockBuilder('Symfony\Component\Validator\ConstraintViolationList') + ->disableOriginalConstructor() + ->setMethods(array('count')) + ->getMock(); + + $constraintViolationList + ->expects($this->once()) + ->method('count') + ->will($this->returnValue(2)); + + $this->context + ->expects($this->never()) + ->method('addViolation'); + + $this->context + ->expects($this->once()) + ->method('getViolations') + ->will($this->returnValue($constraintViolationList)); + + $constraint1 = new Range(array('min' => 2)); + $constraint2 = new Range(array('min' => 7)); + + $this->setValidateValueAssertions($array, $constraint1, $constraint2); + + $this->validator->validate( + $array, + new Some( + array( + 'constraints' => array( + $constraint1, + $constraint2, + ), + 'min' => 2, + 'max' => 4, + ) + ) + ); + } + + /** + * Validates not success min + * + * @dataProvider getValidArguments + */ + public function testNotSuccessMinMaxValidate($array) + { + $constraintViolationList = $this + ->getMockBuilder('Symfony\Component\Validator\ConstraintViolationList') + ->disableOriginalConstructor() + ->setMethods(array('count')) + ->getMock(); + + $constraintViolationList + ->expects($this->once()) + ->method('count') + ->will($this->returnValue(2)); + + $this->context + ->expects($this->once()) + ->method('addViolation'); + + $this->context + ->expects($this->once()) + ->method('getViolations') + ->will($this->returnValue($constraintViolationList)); + + $constraint1 = new Range(array('min' => 2)); + $constraint2 = new Range(array('min' => 7)); + + $this->setValidateValueAssertions($array, $constraint1, $constraint2); + + $this->validator->validate( + $array, + new Some( + array( + 'constraints' => array( + $constraint1, + $constraint2, + ), + 'min' => 1, + 'max' => 3, + ) + ) + ); + } + + /** + * Validates success max + * + * @dataProvider getValidArguments + */ + public function testSuccessMaxValidate($array) + { + $constraintViolationList = $this + ->getMockBuilder('Symfony\Component\Validator\ConstraintViolationList') + ->disableOriginalConstructor() + ->setMethods(array('count')) + ->getMock(); + + $constraintViolationList + ->expects($this->once()) + ->method('count') + ->will($this->returnValue(2)); + + $this->context + ->expects($this->never()) + ->method('addViolation'); + + $this->context + ->expects($this->once()) + ->method('getViolations') + ->will($this->returnValue($constraintViolationList)); + + $constraint1 = new Range(array('min' => 2)); + $constraint2 = new Range(array('min' => 7)); + + $this->setValidateValueAssertions($array, $constraint1, $constraint2); + + $this->validator->validate( + $array, + new Some( + array( + 'constraints' => array( + $constraint1, + $constraint2, + ), + 'max' => 5, + ) + ) + ); + } + + /** + * Validates not success max + * + * @dataProvider getValidArguments + */ + public function testNotSuccessMaxValidate($array) + { + $constraintViolationList = $this + ->getMockBuilder('Symfony\Component\Validator\ConstraintViolationList') + ->disableOriginalConstructor() + ->setMethods(array('count')) + ->getMock(); + + $constraintViolationList + ->expects($this->once()) + ->method('count') + ->will($this->returnValue(2)); + + $this->context + ->expects($this->once()) + ->method('addViolation'); + + $this->context + ->expects($this->once()) + ->method('getViolations') + ->will($this->returnValue($constraintViolationList)); + + $constraint1 = new Range(array('min' => 2)); + $constraint2 = new Range(array('min' => 7)); + + $this->setValidateValueAssertions($array, $constraint1, $constraint2); + + $this->validator->validate( + $array, + new Some( + array( + 'constraints' => array( + $constraint1, + $constraint2, + ), + 'max' => 2, + ) + ) + ); + } + + /** + * Validates success exactly + * + * @dataProvider getValidArguments + */ + public function testSuccessExactlyValidate($array) + { + $constraintViolationList = $this + ->getMockBuilder('Symfony\Component\Validator\ConstraintViolationList') + ->disableOriginalConstructor() + ->setMethods(array('count')) + ->getMock(); + + $constraintViolationList + ->expects($this->once()) + ->method('count') + ->will($this->returnValue(2)); + + $this->context + ->expects($this->never()) + ->method('addViolation'); + + $this->context + ->expects($this->once()) + ->method('getViolations') + ->will($this->returnValue($constraintViolationList)); + + $constraint1 = new Range(array('min' => 2)); + $constraint2 = new Range(array('min' => 7)); + + $this->setValidateValueAssertions($array, $constraint1, $constraint2); + + $this->validator->validate( + $array, + new Some( + array( + 'constraints' => array( + $constraint1, + $constraint2, + ), + 'exactly' => 4, + ) + ) + ); + } + + /** + * Validates not success exactly + * + * @dataProvider getValidArguments + */ + public function testNotSuccessExactlyValidate($array) + { + $constraintViolationList = $this + ->getMockBuilder('Symfony\Component\Validator\ConstraintViolationList') + ->disableOriginalConstructor() + ->setMethods(array('count')) + ->getMock(); + + $constraintViolationList + ->expects($this->once()) + ->method('count') + ->will($this->returnValue(2)); + + $this->context + ->expects($this->once()) + ->method('addViolation'); + + $this->context + ->expects($this->once()) + ->method('getViolations') + ->will($this->returnValue($constraintViolationList)); + + $constraint1 = new Range(array('min' => 2)); + $constraint2 = new Range(array('min' => 7)); + + $this->setValidateValueAssertions($array, $constraint1, $constraint2); + + $this->validator->validate( + $array, + new Some( + array( + 'constraints' => array( + $constraint1, + $constraint2, + ), + 'exactly' => 3, + ) + ) + ); + } + + /** + * Functional test, validating Some constraint + * + * Using exactly + */ + public function testFunctionalSuccessExactly() + { + $metadataFactory = new FakeMetadataFactory(); + $visitor = new ValidationVisitor('Root', $metadataFactory, new ConstraintValidatorFactory(), new DefaultTranslator()); + $metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\EntityCollection'); + $metadata->addPropertyConstraint('collection', new Some( + array( + 'constraints' => array( + new Range(array('min' => 2)), + new Range(array('min' => 3)), + new Range(array('min' => 4)), + new Range(array('min' => 5)) + ), + 'exactly' => 3, + ) + ) + ); + $metadataFactory->addMetadata($metadata); + + $visitor->validate(new EntityCollection(), 'Default', ''); + $this->assertCount(0, $visitor->getViolations()); + } + + /** + * Functional test, not validating Some constraint + * + * Using exactly + */ + public function testFunctionalNotSuccessExactly() + { + $metadataFactory = new FakeMetadataFactory(); + $visitor = new ValidationVisitor('Root', $metadataFactory, new ConstraintValidatorFactory(), new DefaultTranslator()); + $metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\EntityCollection'); + $metadata->addPropertyConstraint('collection', new Some( + array( + 'constraints' => array( + new Range(array('min' => 2)), + new Range(array('min' => 3)), + new Range(array('min' => 4)), + new Range(array('min' => 5)) + ), + 'exactly' => 1, + ) + ) + ); + $metadataFactory->addMetadata($metadata); + + $visitor->validate(new EntityCollection(), 'Default', ''); + $this->assertCount(1, $visitor->getViolations()); + } + + /** + * Adds validateValue assertions + */ + protected function setValidateValueAssertions($array, $constraint1, $constraint2) + { + $iteration = 1; + + foreach ($array as $key => $value) { + + $this + ->context + ->expects($this->at($iteration++)) + ->method('validateValue') + ->with($value, $constraint1, '['.$key.']'); + + $this + ->context + ->expects($this->at($iteration++)) + ->method('validateValue') + ->with($value, $constraint2, '['.$key.']'); + } + } + + + /** + * Data provider + */ + public function getValidArguments() + { + return array( + array(array(5, 6, 7)), + array(new \ArrayObject(array(5, 6, 7))), + ); + } +} \ No newline at end of file diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php new file mode 100644 index 000000000000..bf1bcb8d1a60 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php @@ -0,0 +1,30 @@ + + * + * 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; + +use Symfony\Component\Validator\Constraints\Unique; +use Symfony\Component\Validator\Constraints\Valid; + +/** + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + */ +class UniqueTest extends \PHPUnit_Framework_TestCase +{ + + public function testSuccess() + { + new Unique(); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php new file mode 100644 index 000000000000..a054e1283517 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php @@ -0,0 +1,159 @@ + + * + * 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; + +use Symfony\Component\Validator\ExecutionContext; +use Symfony\Component\Validator\Constraints\Range; +use Symfony\Component\Validator\Constraints\NotNull; +use Symfony\Component\Validator\Constraints\Unique; +use Symfony\Component\Validator\Constraints\UniqueValidator; +use Symfony\Component\Validator\Tests\Fixtures\FakeMetadataFactory; +use Symfony\Component\Validator\ValidationVisitor; +use Symfony\Component\Validator\DefaultTranslator; +use Symfony\Component\Validator\ConstraintValidatorFactory; +use Symfony\Component\Validator\Mapping\ClassMetadata; +use Symfony\Component\Validator\Tests\Fixtures\EntityCollection; + +/** + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + * + * @api + */ +class UniqueValidatorTest extends \PHPUnit_Framework_TestCase +{ + + /** + * @var ExecutionContext + * + * Context mockup + */ + protected $context; + + /** + * @var SomeValidator + * + * Validator instance + */ + protected $validator; + + /** + * Set up method + */ + protected function setUp() + { + $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); + $this->validator = new UniqueValidator(); + $this->validator->initialize($this->context); + } + + /** + * Tear down method + */ + protected function tearDown() + { + $this->validator = null; + $this->context = null; + } + + /** + * Tests that if null, just valid + */ + public function testNullIsValid() + { + $this + ->context + ->expects($this->never()) + ->method('addViolation'); + + $this->validator->validate( + null, + new Unique() + ); + } + + /** + * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException + */ + public function testThrowsExceptionIfNotTraversable() + { + $this->validator->validate('foo.barbar', new Unique()); + } + + /** + * Test not validate + */ + + public function testUniqueNotSuccess() + { + $this + ->context + ->expects($this->once()) + ->method('addViolation'); + + $this->validator->validate( + array( + array(1, 1, 1), + array(1, 1, 1) + ), + new Unique() + ); + + } + + /** + * Test validate + */ + public function testUniqueSuccess() + { + $this + ->context + ->expects($this->never()) + ->method('addViolation'); + + $this->validator->validate( + array( + array(1, 1, 1), + array(2, 2, 2) + ), + new Unique() + ); + } + + /** + * Functional test, validating satisfactorily Unique constraint + */ + public function testFunctionalSuccessExactly() + { + $metadataFactory = new FakeMetadataFactory(); + $visitor = new ValidationVisitor('Root', $metadataFactory, new ConstraintValidatorFactory(), new DefaultTranslator()); + $metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\EntityCollection'); + $metadata->addPropertyConstraint('collection', new Unique()); + $metadataFactory->addMetadata($metadata); + $visitor->validate(new EntityCollection(), 'Default', ''); + $this->assertCount(0, $visitor->getViolations()); + } + + /** + * Functional test, validating unsatisfactorily Unique constraint + */ + public function testFunctionalNotSuccessExactly() + { + $metadataFactory = new FakeMetadataFactory(); + $visitor = new ValidationVisitor('Root', $metadataFactory, new ConstraintValidatorFactory(), new DefaultTranslator()); + $metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\EntityCollection'); + $metadata->addPropertyConstraint('collectionNotUnique', new Unique()); + $metadataFactory->addMetadata($metadata); + $visitor->validate(new EntityCollection(), 'Default', ''); + $this->assertCount(1, $visitor->getViolations()); + } +} \ No newline at end of file diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/EntityCollection.php b/src/Symfony/Component/Validator/Tests/Fixtures/EntityCollection.php new file mode 100644 index 000000000000..73ddb1f69d24 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Fixtures/EntityCollection.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Validator\Tests\Fixtures; + +use Symfony\Component\Validator\Constraints as Assert; + +/** + * @author Marc Morera Merino + * @author Marc Morales Valldepérez + */ +class EntityCollection +{ + /** + * + */ + protected $collection = array(1,2,3); + + /** + * + */ + protected $collectionNotUnique = array(1,2,3,1,2); +} \ No newline at end of file diff --git a/src/Symfony/Component/Validator/ValidationVisitor.php b/src/Symfony/Component/Validator/ValidationVisitor.php index ddff8adc6038..23bd633f830b 100644 --- a/src/Symfony/Component/Validator/ValidationVisitor.php +++ b/src/Symfony/Component/Validator/ValidationVisitor.php @@ -163,6 +163,18 @@ public function validate($value, $group, $propertyPath, $traverse = false, $deep } } + /** + * Clears violation stack + * + * @return ValidationVisitor self Object + */ + public function clearViolations() + { + $this->violations = new ConstraintViolationList(); + + return $this; + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Validator/composer.json b/src/Symfony/Component/Validator/composer.json index af14eabdb63a..09a592326d71 100644 --- a/src/Symfony/Component/Validator/composer.json +++ b/src/Symfony/Component/Validator/composer.json @@ -26,7 +26,8 @@ "symfony/yaml": "~2.0", "symfony/config": "~2.2", "doctrine/annotations": "~1.0", - "doctrine/cache": "~1.0" + "doctrine/cache": "~1.0", + "symfony/expression-language": "2.5.*@dev" }, "suggest": { "doctrine/annotations": "For using the annotation mapping. You will also need doctrine/cache.", From 5fff51ad83930642a1a789a087566973a9a138cd Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 9 Jan 2014 21:59:17 +0100 Subject: [PATCH 2/3] [Validator] Fixed phpcs issues --- .../Validator/Constraints/AbstractComposite.php | 4 ---- .../Constraints/AbstractCompositeValidator.php | 1 - src/Symfony/Component/Validator/Constraints/All.php | 2 -- .../Component/Validator/Constraints/AllValidator.php | 3 --- src/Symfony/Component/Validator/Constraints/Each.php | 4 +--- .../Component/Validator/Constraints/EachValidator.php | 2 -- src/Symfony/Component/Validator/Constraints/None.php | 4 ---- .../Component/Validator/Constraints/NoneValidator.php | 6 +----- src/Symfony/Component/Validator/Constraints/Some.php | 4 +--- .../Component/Validator/Constraints/SomeValidator.php | 10 +++------- src/Symfony/Component/Validator/Constraints/Unique.php | 1 - .../Validator/Constraints/UniqueValidator.php | 3 +-- .../Tests/Constraints/AbstractCompositeTest.php | 5 ----- .../Validator/Tests/Constraints/NoneValidatorTest.php | 4 ---- .../Validator/Tests/Constraints/SomeValidatorTest.php | 4 +--- .../Validator/Tests/Constraints/UniqueTest.php | 1 - .../Tests/Constraints/UniqueValidatorTest.php | 4 +--- .../Validator/Tests/Fixtures/EntityCollection.php | 2 +- 18 files changed, 10 insertions(+), 54 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/AbstractComposite.php b/src/Symfony/Component/Validator/Constraints/AbstractComposite.php index 8f6591b02e99..eef95c41d926 100644 --- a/src/Symfony/Component/Validator/Constraints/AbstractComposite.php +++ b/src/Symfony/Component/Validator/Constraints/AbstractComposite.php @@ -30,7 +30,6 @@ abstract class AbstractComposite extends Constraint */ public $constraints = array(); - /** * {@inheritDoc} */ @@ -95,7 +94,6 @@ public function __construct($options = null) } } - /** * Adds the given group if this constraint is in the Default group * @@ -114,7 +112,6 @@ public function addImplicitGroupName($group) } } - /** * {@inheritDoc} */ @@ -123,7 +120,6 @@ public function getDefaultOption() return 'constraints'; } - /** * {@inheritDoc} */ diff --git a/src/Symfony/Component/Validator/Constraints/AbstractCompositeValidator.php b/src/Symfony/Component/Validator/Constraints/AbstractCompositeValidator.php index d425191f3b57..68260858087f 100644 --- a/src/Symfony/Component/Validator/Constraints/AbstractCompositeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/AbstractCompositeValidator.php @@ -28,7 +28,6 @@ abstract class AbstractCompositeValidator extends ConstraintValidator */ abstract public function doValidate($value, Constraint $constraint); - /** * {@inheritDoc} */ diff --git a/src/Symfony/Component/Validator/Constraints/All.php b/src/Symfony/Component/Validator/Constraints/All.php index 42a7344be0d2..1ade87143e7b 100644 --- a/src/Symfony/Component/Validator/Constraints/All.php +++ b/src/Symfony/Component/Validator/Constraints/All.php @@ -11,8 +11,6 @@ namespace Symfony\Component\Validator\Constraints; -use Symfony\Component\Validator\Constraints\Each; - /** * @Annotation * diff --git a/src/Symfony/Component/Validator/Constraints/AllValidator.php b/src/Symfony/Component/Validator/Constraints/AllValidator.php index b5dfc81a5913..f5596ac7a73e 100644 --- a/src/Symfony/Component/Validator/Constraints/AllValidator.php +++ b/src/Symfony/Component/Validator/Constraints/AllValidator.php @@ -11,9 +11,6 @@ namespace Symfony\Component\Validator\Constraints; -use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\Constraints\EachValidator; - /** * @author Bernhard Schussek * diff --git a/src/Symfony/Component/Validator/Constraints/Each.php b/src/Symfony/Component/Validator/Constraints/Each.php index c47874f28de0..ddabfea22f06 100644 --- a/src/Symfony/Component/Validator/Constraints/Each.php +++ b/src/Symfony/Component/Validator/Constraints/Each.php @@ -11,8 +11,6 @@ namespace Symfony\Component\Validator\Constraints; -use Symfony\Component\Validator\Constraints\AbstractComposite; - /** * @Annotation * @@ -24,4 +22,4 @@ */ class Each extends AbstractComposite { -} \ No newline at end of file +} diff --git a/src/Symfony/Component/Validator/Constraints/EachValidator.php b/src/Symfony/Component/Validator/Constraints/EachValidator.php index 8ef1647050b1..ac9a205515ee 100644 --- a/src/Symfony/Component/Validator/Constraints/EachValidator.php +++ b/src/Symfony/Component/Validator/Constraints/EachValidator.php @@ -12,8 +12,6 @@ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\Exception\UnexpectedTypeException; -use Symfony\Component\Validator\Constraints\AbstractCompositeValidator; /** * @author Marc Morera Merino diff --git a/src/Symfony/Component/Validator/Constraints/None.php b/src/Symfony/Component/Validator/Constraints/None.php index 3adeeb7c8b97..b282ee566290 100644 --- a/src/Symfony/Component/Validator/Constraints/None.php +++ b/src/Symfony/Component/Validator/Constraints/None.php @@ -11,10 +11,6 @@ namespace Symfony\Component\Validator\Constraints; -use Symfony\Component\Validator\Constraints\AbstractComposite; -use Symfony\Component\Validator\Exception\MissingOptionsException; - - /** * @Annotation * diff --git a/src/Symfony/Component/Validator/Constraints/NoneValidator.php b/src/Symfony/Component/Validator/Constraints/NoneValidator.php index 2fd70bee02dd..3894b2e6cc4c 100644 --- a/src/Symfony/Component/Validator/Constraints/NoneValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NoneValidator.php @@ -12,10 +12,6 @@ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\Exception\UnexpectedTypeException; -use Symfony\Component\Validator\Constraints\AbstractCompositeValidator; -use Symfony\Component\Validator\Exception\ConstraintDefinitionException; - /** * @author Marc Morera Merino @@ -48,7 +44,7 @@ public function doValidate($value, Constraint $constraint) */ $this->context->clearViolations(); - if ($constraintsSuccess > 0){ + if ($constraintsSuccess > 0) { $this->context->addViolation($constraint->violationMessage); } } diff --git a/src/Symfony/Component/Validator/Constraints/Some.php b/src/Symfony/Component/Validator/Constraints/Some.php index 12953fc83d94..199ce4cb6a34 100644 --- a/src/Symfony/Component/Validator/Constraints/Some.php +++ b/src/Symfony/Component/Validator/Constraints/Some.php @@ -11,10 +11,8 @@ namespace Symfony\Component\Validator\Constraints; -use Symfony\Component\Validator\Constraints\AbstractComposite; use Symfony\Component\Validator\Exception\MissingOptionsException; - /** * @Annotation * @@ -79,7 +77,7 @@ public function __construct($options = null) throw new MissingOptionsException(sprintf('"min" or "max" and "exactly" must not be given at the same time: %s', __CLASS__), array('min', 'max', 'exactly')); } - if (!isset($this->min) && !isset($this->exactly)){ + if (!isset($this->min) && !isset($this->exactly)) { $this->min = 1; } diff --git a/src/Symfony/Component/Validator/Constraints/SomeValidator.php b/src/Symfony/Component/Validator/Constraints/SomeValidator.php index 560f51d992f0..65486da69929 100644 --- a/src/Symfony/Component/Validator/Constraints/SomeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/SomeValidator.php @@ -12,10 +12,6 @@ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\Exception\UnexpectedTypeException; -use Symfony\Component\Validator\Constraints\AbstractCompositeValidator; -use Symfony\Component\Validator\Exception\ConstraintDefinitionException; - /** * @author Marc Morera Merino @@ -48,7 +44,7 @@ public function doValidate($value, Constraint $constraint) */ $this->context->clearViolations(); - if (isset($constraint->exactly) && $constraintsSuccess != $constraint->exactly){ + if (isset($constraint->exactly) && $constraintsSuccess != $constraint->exactly) { $this->context->addViolation($constraint->exactlyMessage, array( '{{ limit }}' => $constraint->exactly, @@ -57,7 +53,7 @@ public function doValidate($value, Constraint $constraint) return; } - if (isset($constraint->min) && $constraintsSuccess < $constraint->min){ + if (isset($constraint->min) && $constraintsSuccess < $constraint->min) { $this->context->addViolation($constraint->minMessage, array( '{{ limit }}' => $constraint->min, )); @@ -65,7 +61,7 @@ public function doValidate($value, Constraint $constraint) return; } - if (isset($constraint->max) && $constraintsSuccess > $constraint->max){ + if (isset($constraint->max) && $constraintsSuccess > $constraint->max) { $this->context->addViolation($constraint->maxMessage, array( '{{ limit }}' => $constraint->max, ), null, true); diff --git a/src/Symfony/Component/Validator/Constraints/Unique.php b/src/Symfony/Component/Validator/Constraints/Unique.php index b06cf42f619d..56cf6f11bc68 100644 --- a/src/Symfony/Component/Validator/Constraints/Unique.php +++ b/src/Symfony/Component/Validator/Constraints/Unique.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Validator\Constraints; - use Symfony\Component\Validator\Constraint; /** diff --git a/src/Symfony/Component/Validator/Constraints/UniqueValidator.php b/src/Symfony/Component/Validator/Constraints/UniqueValidator.php index 3b7af6074b87..a254c7290ce0 100644 --- a/src/Symfony/Component/Validator/Constraints/UniqueValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UniqueValidator.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\Constraints\AbstractCompositeValidator; /** * @author Marc Morera Merino @@ -28,7 +27,7 @@ class UniqueValidator extends AbstractCompositeValidator */ public function doValidate($value, Constraint $constraint) { - if ($this->findRepeated($value)){ + if ($this->findRepeated($value)) { $this->context->addViolation($constraint->uniqueMessage, $params=array()); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AbstractCompositeTest.php b/src/Symfony/Component/Validator/Tests/Constraints/AbstractCompositeTest.php index ba018c7656e1..3251adcb5f4c 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/AbstractCompositeTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/AbstractCompositeTest.php @@ -28,7 +28,6 @@ class AbstractCompositeTest extends \PHPUnit_Framework_TestCase */ private $simpleConstraint; - /** * Setup method */ @@ -43,7 +42,6 @@ public function setUp() ->getMock(); } - /** * Collection groups: none * Constraint groups: none @@ -73,7 +71,6 @@ public function testEmptyGroups() )); } - /** * Collection groups: [Default, Group1] * Constraint groups: none @@ -111,7 +108,6 @@ public function testCollectionGroups() )); } - /** * Collection groups: none * Constraint groups: [Default, Group1] @@ -158,7 +154,6 @@ public function testConstraintsGroups() )); } - /** * Collection groups: none * Constraint groups: [Default, Group1] diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NoneValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NoneValidatorTest.php index 0e4a6d9b4403..7e508e476e6b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NoneValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NoneValidatorTest.php @@ -13,7 +13,6 @@ use Symfony\Component\Validator\ExecutionContext; use Symfony\Component\Validator\Constraints\Range; -use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\Constraints\None; use Symfony\Component\Validator\Constraints\NoneValidator; use Symfony\Component\Validator\Tests\Fixtures\FakeMetadataFactory; @@ -190,8 +189,6 @@ public function testNotSuccessValidate($array) ); } - - /** * Adds validateValue assertions */ @@ -265,7 +262,6 @@ public function testFunctionalNotSuccessExactly() $this->assertCount(1, $visitor->getViolations()); } - /** * Data provider */ diff --git a/src/Symfony/Component/Validator/Tests/Constraints/SomeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/SomeValidatorTest.php index f09aa1d9ad54..3d2181b77c9b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/SomeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/SomeValidatorTest.php @@ -13,7 +13,6 @@ use Symfony\Component\Validator\ExecutionContext; use Symfony\Component\Validator\Constraints\Range; -use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\Constraints\Some; use Symfony\Component\Validator\Constraints\SomeValidator; use Symfony\Component\Validator\Tests\Fixtures\FakeMetadataFactory; @@ -665,7 +664,6 @@ protected function setValidateValueAssertions($array, $constraint1, $constraint2 } } - /** * Data provider */ @@ -676,4 +674,4 @@ public function getValidArguments() array(new \ArrayObject(array(5, 6, 7))), ); } -} \ No newline at end of file +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php index bf1bcb8d1a60..d1c1cde76b05 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Unique; -use Symfony\Component\Validator\Constraints\Valid; /** * @author Marc Morera Merino diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php index a054e1283517..5833810dfcb5 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php @@ -12,8 +12,6 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\ExecutionContext; -use Symfony\Component\Validator\Constraints\Range; -use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\Constraints\Unique; use Symfony\Component\Validator\Constraints\UniqueValidator; use Symfony\Component\Validator\Tests\Fixtures\FakeMetadataFactory; @@ -156,4 +154,4 @@ public function testFunctionalNotSuccessExactly() $visitor->validate(new EntityCollection(), 'Default', ''); $this->assertCount(1, $visitor->getViolations()); } -} \ No newline at end of file +} diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/EntityCollection.php b/src/Symfony/Component/Validator/Tests/Fixtures/EntityCollection.php index 73ddb1f69d24..ddeaf6f73d3f 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/EntityCollection.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/EntityCollection.php @@ -28,4 +28,4 @@ class EntityCollection * */ protected $collectionNotUnique = array(1,2,3,1,2); -} \ No newline at end of file +} From 9d4fda0c168fda65d769fbd4fd3b4ce9ff158ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Morales=20Valldep=C3=A9rez?= Date: Fri, 10 Jan 2014 20:43:50 +0100 Subject: [PATCH 3/3] fixed issues --- .../AbstractComparisonValidator.php | 8 ++-- .../Constraints/AbstractComposite.php | 31 +++++-------- .../AbstractCompositeValidator.php | 46 ------------------- .../Component/Validator/Constraints/All.php | 38 ++++++++++++++- .../Validator/Constraints/AllValidator.php | 26 ++++++++++- .../Component/Validator/Constraints/Each.php | 7 +-- .../Validator/Constraints/EachValidator.php | 18 ++++++-- .../Component/Validator/Constraints/None.php | 6 +-- .../Validator/Constraints/NoneValidator.php | 24 ++++++---- .../Component/Validator/Constraints/Some.php | 4 +- .../Validator/Constraints/SomeValidator.php | 22 +++++---- .../Validator/Constraints/Unique.php | 6 +-- .../Validator/Constraints/UniqueValidator.php | 20 +++++--- .../Constraints/AbstractCompositeTest.php | 2 +- .../Validator/Tests/Constraints/EachTest.php | 4 +- .../Tests/Constraints/EachValidatorTest.php | 4 +- .../Validator/Tests/Constraints/NoneTest.php | 4 +- .../Tests/Constraints/NoneValidatorTest.php | 4 +- .../Validator/Tests/Constraints/SomeTest.php | 4 +- .../Tests/Constraints/SomeValidatorTest.php | 4 +- .../Tests/Constraints/UniqueTest.php | 4 +- .../Tests/Constraints/UniqueValidatorTest.php | 4 +- .../Tests/Fixtures/EntityCollection.php | 2 +- 23 files changed, 150 insertions(+), 142 deletions(-) delete mode 100644 src/Symfony/Component/Validator/Constraints/AbstractCompositeValidator.php diff --git a/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php b/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php index f6b919331fae..593c5115ffd3 100644 --- a/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php +++ b/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php @@ -42,7 +42,7 @@ public function validate($value, Constraint $constraint) /** * Returns a string representation of the type of the value. * - * @param mixed $value + * @param mixed $value * * @return string */ @@ -54,7 +54,7 @@ private function valueToType($value) /** * Returns a string representation of the value. * - * @param mixed $value + * @param mixed $value * * @return string */ @@ -74,8 +74,8 @@ private function valueToString($value) /** * Compares the two given values to find if their relationship is valid * - * @param mixed $value1 The first value to compare - * @param mixed $value2 The second value to compare + * @param mixed $value1 The first value to compare + * @param mixed $value2 The second value to compare * * @return Boolean true if the relationship is valid, false otherwise */ diff --git a/src/Symfony/Component/Validator/Constraints/AbstractComposite.php b/src/Symfony/Component/Validator/Constraints/AbstractComposite.php index eef95c41d926..fc000fa5f166 100644 --- a/src/Symfony/Component/Validator/Constraints/AbstractComposite.php +++ b/src/Symfony/Component/Validator/Constraints/AbstractComposite.php @@ -18,7 +18,7 @@ * @Annotation * * @author Marc Morales Valldepérez - * @author Marc Morera Merino + * @author Marc Morera Merino */ abstract class AbstractComposite extends Constraint { @@ -41,14 +41,10 @@ public function __construct($options = null) $this->constraints = array($this->constraints); } - /** - * We consider explicid groups are defined if are not default one - */ - $areExplicitGroupsDefined = ( $this->groups != array(self::DEFAULT_GROUP) ); + // We consider explicid groups are defined if are not default one + $areExplicitGroupsDefined = ( $this->groups != array(self::DEFAULT_GROUP)); - /** - * Each constraint contained - */ + // Each constraint contained foreach ($this->constraints as $constraint) { if (!$constraint instanceof Constraint) { throw new ConstraintDefinitionException(sprintf('The value %s is not an instance of Constraint in constraint %s', $constraint, __CLASS__)); @@ -58,9 +54,7 @@ public function __construct($options = null) throw new ConstraintDefinitionException(sprintf('The constraint Valid cannot be nested inside constraint %s. You can only declare the Valid constraint directly on a field or method.', __CLASS__)); } - /** - * If explicid groups are defined - */ + // If explicid groups are defined if ($areExplicitGroupsDefined) { /** * If constraint has explicid groups defined @@ -68,17 +62,14 @@ public function __construct($options = null) * In that case, the groups of the nested constraint need to be * a subset of the groups of the outer constraint. */ - if ($constraint->groups != array(self::DEFAULT_GROUP)) { - /** - * If are not a subset - */ + if ($constraint->groups !== array(self::DEFAULT_GROUP)) { + + // If are not a subset if ($constraint->groups != array_intersect($constraint->groups, $this->groups)) { throw new ConstraintDefinitionException(sprintf('The groups defined in Constraint %s must be a subset of the groups defined in the Constraint %s', $constraint, __CLASS__)); } - /** - * Otherwise, we add all defined groups here - */ + // Otherwise, we add all defined groups here } else { foreach ($this->groups as $group) { $constraint->addImplicitGroupName($group); @@ -95,9 +86,9 @@ public function __construct($options = null) } /** - * Adds the given group if this constraint is in the Default group + * Adds the given group if this constraint is in the Default group. * - * Also propagate same method to nested Constraints + * Also propagate same method to nested Constraints. * * @param string $group * diff --git a/src/Symfony/Component/Validator/Constraints/AbstractCompositeValidator.php b/src/Symfony/Component/Validator/Constraints/AbstractCompositeValidator.php deleted file mode 100644 index 68260858087f..000000000000 --- a/src/Symfony/Component/Validator/Constraints/AbstractCompositeValidator.php +++ /dev/null @@ -1,46 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator\Constraints; - -use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\ConstraintValidator; -use Symfony\Component\Validator\Exception\UnexpectedTypeException; - -/** - * @author Marc Morera Merino - * @author Marc Morales Valldepérez - * - */ -abstract class AbstractCompositeValidator extends ConstraintValidator -{ - - /** - * {@inheritDoc} - */ - abstract public function doValidate($value, Constraint $constraint); - - /** - * {@inheritDoc} - */ - public function validate($value, Constraint $constraint) - { - if (null === $value) { - return; - } - - if (!is_array($value) && !$value instanceof \Traversable) { - throw new UnexpectedTypeException($value, 'array or Traversable'); - } - - $this->doValidate($value, $constraint); - } -} diff --git a/src/Symfony/Component/Validator/Constraints/All.php b/src/Symfony/Component/Validator/Constraints/All.php index 1ade87143e7b..35efec4e29aa 100644 --- a/src/Symfony/Component/Validator/Constraints/All.php +++ b/src/Symfony/Component/Validator/Constraints/All.php @@ -11,6 +11,9 @@ namespace Symfony\Component\Validator\Constraints; +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\Exception\ConstraintDefinitionException; + /** * @Annotation * @@ -21,7 +24,40 @@ * @deprecated Deprecated in 2.5, to be removed in 3.0. Use * {@link \Symfony\Component\Validator\Constraints\Each} instead. */ -class All extends Each +class All extends Constraint { + public $constraints = array(); + + /** + * {@inheritDoc} + */ + public function __construct($options = null) + { + parent::__construct($options); + + if (!is_array($this->constraints)) { + $this->constraints = array($this->constraints); + } + + foreach ($this->constraints as $constraint) { + if (!$constraint instanceof Constraint) { + throw new ConstraintDefinitionException(sprintf('The value %s is not an instance of Constraint in constraint %s', $constraint, __CLASS__)); + } + + if ($constraint instanceof Valid) { + throw new ConstraintDefinitionException(sprintf('The constraint Valid cannot be nested inside constraint %s. You can only declare the Valid constraint directly on a field or method.', __CLASS__)); + } + } + } + + public function getDefaultOption() + { + return 'constraints'; + } + + public function getRequiredOptions() + { + return array('constraints'); + } } diff --git a/src/Symfony/Component/Validator/Constraints/AllValidator.php b/src/Symfony/Component/Validator/Constraints/AllValidator.php index f5596ac7a73e..087a6f62896f 100644 --- a/src/Symfony/Component/Validator/Constraints/AllValidator.php +++ b/src/Symfony/Component/Validator/Constraints/AllValidator.php @@ -11,6 +11,10 @@ namespace Symfony\Component\Validator\Constraints; +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; + /** * @author Bernhard Schussek * @@ -19,7 +23,27 @@ * @deprecated Deprecated in 2.5, to be removed in 3.0. Use * {@link \Symfony\Component\Validator\Constraints\EachValidator} instead. */ -class AllValidator extends EachValidator +class AllValidator extends ConstraintValidator { + /** + * {@inheritDoc} + */ + public function validate($value, Constraint $constraint) + { + if (null === $value) { + return; + } + + if (!is_array($value) && !$value instanceof \Traversable) { + throw new UnexpectedTypeException($value, 'array or Traversable'); + } + + $group = $this->context->getGroup(); + foreach ($value as $key => $element) { + foreach ($constraint->constraints as $constr) { + $this->context->validateValue($element, $constr, '['.$key.']', $group); + } + } + } } diff --git a/src/Symfony/Component/Validator/Constraints/Each.php b/src/Symfony/Component/Validator/Constraints/Each.php index ddabfea22f06..a7a775b20902 100644 --- a/src/Symfony/Component/Validator/Constraints/Each.php +++ b/src/Symfony/Component/Validator/Constraints/Each.php @@ -14,11 +14,8 @@ /** * @Annotation * - * @author Marc Morera Merino - * @author Marc Morales Valldepérez - * - * @api - * + * @author Marc Morera Merino + * @author Marc Morales Valldepérez * */ class Each extends AbstractComposite { diff --git a/src/Symfony/Component/Validator/Constraints/EachValidator.php b/src/Symfony/Component/Validator/Constraints/EachValidator.php index ac9a205515ee..3be1350fea29 100644 --- a/src/Symfony/Component/Validator/Constraints/EachValidator.php +++ b/src/Symfony/Component/Validator/Constraints/EachValidator.php @@ -12,21 +12,29 @@ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez - * - * @api */ -class EachValidator extends AbstractCompositeValidator +class EachValidator extends ConstraintValidator { /** * {@inheritDoc} */ - public function doValidate($value, Constraint $constraint) + public function validate($value, Constraint $constraint) { + if (null === $value) { + return; + } + + if (!is_array($value) && !$value instanceof \Traversable) { + throw new UnexpectedTypeException($value, 'array or Traversable'); + } + $group = $this->context->getGroup(); foreach ($value as $key => $element) { diff --git a/src/Symfony/Component/Validator/Constraints/None.php b/src/Symfony/Component/Validator/Constraints/None.php index b282ee566290..63cf1713dcc5 100644 --- a/src/Symfony/Component/Validator/Constraints/None.php +++ b/src/Symfony/Component/Validator/Constraints/None.php @@ -14,10 +14,8 @@ /** * @Annotation * - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez - * - * @api */ class None extends AbstractComposite { @@ -27,5 +25,5 @@ class None extends AbstractComposite * * Message for notice Violation */ - public $violationMessage = 'None of this collection should pass validation.'; + public $message = 'None of this collection should pass validation.'; } diff --git a/src/Symfony/Component/Validator/Constraints/NoneValidator.php b/src/Symfony/Component/Validator/Constraints/NoneValidator.php index 3894b2e6cc4c..37084ddb4321 100644 --- a/src/Symfony/Component/Validator/Constraints/NoneValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NoneValidator.php @@ -12,21 +12,29 @@ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez - * - * @api */ -class NoneValidator extends AbstractCompositeValidator +class NoneValidator extends ConstraintValidator { /** * {@inheritDoc} */ - public function doValidate($value, Constraint $constraint) + public function validate($value, Constraint $constraint) { + if (null === $value) { + return; + } + + if (!is_array($value) && !$value instanceof \Traversable) { + throw new UnexpectedTypeException($value, 'array or Traversable'); + } + $group = $this->context->getGroup(); $totalIterations = count($value) * count($constraint->constraints); @@ -39,13 +47,11 @@ public function doValidate($value, Constraint $constraint) $constraintsSuccess = $totalIterations - (int) $this->context->getViolations()->count(); - /** - * We clear all violations as just current Validator should add real Violations - */ + //We clear all violations as just current Validator should add real Violations $this->context->clearViolations(); if ($constraintsSuccess > 0) { - $this->context->addViolation($constraint->violationMessage); + $this->context->addViolation($constraint->message); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Some.php b/src/Symfony/Component/Validator/Constraints/Some.php index 199ce4cb6a34..038da3249bf2 100644 --- a/src/Symfony/Component/Validator/Constraints/Some.php +++ b/src/Symfony/Component/Validator/Constraints/Some.php @@ -16,10 +16,8 @@ /** * @Annotation * - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez - * - * @api */ class Some extends AbstractComposite { diff --git a/src/Symfony/Component/Validator/Constraints/SomeValidator.php b/src/Symfony/Component/Validator/Constraints/SomeValidator.php index 65486da69929..6de02535739b 100644 --- a/src/Symfony/Component/Validator/Constraints/SomeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/SomeValidator.php @@ -12,21 +12,29 @@ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez - * - * @api */ -class SomeValidator extends AbstractCompositeValidator +class SomeValidator extends ConstraintValidator { /** * {@inheritDoc} */ - public function doValidate($value, Constraint $constraint) + public function validate($value, Constraint $constraint) { + if (null === $value) { + return; + } + + if (!is_array($value) && !$value instanceof \Traversable) { + throw new UnexpectedTypeException($value, 'array or Traversable'); + } + $group = $this->context->getGroup(); $totalIterations = count($value) * count($constraint->constraints); @@ -39,9 +47,7 @@ public function doValidate($value, Constraint $constraint) $constraintsSuccess = $totalIterations - (int) $this->context->getViolations()->count(); - /** - * We clear all violations as just current Validator should add real Violations - */ + // We clear all violations as just current Validator should add real Violations $this->context->clearViolations(); if (isset($constraint->exactly) && $constraintsSuccess != $constraint->exactly) { diff --git a/src/Symfony/Component/Validator/Constraints/Unique.php b/src/Symfony/Component/Validator/Constraints/Unique.php index 56cf6f11bc68..22120e8e63e2 100644 --- a/src/Symfony/Component/Validator/Constraints/Unique.php +++ b/src/Symfony/Component/Validator/Constraints/Unique.php @@ -16,10 +16,8 @@ /** * @Annotation * - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez - * - * @api */ class Unique extends Constraint { @@ -29,5 +27,5 @@ class Unique extends Constraint * * Message for notice Exactly Violation */ - public $uniqueMessage = 'This collection has repeated elements'; + public $message = 'This collection has repeated elements'; } diff --git a/src/Symfony/Component/Validator/Constraints/UniqueValidator.php b/src/Symfony/Component/Validator/Constraints/UniqueValidator.php index a254c7290ce0..c9dda8f2cc58 100644 --- a/src/Symfony/Component/Validator/Constraints/UniqueValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UniqueValidator.php @@ -12,24 +12,32 @@ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez - * - * @api */ -class UniqueValidator extends AbstractCompositeValidator +class UniqueValidator extends ConstraintValidator { /** * {@inheritDoc} */ - public function doValidate($value, Constraint $constraint) + public function validate($value, Constraint $constraint) { + if (null === $value) { + return; + } + + if (!is_array($value) && !$value instanceof \Traversable) { + throw new UnexpectedTypeException($value, 'array or Traversable'); + } + if ($this->findRepeated($value)) { - $this->context->addViolation($constraint->uniqueMessage, $params=array()); + $this->context->addViolation($constraint->message, $params=array()); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AbstractCompositeTest.php b/src/Symfony/Component/Validator/Tests/Constraints/AbstractCompositeTest.php index 3251adcb5f4c..5862dd77dff2 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/AbstractCompositeTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/AbstractCompositeTest.php @@ -16,7 +16,7 @@ /** * @author Marc Morales Valldepérez - * @author Marc Morera Merino + * @author Marc Morera Merino */ class AbstractCompositeTest extends \PHPUnit_Framework_TestCase { diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EachTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EachTest.php index 0e7fe1bb7e24..95abb18da149 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EachTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EachTest.php @@ -15,10 +15,8 @@ use Symfony\Component\Validator\Constraints\Valid; /** - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez - * - * @api */ class EachTest extends \PHPUnit_Framework_TestCase { diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EachValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EachValidatorTest.php index 3836baf37cba..9cf95037b1f7 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EachValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EachValidatorTest.php @@ -18,10 +18,8 @@ use Symfony\Component\Validator\Constraints\EachValidator; /** - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez - * - * @api */ class EachValidatorTest extends \PHPUnit_Framework_TestCase { diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NoneTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NoneTest.php index 36c1632579aa..38282fa48c97 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NoneTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NoneTest.php @@ -15,10 +15,8 @@ use Symfony\Component\Validator\Constraints\Valid; /** - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez - * - * @api */ class NoneTest extends \PHPUnit_Framework_TestCase { diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NoneValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NoneValidatorTest.php index 7e508e476e6b..0d652db0da52 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NoneValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NoneValidatorTest.php @@ -23,10 +23,8 @@ use Symfony\Component\Validator\Tests\Fixtures\EntityCollection; /** - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez - * - * @api */ class NoneValidatorTest extends \PHPUnit_Framework_TestCase { diff --git a/src/Symfony/Component/Validator/Tests/Constraints/SomeTest.php b/src/Symfony/Component/Validator/Tests/Constraints/SomeTest.php index a2a182f691ce..6624e1245ee9 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/SomeTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/SomeTest.php @@ -15,10 +15,8 @@ use Symfony\Component\Validator\Constraints\Valid; /** - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez - * - * @api */ class SomeTest extends \PHPUnit_Framework_TestCase { diff --git a/src/Symfony/Component/Validator/Tests/Constraints/SomeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/SomeValidatorTest.php index 3d2181b77c9b..24a294ba7115 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/SomeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/SomeValidatorTest.php @@ -23,10 +23,8 @@ use Symfony\Component\Validator\Tests\Fixtures\EntityCollection; /** - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez - * - * @api */ class SomeValidatorTest extends \PHPUnit_Framework_TestCase { diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php index d1c1cde76b05..a929288c771e 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UniqueTest.php @@ -14,10 +14,8 @@ use Symfony\Component\Validator\Constraints\Unique; /** - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez - * - * @api */ class UniqueTest extends \PHPUnit_Framework_TestCase { diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php index 5833810dfcb5..5e3e7a764491 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php @@ -22,10 +22,8 @@ use Symfony\Component\Validator\Tests\Fixtures\EntityCollection; /** - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez - * - * @api */ class UniqueValidatorTest extends \PHPUnit_Framework_TestCase { diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/EntityCollection.php b/src/Symfony/Component/Validator/Tests/Fixtures/EntityCollection.php index ddeaf6f73d3f..ac3b79f97be2 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/EntityCollection.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/EntityCollection.php @@ -14,7 +14,7 @@ use Symfony\Component\Validator\Constraints as Assert; /** - * @author Marc Morera Merino + * @author Marc Morera Merino * @author Marc Morales Valldepérez */ class EntityCollection