From 7504448ee753bb1d936c0705025c4e145c0f8bd5 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Sat, 26 Jul 2014 13:48:25 +0200 Subject: [PATCH] [Validator] Added extensive test coverage for the constraint validators for the different APIs --- .../Validator/Constraints/AllValidator.php | 4 +- .../Constraints/CollectionValidator.php | 17 +- .../Validator/Constraints/CountValidator.php | 6 +- .../Constraints/LegacyAllValidator.php | 4 +- .../Constraints/LegacyChoiceValidator.php | 4 +- .../Constraints/LegacyCollectionValidator.php | 14 +- .../Validator/Constraints/LengthValidator.php | 6 +- .../AbstractComparisonValidatorTestCase.php | 48 +-- .../AbstractConstraintValidatorTest.php | 298 ++++++++++++++++++ .../Tests/Constraints/AllValidatorTest.php | 52 +-- .../Tests/Constraints/BlankValidatorTest.php | 39 +-- .../Constraints/CallbackValidatorTest.php | 218 ++++++------- .../Constraints/CardSchemeValidatorTest.php | 42 ++- .../Tests/Constraints/ChoiceValidatorTest.php | 153 ++++----- ...llectionValidatorCustomArrayObjectTest.php | 58 +--- .../Constraints/CollectionValidatorTest.php | 212 ++++++------- .../CountValidatorCountableTest.php | 17 +- .../Tests/Constraints/CountValidatorTest.php | 71 ++--- .../Constraints/CountryValidatorTest.php | 49 ++- .../Constraints/CurrencyValidatorTest.php | 49 ++- .../Constraints/DateTimeValidatorTest.php | 47 ++- .../Tests/Constraints/DateValidatorTest.php | 47 ++- .../Tests/Constraints/EmailValidatorTest.php | 49 ++- .../Constraints/EqualToValidatorTest.php | 6 + .../Constraints/ExpressionValidatorTest.php | 163 ++++------ .../Tests/Constraints/FalseValidatorTest.php | 33 +- .../Constraints/FileValidatorPathTest.php | 10 +- .../Tests/Constraints/FileValidatorTest.php | 110 +++---- .../GreaterThanOrEqualValidatorTest.php | 6 + .../Constraints/GreaterThanValidatorTest.php | 6 + .../Tests/Constraints/IbanValidatorTest.php | 39 ++- .../Constraints/IdenticalToValidatorTest.php | 6 + .../Tests/Constraints/ImageValidatorTest.php | 146 ++++----- .../Tests/Constraints/IpValidatorTest.php | 164 ++++------ .../Tests/Constraints/IsbnValidatorTest.php | 79 ++--- .../Tests/Constraints/IssnValidatorTest.php | 83 ++--- .../Constraints/LanguageValidatorTest.php | 53 ++-- .../LegacyAllValidator2Dot4ApiTest.php | 32 ++ .../LegacyAllValidatorLegacyApiTest.php | 26 ++ .../LegacyBlankValidator2Dot4ApiTest.php | 26 ++ .../LegacyBlankValidatorLegacyApiTest.php | 26 ++ .../LegacyCallbackValidator2Dot4ApiTest.php | 26 ++ .../LegacyCallbackValidatorLegacyApiTest.php | 26 ++ .../LegacyCardSchemeValidator2Dot4ApiTest.php | 26 ++ ...LegacyCardSchemeValidatorLegacyApiTest.php | 26 ++ .../LegacyChoiceValidator2Dot4ApiTest.php | 32 ++ .../LegacyChoiceValidatorLegacyApiTest.php | 26 ++ ...cyCollectionValidatorArray2Dot4ApiTest.php | 28 ++ ...yCollectionValidatorArrayLegacyApiTest.php | 22 ++ ...ectionValidatorArrayObject2Dot4ApiTest.php | 28 ++ ...ctionValidatorArrayObjectLegacyApiTest.php | 22 ++ ...ValidatorCustomArrayObject2Dot4ApiTest.php | 28 ++ ...alidatorCustomArrayObjectLegacyApiTest.php | 22 ++ .../LegacyCountValidatorArray2Dot4ApiTest.php | 32 ++ ...LegacyCountValidatorArrayLegacyApiTest.php | 26 ++ ...acyCountValidatorCountable2Dot4ApiTest.php | 32 ++ ...cyCountValidatorCountableLegacyApiTest.php | 26 ++ .../LegacyCurrencyValidator2Dot4ApiTest.php | 26 ++ .../LegacyCurrencyValidatorLegacyApiTest.php | 26 ++ .../LegacyDateTimeValidator2Dot4ApiTest.php | 26 ++ .../LegacyDateTimeValidatorLegacyApiTest.php | 26 ++ .../LegacyDateValidator2Dot4ApiTest.php | 26 ++ .../LegacyDateValidatorLegacyApiTest.php | 26 ++ .../LegacyEmailValidator2Dot4ApiTest.php | 26 ++ .../LegacyEmailValidatorLegacyApiTest.php | 26 ++ .../LegacyEqualToValidator2Dot4ApiTest.php | 26 ++ .../LegacyEqualToValidatorLegacyApiTest.php | 26 ++ .../LegacyExpressionValidator2Dot4ApiTest.php | 26 ++ ...LegacyExpressionValidatorLegacyApiTest.php | 26 ++ .../LegacyFalseValidator2Dot4ApiTest.php | 26 ++ .../LegacyFalseValidatorLegacyApiTest.php | 26 ++ .../LegacyFileValidatorObject2Dot4ApiTest.php | 26 ++ ...LegacyFileValidatorObjectLegacyApiTest.php | 26 ++ .../LegacyFileValidatorPath2Dot4ApiTest.php | 26 ++ .../LegacyFileValidatorPathLegacyApiTest.php | 26 ++ ...reaterThanOrEqualValidator2Dot4ApiTest.php | 26 ++ ...eaterThanOrEqualValidatorLegacyApiTest.php | 26 ++ ...LegacyGreaterThanValidator2Dot4ApiTest.php | 26 ++ ...egacyGreaterThanValidatorLegacyApiTest.php | 26 ++ .../LegacyIbanValidator2Dot4ApiTest.php | 26 ++ .../LegacyIbanValidatorLegacyApiTest.php | 26 ++ ...LegacyIdenticalToValidator2Dot4ApiTest.php | 26 ++ ...egacyIdenticalToValidatorLegacyApiTest.php | 26 ++ .../LegacyImageValidator2Dot4ApiTest.php | 26 ++ .../LegacyImageValidatorLegacyApiTest.php | 26 ++ .../LegacyIpValidator2Dot4ApiTest.php | 26 ++ .../LegacyIpValidatorLegacyApiTest.php | 26 ++ .../LegacyIsbnValidator2Dot4ApiTest.php | 26 ++ .../LegacyIsbnValidatorLegacyApiTest.php | 26 ++ .../LegacyIssnValidator2Dot4ApiTest.php | 26 ++ .../LegacyIssnValidatorLegacyApiTest.php | 26 ++ .../LegacyLanguageValidator2Dot4ApiTest.php | 26 ++ .../LegacyLanguageValidatorLegacyApiTest.php | 26 ++ .../LegacyLengthValidator2Dot4ApiTest.php | 32 ++ .../LegacyLengthValidatorLegacyApiTest.php | 26 ++ ...cyLessThanOrEqualValidator2Dot4ApiTest.php | 26 ++ ...yLessThanOrEqualValidatorLegacyApiTest.php | 26 ++ .../LegacyLessThanValidator2Dot4ApiTest.php | 26 ++ .../LegacyLessThanValidatorLegacyApiTest.php | 26 ++ .../LegacyLocaleValidator2Dot4ApiTest.php | 26 ++ .../LegacyLocaleValidatorLegacyApiTest.php | 26 ++ .../LegacyLuhnValidator2Dot4ApiTest.php | 26 ++ .../LegacyLuhnValidatorLegacyApiTest.php | 26 ++ .../LegacyNotBlankValidator2Dot4ApiTest.php | 26 ++ .../LegacyNotBlankValidatorLegacyApiTest.php | 26 ++ .../LegacyNotEqualToValidator2Dot4ApiTest.php | 26 ++ ...LegacyNotEqualToValidatorLegacyApiTest.php | 26 ++ ...acyNotIdenticalToValidator2Dot4ApiTest.php | 26 ++ ...cyNotIdenticalToValidatorLegacyApiTest.php | 26 ++ .../LegacyNotNullValidator2Dot4ApiTest.php | 26 ++ .../LegacyNotNullValidatorLegacyApiTest.php | 26 ++ .../LegacyNullValidator2Dot4ApiTest.php | 26 ++ .../LegacyNullValidatorLegacyApiTest.php | 26 ++ .../LegacyRangeValidator2Dot4ApiTest.php | 26 ++ .../LegacyRangeValidatorLegacyApiTest.php | 26 ++ .../LegacyRegexValidator2Dot4ApiTest.php | 26 ++ .../LegacyRegexValidatorLegacyApiTest.php | 26 ++ .../LegacyTimeValidator2Dot4ApiTest.php | 26 ++ .../LegacyTimeValidatorLegacyApiTest.php | 26 ++ .../LegacyTrueValidator2Dot4ApiTest.php | 26 ++ .../LegacyTrueValidatorLegacyApiTest.php | 26 ++ .../LegacyTypeValidator2Dot4ApiTest.php | 36 +++ .../LegacyTypeValidatorLegacyApiTest.php | 28 ++ .../LegacyUrlValidator2Dot4ApiTest.php | 26 ++ .../LegacyUrlValidatorLegacyApiTest.php | 26 ++ .../LegacyUuidValidator2Dot4ApiTest.php | 26 ++ .../LegacyUuidValidatorLegacyApiTest.php | 26 ++ .../Tests/Constraints/LengthValidatorTest.php | 78 ++--- .../LessThanOrEqualValidatorTest.php | 6 + .../Constraints/LessThanValidatorTest.php | 6 + .../Tests/Constraints/LocaleValidatorTest.php | 49 ++- .../Tests/Constraints/LuhnValidatorTest.php | 42 +-- .../Constraints/NotBlankValidatorTest.php | 46 +-- .../Constraints/NotEqualToValidatorTest.php | 6 + .../NotIdenticalToValidatorTest.php | 6 + .../Constraints/NotNullValidatorTest.php | 29 +- .../Tests/Constraints/NullValidatorTest.php | 32 +- .../Tests/Constraints/RangeValidatorTest.php | 107 +++---- .../Tests/Constraints/RegexValidatorTest.php | 42 +-- .../Tests/Constraints/TimeValidatorTest.php | 47 ++- .../Tests/Constraints/TrueValidatorTest.php | 34 +- .../Tests/Constraints/TypeValidatorTest.php | 72 +++-- .../Tests/Constraints/UrlValidatorTest.php | 47 ++- .../Tests/Constraints/UuidValidatorTest.php | 72 ++--- .../Validator/Tests/Fixtures/Countable.php | 27 ++ .../Tests/Fixtures/CustomArrayObject.php | 70 ++++ .../Fixtures/StubGlobalExecutionContext.php | 71 +++++ .../Validator/LegacyValidator2Dot5ApiTest.php | 5 +- .../LegacyValidatorLegacyApiTest.php | 5 +- .../RecursiveValidator2Dot5ApiTest.php | 3 +- .../Component/Validator/ValidatorBuilder.php | 13 +- 151 files changed, 4049 insertions(+), 1650 deletions(-) create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyAllValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyAllValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyBlankValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyBlankValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCallbackValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCallbackValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCardSchemeValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCardSchemeValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyChoiceValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyChoiceValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArray2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArrayLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArrayObject2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArrayObjectLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorCustomArrayObject2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorCustomArrayObjectLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorArray2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorArrayLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorCountable2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorCountableLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCurrencyValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyCurrencyValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyDateTimeValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyDateTimeValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyDateValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyDateValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyEmailValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyEmailValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyEqualToValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyEqualToValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyExpressionValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyExpressionValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyFalseValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyFalseValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorObject2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorObjectLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorPath2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorPathLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanOrEqualValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanOrEqualValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyIbanValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyIbanValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyIdenticalToValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyIdenticalToValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyImageValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyImageValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyIpValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyIpValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyIsbnValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyIsbnValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyIssnValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyIssnValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyLanguageValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyLanguageValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyLengthValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyLengthValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanOrEqualValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanOrEqualValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyLocaleValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyLocaleValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyLuhnValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyLuhnValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyNotBlankValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyNotBlankValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyNotEqualToValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyNotEqualToValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyNotIdenticalToValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyNotIdenticalToValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyNotNullValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyNotNullValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyNullValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyNullValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyRangeValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyRangeValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyRegexValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyRegexValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyTimeValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyTimeValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyTrueValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyTrueValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyTypeValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyTypeValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyUrlValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyUrlValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyUuidValidator2Dot4ApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/LegacyUuidValidatorLegacyApiTest.php create mode 100644 src/Symfony/Component/Validator/Tests/Fixtures/Countable.php create mode 100644 src/Symfony/Component/Validator/Tests/Fixtures/CustomArrayObject.php create mode 100644 src/Symfony/Component/Validator/Tests/Fixtures/StubGlobalExecutionContext.php diff --git a/src/Symfony/Component/Validator/Constraints/AllValidator.php b/src/Symfony/Component/Validator/Constraints/AllValidator.php index cb952f93a7..144595ccb4 100644 --- a/src/Symfony/Component/Validator/Constraints/AllValidator.php +++ b/src/Symfony/Component/Validator/Constraints/AllValidator.php @@ -44,9 +44,7 @@ class AllValidator extends ConstraintValidator $validator = $context->getValidator()->inContext($context); foreach ($value as $key => $element) { - foreach ($constraint->constraints as $constr) { - $validator->atPath('['.$key.']')->validate($element, $constr, $group); - } + $validator->atPath('['.$key.']')->validate($element, $constraint->constraints, $group); } } } diff --git a/src/Symfony/Component/Validator/Constraints/CollectionValidator.php b/src/Symfony/Component/Validator/Constraints/CollectionValidator.php index bf8e6d0b91..c345601b91 100644 --- a/src/Symfony/Component/Validator/Constraints/CollectionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CollectionValidator.php @@ -53,18 +53,20 @@ class CollectionValidator extends ConstraintValidator $validator = $context->getValidator()->inContext($context); foreach ($constraint->fields as $field => $fieldConstraint) { - if ( - // bug fix issue #2779 - (is_array($value) && array_key_exists($field, $value)) || - ($value instanceof \ArrayAccess && $value->offsetExists($field)) - ) { - foreach ($fieldConstraint->constraints as $constr) { - $validator->atPath('['.$field.']')->validate($value[$field], $constr, $group); + // bug fix issue #2779 + $existsInArray = is_array($value) && array_key_exists($field, $value); + $existsInArrayAccess = $value instanceof \ArrayAccess && $value->offsetExists($field); + + if ($existsInArray || $existsInArrayAccess) { + if (count($fieldConstraint->constraints) > 0) { + $validator->atPath('['.$field.']') + ->validate($value[$field], $fieldConstraint->constraints, $group); } } elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) { $context->buildViolation($constraint->missingFieldsMessage) ->atPath('['.$field.']') ->setParameter('{{ field }}', $field) + ->setInvalidValue(null) ->addViolation(); } } @@ -75,6 +77,7 @@ class CollectionValidator extends ConstraintValidator $context->buildViolation($constraint->extraFieldsMessage) ->atPath('['.$field.']') ->setParameter('{{ field }}', $field) + ->setInvalidValue($fieldValue) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Constraints/CountValidator.php b/src/Symfony/Component/Validator/Constraints/CountValidator.php index 160ba7ac0b..e3fea656b5 100644 --- a/src/Symfony/Component/Validator/Constraints/CountValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CountValidator.php @@ -39,7 +39,7 @@ class CountValidator extends ConstraintValidator $this->context->buildViolation($constraint->exactMessage) ->setParameter('{{ count }}', $count) ->setParameter('{{ limit }}', $constraint->min) - ->setValue($value) + ->setInvalidValue($value) ->setPlural((int) $constraint->min) ->addViolation(); @@ -50,7 +50,7 @@ class CountValidator extends ConstraintValidator $this->context->buildViolation($constraint->maxMessage) ->setParameter('{{ count }}', $count) ->setParameter('{{ limit }}', $constraint->max) - ->setValue($value) + ->setInvalidValue($value) ->setPlural((int) $constraint->max) ->addViolation(); @@ -61,7 +61,7 @@ class CountValidator extends ConstraintValidator $this->context->buildViolation($constraint->minMessage) ->setParameter('{{ count }}', $count) ->setParameter('{{ limit }}', $constraint->min) - ->setValue($value) + ->setInvalidValue($value) ->setPlural((int) $constraint->min) ->addViolation(); } diff --git a/src/Symfony/Component/Validator/Constraints/LegacyAllValidator.php b/src/Symfony/Component/Validator/Constraints/LegacyAllValidator.php index 47e037a9b4..844fe31782 100644 --- a/src/Symfony/Component/Validator/Constraints/LegacyAllValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LegacyAllValidator.php @@ -43,9 +43,7 @@ class LegacyAllValidator extends ConstraintValidator $group = $context->getGroup(); foreach ($value as $key => $element) { - foreach ($constraint->constraints as $constr) { - $context->validateValue($element, $constr, '['.$key.']', $group); - } + $context->validateValue($element, $constraint->constraints, '['.$key.']', $group); } } } diff --git a/src/Symfony/Component/Validator/Constraints/LegacyChoiceValidator.php b/src/Symfony/Component/Validator/Constraints/LegacyChoiceValidator.php index 26912152fc..68f4faf507 100644 --- a/src/Symfony/Component/Validator/Constraints/LegacyChoiceValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LegacyChoiceValidator.php @@ -70,13 +70,13 @@ class LegacyChoiceValidator extends ConstraintValidator $count = count($value); if ($constraint->min !== null && $count < $constraint->min) { - $this->context->addViolation($constraint->minMessage, array('{{ limit }}' => $constraint->min), null, (int) $constraint->min); + $this->context->addViolation($constraint->minMessage, array('{{ limit }}' => $constraint->min), $value, (int) $constraint->min); return; } if ($constraint->max !== null && $count > $constraint->max) { - $this->context->addViolation($constraint->maxMessage, array('{{ limit }}' => $constraint->max), null, (int) $constraint->max); + $this->context->addViolation($constraint->maxMessage, array('{{ limit }}' => $constraint->max), $value, (int) $constraint->max); return; } diff --git a/src/Symfony/Component/Validator/Constraints/LegacyCollectionValidator.php b/src/Symfony/Component/Validator/Constraints/LegacyCollectionValidator.php index 6618079fd1..cc1067439e 100644 --- a/src/Symfony/Component/Validator/Constraints/LegacyCollectionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LegacyCollectionValidator.php @@ -52,13 +52,13 @@ class LegacyCollectionValidator extends ConstraintValidator $group = $context->getGroup(); foreach ($constraint->fields as $field => $fieldConstraint) { - if ( - // bug fix issue #2779 - (is_array($value) && array_key_exists($field, $value)) || - ($value instanceof \ArrayAccess && $value->offsetExists($field)) - ) { - foreach ($fieldConstraint->constraints as $constr) { - $context->validateValue($value[$field], $constr, '['.$field.']', $group); + // bug fix issue #2779 + $existsInArray = is_array($value) && array_key_exists($field, $value); + $existsInArrayAccess = $value instanceof \ArrayAccess && $value->offsetExists($field); + + if ($existsInArray || $existsInArrayAccess) { + if (count($fieldConstraint->constraints) > 0) { + $context->validateValue($value[$field], $fieldConstraint->constraints, '['.$field.']', $group); } } elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) { $context->addViolationAt('['.$field.']', $constraint->missingFieldsMessage, array( diff --git a/src/Symfony/Component/Validator/Constraints/LengthValidator.php b/src/Symfony/Component/Validator/Constraints/LengthValidator.php index 2d94ae4d8d..df849544b3 100644 --- a/src/Symfony/Component/Validator/Constraints/LengthValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LengthValidator.php @@ -51,7 +51,7 @@ class LengthValidator extends ConstraintValidator $this->context->buildViolation($constraint->exactMessage) ->setParameter('{{ value }}', $stringValue) ->setParameter('{{ limit }}', $constraint->min) - ->setValue($value) + ->setInvalidValue($value) ->setPlural((int) $constraint->min) ->addViolation(); @@ -62,7 +62,7 @@ class LengthValidator extends ConstraintValidator $this->context->buildViolation($constraint->maxMessage) ->setParameter('{{ value }}', $stringValue) ->setParameter('{{ limit }}', $constraint->max) - ->setValue($value) + ->setInvalidValue($value) ->setPlural((int) $constraint->max) ->addViolation(); @@ -73,7 +73,7 @@ class LengthValidator extends ConstraintValidator $this->context->buildViolation($constraint->minMessage) ->setParameter('{{ value }}', $stringValue) ->setParameter('{{ limit }}', $constraint->min) - ->setValue($value) + ->setInvalidValue($value) ->setPlural((int) $constraint->min) ->addViolation(); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php index 36405e3de8..e9fde5f61b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php @@ -32,30 +32,15 @@ class ComparisonTest_Class /** * @author Daniel Holmes */ -abstract class AbstractComparisonValidatorTestCase extends \PHPUnit_Framework_TestCase +abstract class AbstractComparisonValidatorTestCase extends AbstractConstraintValidatorTest { - private $validator; - private $context; - - protected function setUp() - { - $this->validator = $this->createValidator(); - $this->context = $this->getMockBuilder('Symfony\Component\Validator\ExecutionContext') - ->disableOriginalConstructor() - ->getMock(); - $this->validator->initialize($this->context); - } - /** - * @return AbstractComparisonValidator + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException */ - abstract protected function createValidator(); - public function testThrowsConstraintExceptionIfNoValueOrProperty() { - $this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException'); - $comparison = $this->createConstraint(array()); + $this->validator->validate('some value', $comparison); } @@ -66,16 +51,11 @@ abstract class AbstractComparisonValidatorTestCase extends \PHPUnit_Framework_Te */ public function testValidComparisonToValue($dirtyValue, $comparisonValue) { - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = $this->createConstraint(array('value' => $comparisonValue)); - $this->context->expects($this->any()) - ->method('getPropertyPath') - ->will($this->returnValue('property1')); - $this->validator->validate($dirtyValue, $constraint); + + $this->assertNoViolation(); } /** @@ -95,19 +75,13 @@ abstract class AbstractComparisonValidatorTestCase extends \PHPUnit_Framework_Te $constraint = $this->createConstraint(array('value' => $comparedValue)); $constraint->message = 'Constraint Message'; - $this->context->expects($this->any()) - ->method('getPropertyPath') - ->will($this->returnValue('property1')); - - $this->context->expects($this->once()) - ->method('addViolation') - ->with('Constraint Message', array( - '{{ value }}' => $comparedValueString, - '{{ compared_value }}' => $comparedValueString, - '{{ compared_value_type }}' => $comparedValueType - )); - $this->validator->validate($dirtyValue, $constraint); + + $this->assertViolation('Constraint Message', array( + '{{ value }}' => $comparedValueString, + '{{ compared_value }}' => $comparedValueString, + '{{ compared_value_type }}' => $comparedValueType + )); } /** diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php new file mode 100644 index 0000000000..65cd62586f --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php @@ -0,0 +1,298 @@ + + * + * 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\ConstraintValidatorInterface; +use Symfony\Component\Validator\ConstraintViolation; +use Symfony\Component\Validator\Context\ExecutionContext; +use Symfony\Component\Validator\Context\ExecutionContextInterface; +use Symfony\Component\Validator\Context\LegacyExecutionContext; +use Symfony\Component\Validator\Mapping\ClassMetadata; +use Symfony\Component\Validator\Mapping\PropertyMetadata; +use Symfony\Component\Validator\Tests\Fixtures\StubGlobalExecutionContext; +use Symfony\Component\Validator\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +abstract class AbstractConstraintValidatorTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var ExecutionContextInterface + */ + protected $context; + + /** + * @var ConstraintValidatorInterface + */ + protected $validator; + + protected $group; + + protected $metadata; + + protected $object; + + protected $value; + + protected $root; + + protected $propertyPath; + + protected function setUp() + { + $this->group = 'MyGroup'; + $this->metadata = null; + $this->object = null; + $this->value = 'InvalidValue'; + $this->root = 'root'; + $this->propertyPath = 'property.path'; + $this->context = $this->createContext(); + $this->validator = $this->createValidator(); + $this->validator->initialize($this->context); + } + + protected function createContext() + { + $translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface'); + + if (Validation::API_VERSION_2_4 === $this->getApiVersion()) { + return $this->getMockBuilder('Symfony\Component\Validator\ExecutionContext') + ->setConstructorArgs(array( + new StubGlobalExecutionContext($this->root), + $translator, + null, + $this->metadata, + $this->value, + $this->group, + $this->propertyPath + )) + ->setMethods(array('validate', 'validateValue')) + ->getMock(); + } + + $validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface'); + $contextualValidator = $this->getMock('Symfony\Component\Validator\Validator\ContextualValidatorInterface'); + + switch ($this->getApiVersion()) { + case Validation::API_VERSION_2_5: + $context = new ExecutionContext( + $validator, + $this->root, + $translator + ); + break; + case Validation::API_VERSION_2_5_BC: + $context = new LegacyExecutionContext( + $validator, + $this->root, + $this->getMock('Symfony\Component\Validator\MetadataFactoryInterface'), + $translator + ); + break; + default: + throw new \RuntimeException('Invalid API version'); + } + + $context->setGroup($this->group); + $context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath); + + $validator->expects($this->any()) + ->method('inContext') + ->with($context) + ->will($this->returnValue($contextualValidator)); + + return $context; + } + + protected function createViolation($message, array $parameters = array(), $propertyPath = 'property.path', $invalidValue = 'InvalidValue', $plural = null, $code = null) + { + return new ConstraintViolation( + null, + $message, + $parameters, + $this->root, + $propertyPath, + $invalidValue, + $plural, + $code + ); + } + + protected function setGroup($group) + { + $this->group = $group; + + switch ($this->getApiVersion()) { + case Validation::API_VERSION_2_4: + $this->context = $this->createContext(); + $this->validator->initialize($this->context); + break; + case Validation::API_VERSION_2_5: + case Validation::API_VERSION_2_5_BC: + $this->context->setGroup($group); + break; + } + } + + protected function setObject($object) + { + $this->object = $object; + $this->metadata = is_object($object) + ? new ClassMetadata(get_class($object)) + : null; + + switch ($this->getApiVersion()) { + case Validation::API_VERSION_2_4: + $this->context = $this->createContext(); + $this->validator->initialize($this->context); + break; + case Validation::API_VERSION_2_5: + case Validation::API_VERSION_2_5_BC: + $this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath); + break; + } + } + + protected function setProperty($object, $property) + { + $this->object = $object; + $this->metadata = is_object($object) + ? new PropertyMetadata(get_class($object), $property) + : null; + + switch ($this->getApiVersion()) { + case Validation::API_VERSION_2_4: + $this->context = $this->createContext(); + $this->validator->initialize($this->context); + break; + case Validation::API_VERSION_2_5: + case Validation::API_VERSION_2_5_BC: + $this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath); + break; + } + } + + protected function setValue($value) + { + $this->value = $value; + + switch ($this->getApiVersion()) { + case Validation::API_VERSION_2_4: + $this->context = $this->createContext(); + $this->validator->initialize($this->context); + break; + case Validation::API_VERSION_2_5: + case Validation::API_VERSION_2_5_BC: + $this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath); + break; + } + } + + protected function setRoot($root) + { + $this->root = $root; + $this->context = $this->createContext(); + $this->validator->initialize($this->context); + } + + protected function setPropertyPath($propertyPath) + { + $this->propertyPath = $propertyPath; + + switch ($this->getApiVersion()) { + case Validation::API_VERSION_2_4: + $this->context = $this->createContext(); + $this->validator->initialize($this->context); + break; + case Validation::API_VERSION_2_5: + case Validation::API_VERSION_2_5_BC: + $this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath); + break; + } + } + + protected function expectValidateAt($i, $propertyPath, $value, $group) + { + switch ($this->getApiVersion()) { + case Validation::API_VERSION_2_4: + $this->context->expects($this->at($i)) + ->method('validate') + ->with($value, $propertyPath, $group); + break; + case Validation::API_VERSION_2_5: + case Validation::API_VERSION_2_5_BC: + $validator = $this->context->getValidator()->inContext($this->context); + $validator->expects($this->at(2 * $i)) + ->method('atPath') + ->with($propertyPath) + ->will($this->returnValue($validator)); + $validator->expects($this->at(2 * $i + 1)) + ->method('validate') + ->with($value, array(), $group); + break; + } + } + + protected function expectValidateValueAt($i, $propertyPath, $value, $constraints, $group) + { + switch ($this->getApiVersion()) { + case Validation::API_VERSION_2_4: + $this->context->expects($this->at($i)) + ->method('validateValue') + ->with($value, $constraints, $propertyPath, $group); + break; + case Validation::API_VERSION_2_5: + case Validation::API_VERSION_2_5_BC: + $contextualValidator = $this->context->getValidator()->inContext($this->context); + $contextualValidator->expects($this->at(2 * $i)) + ->method('atPath') + ->with($propertyPath) + ->will($this->returnValue($contextualValidator)); + $contextualValidator->expects($this->at(2 * $i + 1)) + ->method('validate') + ->with($value, $constraints, $group); + break; + } + } + + protected function assertNoViolation() + { + $this->assertCount(0, $this->context->getViolations()); + } + + protected function assertViolation($message, array $parameters = array(), $propertyPath = 'property.path', $invalidValue = 'InvalidValue', $plural = null, $code = null) + { + $violations = $this->context->getViolations(); + + $this->assertCount(1, $violations); + $this->assertEquals($this->createViolation($message, $parameters, $propertyPath, $invalidValue, $plural, $code), $violations[0]); + } + + protected function assertViolations(array $expected) + { + $violations = $this->context->getViolations(); + + $this->assertCount(count($expected), $violations); + + $i = 0; + + foreach ($expected as $violation) { + $this->assertEquals($violation, $violations[$i++]); + } + } + + abstract protected function getApiVersion(); + + abstract protected function createValidator(); +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AllValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/AllValidatorTest.php index 3a654a3b45..68011e8f50 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/AllValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/AllValidatorTest.php @@ -15,35 +15,25 @@ use Symfony\Component\Validator\Constraints\All; use Symfony\Component\Validator\Constraints\AllValidator; use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\Constraints\Range; +use Symfony\Component\Validator\Validation; -class AllValidatorTest extends \PHPUnit_Framework_TestCase +class AllValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new AllValidator(); - $this->validator->initialize($this->context); - - $this->context->expects($this->any()) - ->method('getGroup') - ->will($this->returnValue('MyGroup')); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->validator = null; - $this->context = null; + return new AllValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new All(new Range(array('min' => 4)))); + + $this->assertNoViolation(); } /** @@ -61,18 +51,15 @@ class AllValidatorTest extends \PHPUnit_Framework_TestCase { $constraint = new Range(array('min' => 4)); - $i = 1; + $i = 0; foreach ($array as $key => $value) { - $this->context->expects($this->at($i++)) - ->method('validateValue') - ->with($value, $constraint, '['.$key.']', 'MyGroup'); + $this->expectValidateValueAt($i++, '['.$key.']', $value, array($constraint), 'MyGroup'); } - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($array, new All($constraint)); + + $this->assertNoViolation(); } /** @@ -84,21 +71,16 @@ class AllValidatorTest extends \PHPUnit_Framework_TestCase $constraint2 = new NotNull(); $constraints = array($constraint1, $constraint2); - $i = 1; + + $i = 0; 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->expectValidateValueAt($i++, '['.$key.']', $value, array($constraint1, $constraint2), 'MyGroup'); } - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($array, new All($constraints)); + + $this->assertNoViolation(); } public function getValidArguments() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php index 0fbe5e6fbb..c252f474ba 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php @@ -13,39 +13,33 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Blank; use Symfony\Component\Validator\Constraints\BlankValidator; +use Symfony\Component\Validator\ConstraintViolation; +use Symfony\Component\Validator\Validation; -class BlankValidatorTest extends \PHPUnit_Framework_TestCase +class BlankValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new BlankValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new BlankValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Blank()); + + $this->assertNoViolation(); } public function testBlankIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Blank()); + + $this->assertNoViolation(); } /** @@ -57,13 +51,12 @@ class BlankValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $value, - )); - $this->validator->validate($value, $constraint); + + $this->assertViolation( + 'myMessage', + array('{{ value }}' => $value) + ); } public function getInvalidValues() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php index 06883e3525..828a28e929 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php @@ -14,13 +14,14 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Constraints\CallbackValidator; -use Symfony\Component\Validator\ExecutionContext; +use Symfony\Component\Validator\ExecutionContextInterface; +use Symfony\Component\Validator\Validation; class CallbackValidatorTest_Class { - public static function validateCallback($object, ExecutionContext $context) + public static function validateCallback($object, ExecutionContextInterface $context) { - $context->addViolation('Callback message', array('{{ value }}' => 'foobar'), 'invalidValue'); + $context->addViolation('Callback message', array('{{ value }}' => 'foobar')); return false; } @@ -28,45 +29,38 @@ class CallbackValidatorTest_Class class CallbackValidatorTest_Object { - public function validate(ExecutionContext $context) + public function validate(ExecutionContextInterface $context) { - $context->addViolation('My message', array('{{ value }}' => 'foobar'), 'invalidValue'); + $context->addViolation('My message', array('{{ value }}' => 'foobar')); return false; } - public static function validateStatic($object, ExecutionContext $context) + public static function validateStatic($object, ExecutionContextInterface $context) { - $context->addViolation('Static message', array('{{ value }}' => 'baz'), 'otherInvalidValue'); + $context->addViolation('Static message', array('{{ value }}' => 'baz')); return false; } } -class CallbackValidatorTest extends \PHPUnit_Framework_TestCase +class CallbackValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new CallbackValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new CallbackValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Callback(array('foo'))); + + $this->assertNoViolation(); } public function testSingleMethod() @@ -74,13 +68,11 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase $object = new CallbackValidatorTest_Object(); $constraint = new Callback('validate'); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('My message', array( - '{{ value }}' => 'foobar', - )); - $this->validator->validate($object, $constraint); + + $this->assertViolation('My message', array( + '{{ value }}' => 'foobar', + )); } public function testSingleMethodExplicitName() @@ -88,13 +80,11 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase $object = new CallbackValidatorTest_Object(); $constraint = new Callback(array('callback' => 'validate')); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('My message', array( - '{{ value }}' => 'foobar', - )); - $this->validator->validate($object, $constraint); + + $this->assertViolation('My message', array( + '{{ value }}' => 'foobar', + )); } public function testSingleStaticMethod() @@ -102,68 +92,60 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase $object = new CallbackValidatorTest_Object(); $constraint = new Callback('validateStatic'); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('Static message', array( - '{{ value }}' => 'baz', - )); - $this->validator->validate($object, $constraint); + + $this->assertViolation('Static message', array( + '{{ value }}' => 'baz', + )); } public function testClosure() { $object = new CallbackValidatorTest_Object(); - $constraint = new Callback(function ($object, ExecutionContext $context) { - $context->addViolation('My message', array('{{ value }}' => 'foobar'), 'invalidValue'); + $constraint = new Callback(function ($object, ExecutionContextInterface $context) { + $context->addViolation('My message', array('{{ value }}' => 'foobar')); return false; }); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('My message', array( - '{{ value }}' => 'foobar', - )); - $this->validator->validate($object, $constraint); + + $this->assertViolation('My message', array( + '{{ value }}' => 'foobar', + )); } public function testClosureNullObject() { - $constraint = new Callback(function ($object, ExecutionContext $context) { - $context->addViolation('My message', array('{{ value }}' => 'foobar'), 'invalidValue'); + $constraint = new Callback(function ($object, ExecutionContextInterface $context) { + $context->addViolation('My message', array('{{ value }}' => 'foobar')); return false; }); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('My message', array( - '{{ value }}' => 'foobar', - )); - $this->validator->validate(null, $constraint); + + $this->assertViolation('My message', array( + '{{ value }}' => 'foobar', + )); } public function testClosureExplicitName() { $object = new CallbackValidatorTest_Object(); $constraint = new Callback(array( - 'callback' => function ($object, ExecutionContext $context) { - $context->addViolation('My message', array('{{ value }}' => 'foobar'), 'invalidValue'); + 'callback' => function ($object, ExecutionContextInterface $context) { + $context->addViolation('My message', array('{{ value }}' => 'foobar')); return false; }, )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('My message', array( - '{{ value }}' => 'foobar', - )); - $this->validator->validate($object, $constraint); + + $this->assertViolation('My message', array( + '{{ value }}' => 'foobar', + )); } public function testArrayCallable() @@ -171,26 +153,22 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase $object = new CallbackValidatorTest_Object(); $constraint = new Callback(array(__CLASS__.'_Class', 'validateCallback')); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('Callback message', array( - '{{ value }}' => 'foobar', - )); - $this->validator->validate($object, $constraint); + + $this->assertViolation('Callback message', array( + '{{ value }}' => 'foobar', + )); } public function testArrayCallableNullObject() { $constraint = new Callback(array(__CLASS__.'_Class', 'validateCallback')); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('Callback message', array( - '{{ value }}' => 'foobar', - )); - $this->validator->validate(null, $constraint); + + $this->assertViolation('Callback message', array( + '{{ value }}' => 'foobar', + )); } public function testArrayCallableExplicitName() @@ -200,13 +178,11 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase 'callback' => array(__CLASS__.'_Class', 'validateCallback'), )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('Callback message', array( - '{{ value }}' => 'foobar', - )); - $this->validator->validate($object, $constraint); + + $this->assertViolation('Callback message', array( + '{{ value }}' => 'foobar', + )); } // BC with Symfony < 2.4 @@ -215,13 +191,11 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase $object = new CallbackValidatorTest_Object(); $constraint = new Callback(array('validate')); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('My message', array( - '{{ value }}' => 'foobar', - )); - $this->validator->validate($object, $constraint); + + $this->assertViolation('My message', array( + '{{ value }}' => 'foobar', + )); } // BC with Symfony < 2.4 @@ -230,13 +204,11 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase $object = new CallbackValidatorTest_Object(); $constraint = new Callback(array('methods' => array('validate'))); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('My message', array( - '{{ value }}' => 'foobar', - )); - $this->validator->validate($object, $constraint); + + $this->assertViolation('My message', array( + '{{ value }}' => 'foobar', + )); } // BC with Symfony < 2.4 @@ -245,18 +217,16 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase $object = new CallbackValidatorTest_Object(); $constraint = new Callback(array('validate', 'validateStatic')); - $this->context->expects($this->at(0)) - ->method('addViolation') - ->with('My message', array( - '{{ value }}' => 'foobar', - )); - $this->context->expects($this->at(1)) - ->method('addViolation') - ->with('Static message', array( - '{{ value }}' => 'baz', - )); - $this->validator->validate($object, $constraint); + + $this->assertViolations(array( + $this->createViolation('My message', array( + '{{ value }}' => 'foobar', + )), + $this->createViolation('Static message', array( + '{{ value }}' => 'baz', + )), + )); } // BC with Symfony < 2.4 @@ -267,18 +237,16 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase 'methods' => array('validate', 'validateStatic'), )); - $this->context->expects($this->at(0)) - ->method('addViolation') - ->with('My message', array( - '{{ value }}' => 'foobar', - )); - $this->context->expects($this->at(1)) - ->method('addViolation') - ->with('Static message', array( - '{{ value }}' => 'baz', - )); - $this->validator->validate($object, $constraint); + + $this->assertViolations(array( + $this->createViolation('My message', array( + '{{ value }}' => 'foobar', + )), + $this->createViolation('Static message', array( + '{{ value }}' => 'baz', + )), + )); } // BC with Symfony < 2.4 @@ -289,13 +257,11 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase array(__CLASS__.'_Class', 'validateCallback') )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('Callback message', array( - '{{ value }}' => 'foobar', - )); - $this->validator->validate($object, $constraint); + + $this->assertViolation('Callback message', array( + '{{ value }}' => 'foobar', + )); } // BC with Symfony < 2.4 @@ -306,13 +272,11 @@ class CallbackValidatorTest extends \PHPUnit_Framework_TestCase 'methods' => array(array(__CLASS__.'_Class', 'validateCallback')), )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('Callback message', array( - '{{ value }}' => 'foobar', - )); - $this->validator->validate($object, $constraint); + + $this->assertViolation('Callback message', array( + '{{ value }}' => 'foobar', + )); } /** diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php index ee7cc7a60a..01949492cf 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php @@ -13,39 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\CardScheme; use Symfony\Component\Validator\Constraints\CardSchemeValidator; +use Symfony\Component\Validator\Validation; -class CardSchemeValidatorTest extends \PHPUnit_Framework_TestCase +class CardSchemeValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new CardSchemeValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new CardSchemeValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new CardScheme(array('schemes' => array()))); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new CardScheme(array('schemes' => array()))); + + $this->assertNoViolation(); } /** @@ -53,10 +46,9 @@ class CardSchemeValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidNumbers($scheme, $number) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($number, new CardScheme(array('schemes' => $scheme))); + + $this->assertNoViolation(); } /** @@ -64,10 +56,14 @@ class CardSchemeValidatorTest extends \PHPUnit_Framework_TestCase */ public function testInvalidNumbers($scheme, $number) { - $this->context->expects($this->once()) - ->method('addViolation'); + $constraint = new CardScheme(array( + 'schemes' => $scheme, + 'message' => 'myMessage', + )); - $this->validator->validate($number, new CardScheme(array('schemes' => $scheme))); + $this->validator->validate($number, $constraint); + + $this->assertViolation('myMessage', array()); } public function getValidNumbers() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php index 9267fdb872..c41d57b533 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php @@ -13,39 +13,31 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Choice; use Symfony\Component\Validator\Constraints\ChoiceValidator; +use Symfony\Component\Validator\Mapping\ClassMetadata; +use Symfony\Component\Validator\Validation; function choice_callback() { return array('foo', 'bar'); } -class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase +class ChoiceValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; + protected function getApiVersion() + { + return Validation::API_VERSION_2_5; + } + + protected function createValidator() + { + return new ChoiceValidator(); + } public static function staticCallback() { return array('foo', 'bar'); } - protected function setUp() - { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new ChoiceValidator(); - $this->validator->initialize($this->context); - - $this->context->expects($this->any()) - ->method('getClassName') - ->will($this->returnValue(__CLASS__)); - } - - protected function tearDown() - { - $this->context = null; - $this->validator = null; - } - /** * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException */ @@ -61,10 +53,9 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Choice(array('choices' => array('foo', 'bar')))); + + $this->assertNoViolation(); } /** @@ -87,20 +78,18 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase { $constraint = new Choice(array('choices' => array('foo', 'bar'))); - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('bar', $constraint); + + $this->assertNoViolation(); } public function testValidChoiceCallbackFunction() { $constraint = new Choice(array('callback' => __NAMESPACE__.'\choice_callback')); - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('bar', $constraint); + + $this->assertNoViolation(); } public function testValidChoiceCallbackClosure() @@ -109,30 +98,30 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase return array('foo', 'bar'); })); - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('bar', $constraint); + + $this->assertNoViolation(); } public function testValidChoiceCallbackStaticMethod() { $constraint = new Choice(array('callback' => array(__CLASS__, 'staticCallback'))); - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('bar', $constraint); + + $this->assertNoViolation(); } public function testValidChoiceCallbackContextMethod() { + // search $this for "staticCallback" + $this->setObject($this); + $constraint = new Choice(array('callback' => 'staticCallback')); - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('bar', $constraint); + + $this->assertNoViolation(); } public function testMultipleChoices() @@ -142,10 +131,9 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase 'multiple' => true, )); - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(array('baz', 'bar'), $constraint); + + $this->assertNoViolation(); } public function testInvalidChoice() @@ -155,13 +143,11 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => 'baz', - ), null, null); - $this->validator->validate('baz', $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => 'baz', + )); } public function testInvalidChoiceMultiple() @@ -172,13 +158,11 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase 'multiple' => true, )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => 'baz', - )); - $this->validator->validate(array('foo', 'baz'), $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => 'baz', + )); } public function testTooFewChoices() @@ -190,13 +174,15 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase 'minMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ limit }}' => 2, - ), null, 2); + $value = array('foo'); - $this->validator->validate(array('foo'), $constraint); + $this->setValue($value); + + $this->validator->validate($value, $constraint); + + $this->assertViolation('myMessage', array( + '{{ limit }}' => 2, + ), 'property.path', $value, 2); } public function testTooManyChoices() @@ -208,13 +194,15 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase 'maxMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ limit }}' => 2, - ), null, 2); + $value = array('foo', 'bar', 'moo'); - $this->validator->validate(array('foo', 'bar', 'moo'), $constraint); + $this->setValue($value); + + $this->validator->validate($value, $constraint); + + $this->assertViolation('myMessage', array( + '{{ limit }}' => 2, + ), 'property.path', $value, 2); } public function testNonStrict() @@ -224,11 +212,10 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase 'strict' => false, )); - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('2', $constraint); $this->validator->validate(2, $constraint); + + $this->assertNoViolation(); } public function testStrictAllowsExactValue() @@ -238,10 +225,9 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase 'strict' => true, )); - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(2, $constraint); + + $this->assertNoViolation(); } public function testStrictDisallowsDifferentType() @@ -252,13 +238,11 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => '2', - )); - $this->validator->validate('2', $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => '2', + )); } public function testNonStrictWithMultipleChoices() @@ -269,10 +253,9 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase 'strict' => false )); - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(array('2', 3), $constraint); + + $this->assertNoViolation(); } public function testStrictWithMultipleChoices() @@ -284,12 +267,10 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase 'multipleMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => '3', - )); - $this->validator->validate(array(2, '3'), $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => '3', + )); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorCustomArrayObjectTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorCustomArrayObjectTest.php index ebad849b8b..3d4c29681b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorCustomArrayObjectTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorCustomArrayObjectTest.php @@ -11,63 +11,7 @@ namespace Symfony\Component\Validator\Tests\Constraints; -/** - * This class is a hand written simplified version of PHP native `ArrayObject` - * class, to show that it behaves differently than the PHP native implementation. - */ -class CustomArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable -{ - private $array; - - public function __construct(array $array = null) - { - $this->array = $array ?: array(); - } - - public function offsetExists($offset) - { - return array_key_exists($offset, $this->array); - } - - public function offsetGet($offset) - { - return $this->array[$offset]; - } - - public function offsetSet($offset, $value) - { - if (null === $offset) { - $this->array[] = $value; - } else { - $this->array[$offset] = $value; - } - } - - public function offsetUnset($offset) - { - unset($this->array[$offset]); - } - - public function getIterator() - { - return new \ArrayIterator($this->array); - } - - public function count() - { - return count($this->array); - } - - public function serialize() - { - return serialize($this->array); - } - - public function unserialize($serialized) - { - $this->array = (array) unserialize((string) $serialized); - } -} +use Symfony\Component\Validator\Tests\Fixtures\CustomArrayObject; class CollectionValidatorCustomArrayObjectTest extends CollectionValidatorTest { diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php index 4dc5f7e8bc..d4db792c59 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php @@ -17,51 +17,44 @@ use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\Constraints\Optional; use Symfony\Component\Validator\Constraints\Range; use Symfony\Component\Validator\Constraints\Required; +use Symfony\Component\Validator\Validation; -abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase +abstract class CollectionValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new CollectionValidator(); - $this->validator->initialize($this->context); - - $this->context->expects($this->any()) - ->method('getGroup') - ->will($this->returnValue('MyGroup')); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new CollectionValidator(); } abstract protected function prepareTestData(array $contents); public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolationAt'); - $this->validator->validate(null, new Collection(array('fields' => array( 'foo' => new Range(array('min' => 4)), )))); + + $this->assertNoViolation(); } public function testFieldsAsDefaultOption() { + $constraint = new Range(array('min' => 4)); + $data = $this->prepareTestData(array('foo' => 'foobar')); - $this->context->expects($this->never()) - ->method('addViolationAt'); + $this->expectValidateValueAt(0, '[foo]', $data['foo'], array($constraint), 'MyGroup'); $this->validator->validate($data, new Collection(array( - 'foo' => new Range(array('min' => 4)), + 'foo' => $constraint, ))); + + $this->assertNoViolation(); } /** @@ -82,25 +75,23 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase 'foo' => 3, 'bar' => 5, ); - $i = 1; + + $i = 0; foreach ($array as $key => $value) { - $this->context->expects($this->at($i++)) - ->method('validateValue') - ->with($value, $constraint, '['.$key.']', 'MyGroup'); + $this->expectValidateValueAt($i++, '['.$key.']', $value, array($constraint), 'MyGroup'); } $data = $this->prepareTestData($array); - $this->context->expects($this->never()) - ->method('addViolationAt'); - $this->validator->validate($data, new Collection(array( 'fields' => array( 'foo' => $constraint, 'bar' => $constraint, ), ))); + + $this->assertNoViolation(); } public function testWalkMultipleConstraints() @@ -114,48 +105,46 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase 'foo' => 3, 'bar' => 5, ); - $i = 1; + + $i = 0; foreach ($array as $key => $value) { - foreach ($constraints as $constraint) { - $this->context->expects($this->at($i++)) - ->method('validateValue') - ->with($value, $constraint, '['.$key.']', 'MyGroup'); - } + $this->expectValidateValueAt($i++, '['.$key.']', $value, $constraints, 'MyGroup'); } $data = $this->prepareTestData($array); - $this->context->expects($this->never()) - ->method('addViolationAt'); - $this->validator->validate($data, new Collection(array( 'fields' => array( 'foo' => $constraints, 'bar' => $constraints, ) ))); + + $this->assertNoViolation(); } public function testExtraFieldsDisallowed() { + $constraint = new Range(array('min' => 4)); + $data = $this->prepareTestData(array( 'foo' => 5, 'baz' => 6, )); - $this->context->expects($this->once()) - ->method('addViolationAt') - ->with('[baz]', 'myMessage', array( - '{{ field }}' => 'baz' - )); + $this->expectValidateValueAt(0, '[foo]', $data['foo'], array($constraint), 'MyGroup'); $this->validator->validate($data, new Collection(array( 'fields' => array( - 'foo' => new Range(array('min' => 4)), + 'foo' => $constraint, ), 'extraFieldsMessage' => 'myMessage', ))); + + $this->assertViolation('myMessage', array( + '{{ field }}' => 'baz' + ), 'property.path[baz]', 6); } // bug fix @@ -165,16 +154,17 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase 'foo' => null, )); - $constraint = new Collection(array( + $constraint = new Range(array('min' => 4)); + + $this->expectValidateValueAt(0, '[foo]', $data['foo'], array($constraint), 'MyGroup'); + + $this->validator->validate($data, new Collection(array( 'fields' => array( - 'foo' => new Range(array('min' => 4)), + 'foo' => $constraint, ), - )); + ))); - $this->context->expects($this->never()) - ->method('addViolationAt'); - - $this->validator->validate($data, $constraint); + $this->assertNoViolation(); } public function testExtraFieldsAllowed() @@ -184,54 +174,52 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase 'bar' => 6, )); - $constraint = new Collection(array( + $constraint = new Range(array('min' => 4)); + + $this->expectValidateValueAt(0, '[foo]', $data['foo'], array($constraint), 'MyGroup'); + + $this->validator->validate($data, new Collection(array( 'fields' => array( - 'foo' => new Range(array('min' => 4)), + 'foo' => $constraint, ), 'allowExtraFields' => true, - )); + ))); - $this->context->expects($this->never()) - ->method('addViolationAt'); - - $this->validator->validate($data, $constraint); + $this->assertNoViolation(); } public function testMissingFieldsDisallowed() { $data = $this->prepareTestData(array()); - $constraint = new Collection(array( + $constraint = new Range(array('min' => 4)); + + $this->validator->validate($data, new Collection(array( 'fields' => array( - 'foo' => new Range(array('min' => 4)), + 'foo' => $constraint, ), 'missingFieldsMessage' => 'myMessage', - )); + ))); - $this->context->expects($this->once()) - ->method('addViolationAt') - ->with('[foo]', 'myMessage', array( - '{{ field }}' => 'foo', - )); - - $this->validator->validate($data, $constraint); + $this->assertViolation('myMessage', array( + '{{ field }}' => 'foo' + ), 'property.path[foo]', null); } public function testMissingFieldsAllowed() { $data = $this->prepareTestData(array()); - $constraint = new Collection(array( + $constraint = new Range(array('min' => 4)); + + $this->validator->validate($data, new Collection(array( 'fields' => array( - 'foo' => new Range(array('min' => 4)), + 'foo' => $constraint, ), 'allowMissingFields' => true, - )); + ))); - $this->context->expects($this->never()) - ->method('addViolationAt'); - - $this->validator->validate($data, $constraint); + $this->assertNoViolation(); } public function testOptionalFieldPresent() @@ -240,24 +228,22 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase 'foo' => null, )); - $this->context->expects($this->never()) - ->method('addViolationAt'); - $this->validator->validate($data, new Collection(array( 'foo' => new Optional(), ))); + + $this->assertNoViolation(); } public function testOptionalFieldNotPresent() { $data = $this->prepareTestData(array()); - $this->context->expects($this->never()) - ->method('addViolationAt'); - $this->validator->validate($data, new Collection(array( 'foo' => new Optional(), ))); + + $this->assertNoViolation(); } public function testOptionalFieldSingleConstraint() @@ -268,18 +254,15 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase $constraint = new Range(array('min' => 4)); - $this->context->expects($this->once()) - ->method('validateValue') - ->with($array['foo'], $constraint, '[foo]', 'MyGroup'); - - $this->context->expects($this->never()) - ->method('addViolationAt'); + $this->expectValidateValueAt(0, '[foo]', $array['foo'], array($constraint), 'MyGroup'); $data = $this->prepareTestData($array); $this->validator->validate($data, new Collection(array( 'foo' => new Optional($constraint), ))); + + $this->assertNoViolation(); } public function testOptionalFieldMultipleConstraints() @@ -292,22 +275,16 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase new NotNull(), new Range(array('min' => 4)), ); - $i = 1; - foreach ($constraints as $constraint) { - $this->context->expects($this->at($i++)) - ->method('validateValue') - ->with($array['foo'], $constraint, '[foo]', 'MyGroup'); - } - - $this->context->expects($this->never()) - ->method('addViolationAt'); + $this->expectValidateValueAt(0, '[foo]', $array['foo'], $constraints, 'MyGroup'); $data = $this->prepareTestData($array); $this->validator->validate($data, new Collection(array( 'foo' => new Optional($constraints), ))); + + $this->assertNoViolation(); } public function testRequiredFieldPresent() @@ -316,30 +293,28 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase 'foo' => null, )); - $this->context->expects($this->never()) - ->method('addViolationAt'); - $this->validator->validate($data, new Collection(array( 'foo' => new Required(), ))); + + $this->assertNoViolation(); } public function testRequiredFieldNotPresent() { $data = $this->prepareTestData(array()); - $this->context->expects($this->once()) - ->method('addViolationAt') - ->with('[foo]', 'myMessage', array( - '{{ field }}' => 'foo', - )); - $this->validator->validate($data, new Collection(array( 'fields' => array( 'foo' => new Required(), ), 'missingFieldsMessage' => 'myMessage', ))); + + + $this->assertViolation('myMessage', array( + '{{ field }}' => 'foo' + ), 'property.path[foo]', null); } public function testRequiredFieldSingleConstraint() @@ -350,18 +325,15 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase $constraint = new Range(array('min' => 4)); - $this->context->expects($this->once()) - ->method('validateValue') - ->with($array['foo'], $constraint, '[foo]', 'MyGroup'); - - $this->context->expects($this->never()) - ->method('addViolationAt'); + $this->expectValidateValueAt(0, '[foo]', $array['foo'], array($constraint), 'MyGroup'); $data = $this->prepareTestData($array); $this->validator->validate($data, new Collection(array( 'foo' => new Required($constraint), ))); + + $this->assertNoViolation(); } public function testRequiredFieldMultipleConstraints() @@ -374,22 +346,16 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase new NotNull(), new Range(array('min' => 4)), ); - $i = 1; - foreach ($constraints as $constraint) { - $this->context->expects($this->at($i++)) - ->method('validateValue') - ->with($array['foo'], $constraint, '[foo]', 'MyGroup'); - } - - $this->context->expects($this->never()) - ->method('addViolationAt'); + $this->expectValidateValueAt(0, '[foo]', $array['foo'], $constraints, 'MyGroup'); $data = $this->prepareTestData($array); - $this->validator->validate($array, new Collection(array( + $this->validator->validate($data, new Collection(array( 'foo' => new Required($constraints), ))); + + $this->assertNoViolation(); } public function testObjectShouldBeLeftUnchanged() @@ -398,9 +364,13 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase 'foo' => 3 )); + $constraint = new Range(array('min' => 2)); + + $this->expectValidateValueAt(0, '[foo]', $value['foo'], array($constraint), 'MyGroup'); + $this->validator->validate($value, new Collection(array( 'fields' => array( - 'foo' => new Range(array('min' => 2)), + 'foo' => $constraint, ) ))); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorCountableTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorCountableTest.php index ec4d8dec71..7d46967bde 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorCountableTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorCountableTest.php @@ -11,20 +11,7 @@ namespace Symfony\Component\Validator\Tests\Constraints; -class CountValidatorCountableTest_Countable implements \Countable -{ - private $content; - - public function __construct(array $content) - { - $this->content = $content; - } - - public function count() - { - return count($this->content); - } -} +use Symfony\Component\Validator\Tests\Fixtures\Countable; /** * @author Bernhard Schussek @@ -33,6 +20,6 @@ class CountValidatorCountableTest extends CountValidatorTest { protected function createCollection(array $content) { - return new CountValidatorCountableTest_Countable($content); + return new Countable($content); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php index 9c4a38d56c..4ebf4fa9a6 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php @@ -13,36 +13,30 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Count; use Symfony\Component\Validator\Constraints\CountValidator; +use Symfony\Component\Validator\Validation; /** * @author Bernhard Schussek */ -abstract class CountValidatorTest extends \PHPUnit_Framework_TestCase +abstract class CountValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new CountValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new CountValidator(); } abstract protected function createCollection(array $content); public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Count(6)); + + $this->assertNoViolation(); } /** @@ -93,11 +87,10 @@ abstract class CountValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidValuesMax($value) { - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new Count(array('max' => 3)); $this->validator->validate($value, $constraint); + + $this->assertNoViolation(); } /** @@ -105,11 +98,10 @@ abstract class CountValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidValuesMin($value) { - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new Count(array('min' => 5)); $this->validator->validate($value, $constraint); + + $this->assertNoViolation(); } /** @@ -117,11 +109,10 @@ abstract class CountValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidValuesExact($value) { - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new Count(4); $this->validator->validate($value, $constraint); + + $this->assertNoViolation(); } /** @@ -134,14 +125,12 @@ abstract class CountValidatorTest extends \PHPUnit_Framework_TestCase 'maxMessage' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', $this->identicalTo(array( - '{{ count }}' => count($value), - '{{ limit }}' => 4, - )), $value, 4); - $this->validator->validate($value, $constraint); + + $this->assertViolation('myMessage', array( + '{{ count }}' => count($value), + '{{ limit }}' => 4, + ), 'property.path', $value, 4); } /** @@ -154,14 +143,12 @@ abstract class CountValidatorTest extends \PHPUnit_Framework_TestCase 'minMessage' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', $this->identicalTo(array( - '{{ count }}' => count($value), - '{{ limit }}' => 4, - )), $value, 4); - $this->validator->validate($value, $constraint); + + $this->assertViolation('myMessage', array( + '{{ count }}' => count($value), + '{{ limit }}' => 4, + ), 'property.path', $value, 4); } /** @@ -175,14 +162,12 @@ abstract class CountValidatorTest extends \PHPUnit_Framework_TestCase 'exactMessage' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', $this->identicalTo(array( + $this->validator->validate($value, $constraint); + + $this->assertViolation('myMessage', array( '{{ count }}' => count($value), '{{ limit }}' => 4, - )), $value, 4); - - $this->validator->validate($value, $constraint); + ), 'property.path', $value, 4); } public function testDefaultOption() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php index 954fdb845e..4bfba87dac 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php @@ -14,41 +14,39 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Intl\Util\IntlTestHelper; use Symfony\Component\Validator\Constraints\Country; use Symfony\Component\Validator\Constraints\CountryValidator; +use Symfony\Component\Validator\Validation; -class CountryValidatorTest extends \PHPUnit_Framework_TestCase +class CountryValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - protected function setUp() { IntlTestHelper::requireFullIntl($this); - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new CountryValidator(); - $this->validator->initialize($this->context); + parent::setUp(); } - protected function tearDown() + protected function getApiVersion() { - $this->context = null; - $this->validator = null; + return Validation::API_VERSION_2_5; + } + + protected function createValidator() + { + return new CountryValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Country()); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Country()); + + $this->assertNoViolation(); } /** @@ -64,10 +62,9 @@ class CountryValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidCountries($country) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($country, new Country()); + + $this->assertNoViolation(); } public function getValidCountries() @@ -88,13 +85,11 @@ class CountryValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $country, - )); - $this->validator->validate($country, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $country, + )); } public function getInvalidCountries() @@ -113,9 +108,9 @@ class CountryValidatorTest extends \PHPUnit_Framework_TestCase \Locale::setDefault('en_GB'); $existingCountry = 'GB'; - $this->context->expects($this->never()) - ->method('addViolation'); $this->validator->validate($existingCountry, new Country()); + + $this->assertNoViolation(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php index 00b200e1e9..a7e15ef876 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php @@ -14,41 +14,39 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Intl\Util\IntlTestHelper; use Symfony\Component\Validator\Constraints\Currency; use Symfony\Component\Validator\Constraints\CurrencyValidator; +use Symfony\Component\Validator\Validation; -class CurrencyValidatorTest extends \PHPUnit_Framework_TestCase +class CurrencyValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - protected function setUp() { IntlTestHelper::requireFullIntl($this); - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new CurrencyValidator(); - $this->validator->initialize($this->context); + parent::setUp(); } - protected function tearDown() + protected function getApiVersion() { - $this->context = null; - $this->validator = null; + return Validation::API_VERSION_2_5; + } + + protected function createValidator() + { + return new CurrencyValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Currency()); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Currency()); + + $this->assertNoViolation(); } /** @@ -64,10 +62,9 @@ class CurrencyValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidCurrencies($currency) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($currency, new Currency()); + + $this->assertNoViolation(); } /** @@ -76,10 +73,10 @@ class CurrencyValidatorTest extends \PHPUnit_Framework_TestCase public function testValidCurrenciesWithCountrySpecificLocale($currency) { \Locale::setDefault('en_GB'); - $this->context->expects($this->never()) - ->method('addViolation'); $this->validator->validate($currency, new Currency()); + + $this->assertNoViolation(); } public function getValidCurrencies() @@ -102,13 +99,11 @@ class CurrencyValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $currency, - )); - $this->validator->validate($currency, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $currency, + )); } public function getInvalidCurrencies() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php index 0776848fdb..29201890d7 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php @@ -13,47 +13,39 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\DateTime; use Symfony\Component\Validator\Constraints\DateTimeValidator; +use Symfony\Component\Validator\Validation; -class DateTimeValidatorTest extends \PHPUnit_Framework_TestCase +class DateTimeValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new DateTimeValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new DateTimeValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new DateTime()); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new DateTime()); + + $this->assertNoViolation(); } public function testDateTimeClassIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(new \DateTime(), new DateTime()); + + $this->assertNoViolation(); } /** @@ -69,10 +61,9 @@ class DateTimeValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidDateTimes($dateTime) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($dateTime, new DateTime()); + + $this->assertNoViolation(); } public function getValidDateTimes() @@ -93,13 +84,11 @@ class DateTimeValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $dateTime, - )); - $this->validator->validate($dateTime, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $dateTime, + )); } public function getInvalidDateTimes() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php index b9cf8816b7..3766c6fd87 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php @@ -13,47 +13,39 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Date; use Symfony\Component\Validator\Constraints\DateValidator; +use Symfony\Component\Validator\Validation; -class DateValidatorTest extends \PHPUnit_Framework_TestCase +class DateValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new DateValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new DateValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Date()); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Date()); + + $this->assertNoViolation(); } public function testDateTimeClassIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(new \DateTime(), new Date()); + + $this->assertNoViolation(); } /** @@ -69,10 +61,9 @@ class DateValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidDates($date) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($date, new Date()); + + $this->assertNoViolation(); } public function getValidDates() @@ -93,13 +84,11 @@ class DateValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $date, - )); - $this->validator->validate($date, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $date, + )); } public function getInvalidDates() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php index 27c142f615..95756f5061 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php @@ -13,39 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Email; use Symfony\Component\Validator\Constraints\EmailValidator; +use Symfony\Component\Validator\Validation; -class EmailValidatorTest extends \PHPUnit_Framework_TestCase +class EmailValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new EmailValidator(false); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new EmailValidator(false); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Email()); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Email()); + + $this->assertNoViolation(); } /** @@ -61,10 +54,9 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidEmails($email) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($email, new Email()); + + $this->assertNoViolation(); } public function getValidEmails() @@ -85,13 +77,11 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $email, - )); - $this->validator->validate($email, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $email, + )); } public function getInvalidEmails() @@ -105,9 +95,10 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase public function testStrict() { - $this->context->expects($this->never()) - ->method('addViolation'); + $constraint = new Email(array('strict' => true)); - $this->validator->validate('example@localhost', new Email(array('strict' => true))); + $this->validator->validate('example@localhost', $constraint); + + $this->assertNoViolation(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php index 46b1b56269..0b7a983231 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php @@ -13,12 +13,18 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\EqualTo; use Symfony\Component\Validator\Constraints\EqualToValidator; +use Symfony\Component\Validator\Validation; /** * @author Daniel Holmes */ class EqualToValidatorTest extends AbstractComparisonValidatorTestCase { + protected function getApiVersion() + { + return Validation::API_VERSION_2_5; + } + protected function createValidator() { return new EqualToValidator(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php index b71138e5f6..a19bc502b4 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php @@ -14,184 +14,139 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\Validator\Constraints\Expression; use Symfony\Component\Validator\Constraints\ExpressionValidator; +use Symfony\Component\Validator\Tests\Fixtures\Entity; +use Symfony\Component\Validator\Validation; -class ExpressionValidatorTest extends \PHPUnit_Framework_TestCase +class ExpressionValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new ExpressionValidator(PropertyAccess::createPropertyAccessor()); - $this->validator->initialize($this->context); - - $this->context->expects($this->any()) - ->method('getClassName') - ->will($this->returnValue(__CLASS__)); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new ExpressionValidator(PropertyAccess::createPropertyAccessor()); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Expression('value == 1')); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Expression('value == 1')); + + $this->assertNoViolation(); } public function testSucceedingExpressionAtObjectLevel() { - $constraint = new Expression('this.property == 1'); + $constraint = new Expression('this.data == 1'); - $object = (object) array('property' => '1'); + $object = new Entity(); + $object->data = '1'; - $this->context->expects($this->any()) - ->method('getPropertyName') - ->will($this->returnValue(null)); - - $this->context->expects($this->never()) - ->method('addViolation'); + $this->setObject($object); $this->validator->validate($object, $constraint); + + $this->assertNoViolation(); } public function testFailingExpressionAtObjectLevel() { $constraint = new Expression(array( - 'expression' => 'this.property == 1', + 'expression' => 'this.data == 1', 'message' => 'myMessage', )); - $object = (object) array('property' => '2'); + $object = new Entity(); + $object->data = '2'; - $this->context->expects($this->any()) - ->method('getPropertyName') - ->will($this->returnValue(null)); - - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage'); + $this->setObject($object); $this->validator->validate($object, $constraint); + + $this->assertViolation('myMessage'); } public function testSucceedingExpressionAtPropertyLevel() { - $constraint = new Expression('value == this.expected'); + $constraint = new Expression('value == this.data'); - $object = (object) array('expected' => '1'); + $object = new Entity(); + $object->data = '1'; - $this->context->expects($this->any()) - ->method('getPropertyName') - ->will($this->returnValue('property')); - - $this->context->expects($this->any()) - ->method('getPropertyPath') - ->will($this->returnValue('property')); - - $this->context->expects($this->any()) - ->method('getRoot') - ->will($this->returnValue($object)); - - $this->context->expects($this->never()) - ->method('addViolation'); + $this->setRoot($object); + $this->setPropertyPath('data'); + $this->setProperty($object, 'data'); $this->validator->validate('1', $constraint); + + $this->assertNoViolation(); } public function testFailingExpressionAtPropertyLevel() { $constraint = new Expression(array( - 'expression' => 'value == this.expected', + 'expression' => 'value == this.data', 'message' => 'myMessage', )); - $object = (object) array('expected' => '1'); + $object = new Entity(); + $object->data = '1'; - $this->context->expects($this->any()) - ->method('getPropertyName') - ->will($this->returnValue('property')); - - $this->context->expects($this->any()) - ->method('getPropertyPath') - ->will($this->returnValue('property')); - - $this->context->expects($this->any()) - ->method('getRoot') - ->will($this->returnValue($object)); - - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage'); + $this->setRoot($object); + $this->setPropertyPath('data'); + $this->setProperty($object, 'data'); $this->validator->validate('2', $constraint); + + $this->assertViolation('myMessage', array(), 'data'); } public function testSucceedingExpressionAtNestedPropertyLevel() { - $constraint = new Expression('value == this.expected'); + $constraint = new Expression('value == this.data'); - $object = (object) array('expected' => '1'); - $root = (object) array('nested' => $object); + $object = new Entity(); + $object->data = '1'; - $this->context->expects($this->any()) - ->method('getPropertyName') - ->will($this->returnValue('property')); + $root = new Entity(); + $root->reference = $object; - $this->context->expects($this->any()) - ->method('getPropertyPath') - ->will($this->returnValue('nested.property')); - - $this->context->expects($this->any()) - ->method('getRoot') - ->will($this->returnValue($root)); - - $this->context->expects($this->never()) - ->method('addViolation'); + $this->setRoot($root); + $this->setPropertyPath('reference.data'); + $this->setProperty($object, 'data'); $this->validator->validate('1', $constraint); + + $this->assertNoViolation(); } public function testFailingExpressionAtNestedPropertyLevel() { $constraint = new Expression(array( - 'expression' => 'value == this.expected', + 'expression' => 'value == this.data', 'message' => 'myMessage', )); - $object = (object) array('expected' => '1'); - $root = (object) array('nested' => $object); + $object = new Entity(); + $object->data = '1'; - $this->context->expects($this->any()) - ->method('getPropertyName') - ->will($this->returnValue('property')); + $root = new Entity(); + $root->reference = $object; - $this->context->expects($this->any()) - ->method('getPropertyPath') - ->will($this->returnValue('nested.property')); - - $this->context->expects($this->any()) - ->method('getRoot') - ->will($this->returnValue($root)); - - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage'); + $this->setRoot($root); + $this->setPropertyPath('reference.data'); + $this->setProperty($object, 'data'); $this->validator->validate('2', $constraint); + + $this->assertViolation('myMessage', array(), 'reference.data'); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FalseValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FalseValidatorTest.php index 1bc16c20bd..c770579473 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FalseValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FalseValidatorTest.php @@ -13,39 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\False; use Symfony\Component\Validator\Constraints\FalseValidator; +use Symfony\Component\Validator\Validation; -class FalseValidatorTest extends \PHPUnit_Framework_TestCase +class FalseValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new FalseValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new FalseValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new False()); + + $this->assertNoViolation(); } public function testFalseIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(false, new False()); + + $this->assertNoViolation(); } public function testTrueIsInvalid() @@ -54,10 +47,8 @@ class FalseValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array()); - $this->validator->validate(true, $constraint); + + $this->assertViolation('myMessage'); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php index c4b93cdcd3..36a5bbc012 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php @@ -26,12 +26,10 @@ class FileValidatorPathTest extends FileValidatorTest 'notFoundMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ file }}' => 'foobar', - )); - $this->validator->validate('foobar', $constraint); + + $this->assertViolation('myMessage', array( + '{{ file }}' => 'foobar', + )); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php index 8b9ce99b80..1e28c89136 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php @@ -14,25 +14,36 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\Validator\Constraints\File; use Symfony\Component\Validator\Constraints\FileValidator; +use Symfony\Component\Validator\Validation; -abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase +abstract class FileValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; protected $path; + protected $file; + protected function getApiVersion() + { + return Validation::API_VERSION_2_5; + } + + protected function createValidator() + { + return new FileValidator(); + } + protected function setUp() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new FileValidator(); - $this->validator->initialize($this->context); + parent::setUp(); + $this->path = sys_get_temp_dir().DIRECTORY_SEPARATOR.'FileValidatorTest'; $this->file = fopen($this->path, 'w'); } protected function tearDown() { + parent::tearDown(); + if (is_resource($this->file)) { fclose($this->file); } @@ -41,26 +52,22 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase unlink($this->path); } - $this->context = null; - $this->validator = null; $this->path = null; $this->file = null; } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new File()); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new File()); + + $this->assertNoViolation(); } /** @@ -73,19 +80,17 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase public function testValidFile() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($this->path, new File()); + + $this->assertNoViolation(); } public function testValidUploadedfile() { - $this->context->expects($this->never()) - ->method('addViolation'); - $file = new UploadedFile($this->path, 'originalName', null, null, null, true); $this->validator->validate($file, new File()); + + $this->assertNoViolation(); } public function provideMaxSizeExceededTests() @@ -137,16 +142,14 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase 'maxSizeMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ limit }}' => $limitAsString, - '{{ size }}' => $sizeAsString, - '{{ suffix }}' => $suffix, - '{{ file }}' => $this->path, - )); - $this->validator->validate($this->getFile($this->path), $constraint); + + $this->assertViolation('myMessage', array( + '{{ limit }}' => $limitAsString, + '{{ size }}' => $sizeAsString, + '{{ suffix }}' => $suffix, + '{{ file }}' => $this->path, + )); } public function provideMaxSizeNotExceededTests() @@ -177,10 +180,9 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase 'maxSizeMessage' => 'myMessage', )); - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($this->getFile($this->path), $constraint); + + $this->assertNoViolation(); } /** @@ -213,14 +215,13 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue('image/jpg')) ; - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new File(array( 'mimeTypes' => array('image/png', 'image/jpg'), )); $this->validator->validate($file, $constraint); + + $this->assertNoViolation(); } public function testValidWildcardMimeType() @@ -241,14 +242,13 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue('image/jpg')) ; - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new File(array( 'mimeTypes' => array('image/*'), )); $this->validator->validate($file, $constraint); + + $this->assertNoViolation(); } public function testInvalidMimeType() @@ -274,15 +274,13 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase 'mimeTypesMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ type }}' => '"application/pdf"', - '{{ types }}' => '"image/png", "image/jpg"', - '{{ file }}' => $this->path, - )); - $this->validator->validate($file, $constraint); + + $this->assertViolation('myMessage', array( + '{{ type }}' => '"application/pdf"', + '{{ types }}' => '"image/png", "image/jpg"', + '{{ file }}' => $this->path, + )); } public function testInvalidWildcardMimeType() @@ -308,15 +306,13 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase 'mimeTypesMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ type }}' => '"application/pdf"', - '{{ types }}' => '"image/*", "image/jpg"', - '{{ file }}' => $this->path, - )); - $this->validator->validate($file, $constraint); + + $this->assertViolation('myMessage', array( + '{{ type }}' => '"application/pdf"', + '{{ types }}' => '"image/*", "image/jpg"', + '{{ file }}' => $this->path, + )); } /** @@ -331,12 +327,10 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase 'maxSize' => $maxSize )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', $params); - $this->validator->validate($file, $constraint); + $this->assertViolation('myMessage', $params); + } public function uploadedFileErrorProvider() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php index 9393bec619..893debf154 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php @@ -13,12 +13,18 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; use Symfony\Component\Validator\Constraints\GreaterThanOrEqualValidator; +use Symfony\Component\Validator\Validation; /** * @author Daniel Holmes */ class GreaterThanOrEqualValidatorTest extends AbstractComparisonValidatorTestCase { + protected function getApiVersion() + { + return Validation::API_VERSION_2_5; + } + protected function createValidator() { return new GreaterThanOrEqualValidator(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php index c9db80f78f..0c43a33007 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php @@ -13,12 +13,18 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\GreaterThan; use Symfony\Component\Validator\Constraints\GreaterThanValidator; +use Symfony\Component\Validator\Validation; /** * @author Daniel Holmes */ class GreaterThanValidatorTest extends AbstractComparisonValidatorTestCase { + protected function getApiVersion() + { + return Validation::API_VERSION_2_5; + } + protected function createValidator() { return new GreaterThanValidator(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php index 60ba94c32c..3c78981f73 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php @@ -13,31 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Iban; use Symfony\Component\Validator\Constraints\IbanValidator; +use Symfony\Component\Validator\Validation; -class IbanValidatorTest extends \PHPUnit_Framework_TestCase +class IbanValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new IbanValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; + } + + protected function createValidator() + { + return new IbanValidator(); } public function testNullIsValid() { - $this->context->expects($this->never())->method('addViolation'); - $this->validator->validate(null, new Iban()); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never())->method('addViolation'); - $this->validator->validate('', new Iban()); + + $this->assertNoViolation(); } /** @@ -45,9 +46,9 @@ class IbanValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidIbans($iban) { - $this->context->expects($this->never())->method('addViolation'); - $this->validator->validate($iban, new Iban()); + + $this->assertNoViolation(); } public function getValidIbans() @@ -160,13 +161,11 @@ class IbanValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $iban, - )); - $this->validator->validate($iban, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $iban, + )); } public function getInvalidIbans() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php index c5267f1820..e2414806f5 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php @@ -13,12 +13,18 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\IdenticalTo; use Symfony\Component\Validator\Constraints\IdenticalToValidator; +use Symfony\Component\Validator\Validation; /** * @author Daniel Holmes */ class IdenticalToValidatorTest extends AbstractComparisonValidatorTestCase { + protected function getApiVersion() + { + return Validation::API_VERSION_2_5; + } + protected function createValidator() { return new IdenticalToValidator(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php index 114c2d2f04..7b6aaa7e40 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php @@ -13,8 +13,9 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Image; use Symfony\Component\Validator\Constraints\ImageValidator; +use Symfony\Component\Validator\Validation; -class ImageValidatorTest extends \PHPUnit_Framework_TestCase +class ImageValidatorTest extends AbstractConstraintValidatorTest { protected $context; protected $validator; @@ -23,11 +24,20 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase protected $imageLandscape; protected $imagePortrait; + protected function getApiVersion() + { + return Validation::API_VERSION_2_5; + } + + protected function createValidator() + { + return new ImageValidator(); + } + protected function setUp() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new ImageValidator(); - $this->validator->initialize($this->context); + parent::setUp(); + $this->image = __DIR__.'/Fixtures/test.gif'; $this->imageLandscape = __DIR__.'/Fixtures/test_landscape.gif'; $this->imagePortrait = __DIR__.'/Fixtures/test_portrait.gif'; @@ -35,33 +45,27 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Image()); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Image()); + + $this->assertNoViolation(); } public function testValidImage() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($this->image, new Image()); + + $this->assertNoViolation(); } public function testValidSize() { - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new Image(array( 'minWidth' => 1, 'maxWidth' => 2, @@ -70,6 +74,8 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase )); $this->validator->validate($this->image, $constraint); + + $this->assertNoViolation(); } public function testWidthTooSmall() @@ -79,14 +85,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase 'minWidthMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ width }}' => '2', - '{{ min_width }}' => '3', - )); - $this->validator->validate($this->image, $constraint); + + $this->assertViolation('myMessage', array( + '{{ width }}' => '2', + '{{ min_width }}' => '3', + )); } public function testWidthTooBig() @@ -96,14 +100,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase 'maxWidthMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ width }}' => '2', - '{{ max_width }}' => '1', - )); - $this->validator->validate($this->image, $constraint); + + $this->assertViolation('myMessage', array( + '{{ width }}' => '2', + '{{ max_width }}' => '1', + )); } public function testHeightTooSmall() @@ -113,14 +115,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase 'minHeightMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ height }}' => '2', - '{{ min_height }}' => '3', - )); - $this->validator->validate($this->image, $constraint); + + $this->assertViolation('myMessage', array( + '{{ height }}' => '2', + '{{ min_height }}' => '3', + )); } public function testHeightTooBig() @@ -130,14 +130,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase 'maxHeightMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ height }}' => '2', - '{{ max_height }}' => '1', - )); - $this->validator->validate($this->image, $constraint); + + $this->assertViolation('myMessage', array( + '{{ height }}' => '2', + '{{ max_height }}' => '1', + )); } /** @@ -195,14 +193,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase 'minRatioMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ ratio }}' => 1, - '{{ min_ratio }}' => 2, - )); - $this->validator->validate($this->image, $constraint); + + $this->assertViolation('myMessage', array( + '{{ ratio }}' => 1, + '{{ min_ratio }}' => 2, + )); } public function testRatioTooBig() @@ -212,14 +208,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase 'maxRatioMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ ratio }}' => 1, - '{{ max_ratio }}' => 0.5, - )); - $this->validator->validate($this->image, $constraint); + + $this->assertViolation('myMessage', array( + '{{ ratio }}' => 1, + '{{ max_ratio }}' => 0.5, + )); } /** @@ -253,14 +247,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase 'allowSquareMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ width }}' => 2, - '{{ height }}' => 2, - )); - $this->validator->validate($this->image, $constraint); + + $this->assertViolation('myMessage', array( + '{{ width }}' => 2, + '{{ height }}' => 2, + )); } public function testLandscapeNotAllowed() @@ -270,14 +262,12 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase 'allowLandscapeMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ width }}' => 2, - '{{ height }}' => 1, - )); - $this->validator->validate($this->imageLandscape, $constraint); + + $this->assertViolation('myMessage', array( + '{{ width }}' => 2, + '{{ height }}' => 1, + )); } public function testPortraitNotAllowed() @@ -287,13 +277,11 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase 'allowPortraitMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ width }}' => 1, - '{{ height }}' => 2, - )); - $this->validator->validate($this->imagePortrait, $constraint); + + $this->assertViolation('myMessage', array( + '{{ width }}' => 1, + '{{ height }}' => 2, + )); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php index bdf6192880..1bd22598db 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php @@ -13,39 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Ip; use Symfony\Component\Validator\Constraints\IpValidator; +use Symfony\Component\Validator\Validation; -class IpValidatorTest extends \PHPUnit_Framework_TestCase +class IpValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new IpValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new IpValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Ip()); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Ip()); + + $this->assertNoViolation(); } /** @@ -61,7 +54,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase */ public function testInvalidValidatorVersion() { - $ip = new Ip(array( + new Ip(array( 'version' => 666, )); } @@ -71,12 +64,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidIpsV4($ip) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($ip, new Ip(array( 'version' => Ip::V4, ))); + + $this->assertNoViolation(); } public function getValidIpsV4() @@ -98,12 +90,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidIpsV6($ip) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($ip, new Ip(array( 'version' => Ip::V6, ))); + + $this->assertNoViolation(); } public function getValidIpsV6() @@ -136,12 +127,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidIpsAll($ip) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($ip, new Ip(array( 'version' => Ip::ALL, ))); + + $this->assertNoViolation(); } public function getValidIpsAll() @@ -159,13 +149,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $ip, - )); - $this->validator->validate($ip, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $ip, + )); } public function getInvalidIpsV4() @@ -193,13 +181,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $ip, - )); - $this->validator->validate($ip, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $ip, + )); } public function getInvalidPrivateIpsV4() @@ -221,13 +207,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $ip, - )); - $this->validator->validate($ip, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $ip, + )); } public function getInvalidReservedIpsV4() @@ -249,13 +233,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $ip, - )); - $this->validator->validate($ip, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $ip, + )); } public function getInvalidPublicIpsV4() @@ -273,13 +255,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $ip, - )); - $this->validator->validate($ip, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $ip, + )); } public function getInvalidIpsV6() @@ -311,13 +291,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $ip, - )); - $this->validator->validate($ip, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $ip, + )); } public function getInvalidPrivateIpsV6() @@ -339,13 +317,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $ip, - )); - $this->validator->validate($ip, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $ip, + )); } public function getInvalidReservedIpsV6() @@ -366,13 +342,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $ip, - )); - $this->validator->validate($ip, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $ip, + )); } public function getInvalidPublicIpsV6() @@ -390,13 +364,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $ip, - )); - $this->validator->validate($ip, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $ip, + )); } public function getInvalidIpsAll() @@ -414,13 +386,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $ip, - )); - $this->validator->validate($ip, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $ip, + )); } public function getInvalidPrivateIpsAll() @@ -438,13 +408,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $ip, - )); - $this->validator->validate($ip, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $ip, + )); } public function getInvalidReservedIpsAll() @@ -462,13 +430,11 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $ip, - )); - $this->validator->validate($ip, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $ip, + )); } public function getInvalidPublicIpsAll() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IsbnValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IsbnValidatorTest.php index feb2234fde..ff4f1ba708 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IsbnValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IsbnValidatorTest.php @@ -13,20 +13,21 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Isbn; use Symfony\Component\Validator\Constraints\IsbnValidator; +use Symfony\Component\Validator\Validation; /** * @see https://en.wikipedia.org/wiki/Isbn */ -class IsbnValidatorTest extends \PHPUnit_Framework_TestCase +class IsbnValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - public function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new IsbnValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; + } + + protected function createValidator() + { + return new IsbnValidator(); } public function getValidIsbn10() @@ -116,21 +117,19 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase public function testNullIsValid() { $constraint = new Isbn(true); - $this->context - ->expects($this->never()) - ->method('addViolation'); $this->validator->validate(null, $constraint); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { $constraint = new Isbn(true); - $this->context - ->expects($this->never()) - ->method('addViolation'); $this->validator->validate('', $constraint); + + $this->assertNoViolation(); } /** @@ -139,6 +138,7 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase public function testExpectsStringCompatibleType() { $constraint = new Isbn(true); + $this->validator->validate(new \stdClass(), $constraint); } @@ -147,12 +147,13 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidIsbn10($isbn) { - $constraint = new Isbn(array('type' => 'isbn10')); - $this->context - ->expects($this->never()) - ->method('addViolation'); + $constraint = new Isbn(array( + 'type' => 'isbn10' + )); $this->validator->validate($isbn, $constraint); + + $this->assertNoViolation(); } /** @@ -160,13 +161,14 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase */ public function testInvalidIsbn10($isbn) { - $constraint = new Isbn(array('type' => 'isbn10')); - $this->context - ->expects($this->once()) - ->method('addViolation') - ->with($constraint->isbn10Message); + $constraint = new Isbn(array( + 'type' => 'isbn10', + 'isbn10Message' => 'myMessage', + )); $this->validator->validate($isbn, $constraint); + + $this->assertViolation('myMessage'); } /** @@ -175,11 +177,10 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase public function testValidIsbn13($isbn) { $constraint = new Isbn(array('type' => 'isbn13')); - $this->context - ->expects($this->never()) - ->method('addViolation'); $this->validator->validate($isbn, $constraint); + + $this->assertNoViolation(); } /** @@ -187,13 +188,14 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase */ public function testInvalidIsbn13($isbn) { - $constraint = new Isbn(array('type' => 'isbn13')); - $this->context - ->expects($this->once()) - ->method('addViolation') - ->with($constraint->isbn13Message); + $constraint = new Isbn(array( + 'type' => 'isbn13', + 'isbn13Message' => 'myMessage', + )); $this->validator->validate($isbn, $constraint); + + $this->assertViolation('myMessage'); } /** @@ -202,11 +204,10 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase public function testValidIsbn($isbn) { $constraint = new Isbn(); - $this->context - ->expects($this->never()) - ->method('addViolation'); $this->validator->validate($isbn, $constraint); + + $this->assertNoViolation(); } /** @@ -214,12 +215,12 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase */ public function testInvalidIsbn($isbn) { - $constraint = new Isbn(); - $this->context - ->expects($this->once()) - ->method('addViolation') - ->with($constraint->bothIsbnMessage); + $constraint = new Isbn(array( + 'bothIsbnMessage' => 'myMessage', + )); $this->validator->validate($isbn, $constraint); + + $this->assertViolation('myMessage'); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IssnValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IssnValidatorTest.php index 3f53e738b3..495a3a609f 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IssnValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IssnValidatorTest.php @@ -13,20 +13,21 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Issn; use Symfony\Component\Validator\Constraints\IssnValidator; +use Symfony\Component\Validator\Validation; /** * @see https://en.wikipedia.org/wiki/Issn */ -class IssnValidatorTest extends \PHPUnit_Framework_TestCase +class IssnValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - public function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new IssnValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; + } + + protected function createValidator() + { + return new IssnValidator(); } public function getValidLowerCasedIssn() @@ -110,21 +111,19 @@ class IssnValidatorTest extends \PHPUnit_Framework_TestCase public function testNullIsValid() { $constraint = new Issn(); - $this->context - ->expects($this->never()) - ->method('addViolation'); $this->validator->validate(null, $constraint); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { $constraint = new Issn(); - $this->context - ->expects($this->never()) - ->method('addViolation'); $this->validator->validate('', $constraint); + + $this->assertNoViolation(); } /** @@ -141,13 +140,14 @@ class IssnValidatorTest extends \PHPUnit_Framework_TestCase */ public function testCaseSensitiveIssns($issn) { - $constraint = new Issn(array('caseSensitive' => true)); - $this->context - ->expects($this->once()) - ->method('addViolation') - ->with($constraint->message); + $constraint = new Issn(array( + 'caseSensitive' => true, + 'message' => 'myMessage', + )); $this->validator->validate($issn, $constraint); + + $this->assertViolation('myMessage'); } /** @@ -155,13 +155,14 @@ class IssnValidatorTest extends \PHPUnit_Framework_TestCase */ public function testRequireHyphenIssns($issn) { - $constraint = new Issn(array('requireHyphen' => true)); - $this->context - ->expects($this->once()) - ->method('addViolation') - ->with($constraint->message); + $constraint = new Issn(array( + 'requireHyphen' => true, + 'message' => 'myMessage', + )); $this->validator->validate($issn, $constraint); + + $this->assertViolation('myMessage'); } /** @@ -170,11 +171,10 @@ class IssnValidatorTest extends \PHPUnit_Framework_TestCase public function testValidIssn($issn) { $constraint = new Issn(); - $this->context - ->expects($this->never()) - ->method('addViolation'); $this->validator->validate($issn, $constraint); + + $this->assertNoViolation(); } /** @@ -182,13 +182,13 @@ class IssnValidatorTest extends \PHPUnit_Framework_TestCase */ public function testInvalidFormatIssn($issn) { - $constraint = new Issn(); - $this->context - ->expects($this->once()) - ->method('addViolation') - ->with($constraint->message); + $constraint = new Issn(array( + 'message' => 'myMessage', + )); $this->validator->validate($issn, $constraint); + + $this->assertViolation('myMessage'); } /** @@ -196,13 +196,13 @@ class IssnValidatorTest extends \PHPUnit_Framework_TestCase */ public function testInvalidValueIssn($issn) { - $constraint = new Issn(); - $this->context - ->expects($this->once()) - ->method('addViolation') - ->with($constraint->message); + $constraint = new Issn(array( + 'message' => 'myMessage', + )); $this->validator->validate($issn, $constraint); + + $this->assertViolation('myMessage'); } /** @@ -210,11 +210,12 @@ class IssnValidatorTest extends \PHPUnit_Framework_TestCase */ public function testInvalidIssn($issn) { - $constraint = new Issn(); - $this->context - ->expects($this->once()) - ->method('addViolation'); + $constraint = new Issn(array( + 'message' => 'myMessage', + )); $this->validator->validate($issn, $constraint); + + $this->assertViolation('myMessage'); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php index af5a05fbcc..22652e777b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php @@ -14,41 +14,39 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Intl\Util\IntlTestHelper; use Symfony\Component\Validator\Constraints\Language; use Symfony\Component\Validator\Constraints\LanguageValidator; +use Symfony\Component\Validator\Validation; -class LanguageValidatorTest extends \PHPUnit_Framework_TestCase +class LanguageValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; + protected function getApiVersion() + { + return Validation::API_VERSION_2_5; + } + + protected function createValidator() + { + return new LanguageValidator(); + } protected function setUp() { IntlTestHelper::requireFullIntl($this); - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new LanguageValidator(); - $this->validator->initialize($this->context); - } - - protected function tearDown() - { - $this->context = null; - $this->validator = null; + parent::setUp(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Language()); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Language()); + + $this->assertNoViolation(); } /** @@ -64,10 +62,9 @@ class LanguageValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidLanguages($language) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($language, new Language()); + + $this->assertNoViolation(); } public function getValidLanguages() @@ -88,13 +85,11 @@ class LanguageValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $language, - )); - $this->validator->validate($language, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $language, + )); } public function getInvalidLanguages() @@ -109,11 +104,11 @@ class LanguageValidatorTest extends \PHPUnit_Framework_TestCase { \Locale::setDefault('fr_FR'); $existingLanguage = 'en'; - $this->context->expects($this->never()) - ->method('addViolation'); $this->validator->validate($existingLanguage, new Language(array( 'message' => 'aMessage' ))); + + $this->assertNoViolation(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyAllValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyAllValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..fabc47181a --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyAllValidator2Dot4ApiTest.php @@ -0,0 +1,32 @@ + + * + * 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\LegacyAllValidator; +use Symfony\Component\Validator\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyAllValidator2Dot4ApiTest extends AllValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } + + protected function createValidator() + { + return new LegacyAllValidator(); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyAllValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyAllValidatorLegacyApiTest.php new file mode 100644 index 0000000000..03cb48bb6e --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyAllValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyAllValidatorLegacyApiTest extends AllValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyBlankValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyBlankValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..3c47b99b71 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyBlankValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyBlankValidator2Dot4ApiTest extends BlankValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyBlankValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyBlankValidatorLegacyApiTest.php new file mode 100644 index 0000000000..047113f1ca --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyBlankValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyBlankValidatorLegacyApiTest extends BlankValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCallbackValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCallbackValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..9cb42de80f --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCallbackValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyCallbackValidator2Dot4ApiTest extends CallbackValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCallbackValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCallbackValidatorLegacyApiTest.php new file mode 100644 index 0000000000..ef19fa04c1 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCallbackValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyCallbackValidatorLegacyApiTest extends CallbackValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCardSchemeValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCardSchemeValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..37141dad43 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCardSchemeValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyCardSchemeValidator2Dot4ApiTest extends CardSchemeValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCardSchemeValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCardSchemeValidatorLegacyApiTest.php new file mode 100644 index 0000000000..dab03e1df9 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCardSchemeValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyCardSchemeValidatorLegacyApiTest extends CardSchemeValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyChoiceValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyChoiceValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..165dbd62d3 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyChoiceValidator2Dot4ApiTest.php @@ -0,0 +1,32 @@ + + * + * 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\LegacyChoiceValidator; +use Symfony\Component\Validator\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyChoiceValidator2Dot4ApiTest extends ChoiceValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } + + protected function createValidator() + { + return new LegacyChoiceValidator(); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyChoiceValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyChoiceValidatorLegacyApiTest.php new file mode 100644 index 0000000000..a70c428ff2 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyChoiceValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyChoiceValidatorLegacyApiTest extends ChoiceValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArray2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArray2Dot4ApiTest.php new file mode 100644 index 0000000000..b8cafcd968 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArray2Dot4ApiTest.php @@ -0,0 +1,28 @@ + + * + * 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\LegacyCollectionValidator; +use Symfony\Component\Validator\Validation; + +class LegacyCollectionValidatorArray2Dot4ApiTest extends CollectionValidatorArrayTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } + + protected function createValidator() + { + return new LegacyCollectionValidator(); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArrayLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArrayLegacyApiTest.php new file mode 100644 index 0000000000..02ceb192a9 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArrayLegacyApiTest.php @@ -0,0 +1,22 @@ + + * + * 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\Validation; + +class LegacyCollectionValidatorArrayLegacyApiTest extends CollectionValidatorArrayTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArrayObject2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArrayObject2Dot4ApiTest.php new file mode 100644 index 0000000000..462e9ff61e --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArrayObject2Dot4ApiTest.php @@ -0,0 +1,28 @@ + + * + * 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\LegacyCollectionValidator; +use Symfony\Component\Validator\Validation; + +class LegacyCollectionValidatorArrayObject2Dot4ApiTest extends CollectionValidatorArrayObjectTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } + + protected function createValidator() + { + return new LegacyCollectionValidator(); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArrayObjectLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArrayObjectLegacyApiTest.php new file mode 100644 index 0000000000..3a2dba9978 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorArrayObjectLegacyApiTest.php @@ -0,0 +1,22 @@ + + * + * 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\Validation; + +class LegacyCollectionValidatorArrayObjectLegacyApiTest extends CollectionValidatorArrayObjectTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorCustomArrayObject2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorCustomArrayObject2Dot4ApiTest.php new file mode 100644 index 0000000000..b3b8cab416 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorCustomArrayObject2Dot4ApiTest.php @@ -0,0 +1,28 @@ + + * + * 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\LegacyCollectionValidator; +use Symfony\Component\Validator\Validation; + +class LegacyCollectionValidatorCustomArrayObject2Dot4ApiTest extends CollectionValidatorCustomArrayObjectTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } + + protected function createValidator() + { + return new LegacyCollectionValidator(); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorCustomArrayObjectLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorCustomArrayObjectLegacyApiTest.php new file mode 100644 index 0000000000..e65147fb21 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCollectionValidatorCustomArrayObjectLegacyApiTest.php @@ -0,0 +1,22 @@ + + * + * 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\Validation; + +class LegacyCollectionValidatorCustomArrayObjectLegacyApiTest extends CollectionValidatorCustomArrayObjectTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorArray2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorArray2Dot4ApiTest.php new file mode 100644 index 0000000000..4169dd7c13 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorArray2Dot4ApiTest.php @@ -0,0 +1,32 @@ + + * + * 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\LegacyCountValidator; +use Symfony\Component\Validator\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyCountValidatorArray2Dot4ApiTest extends CountValidatorArrayTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } + + protected function createValidator() + { + return new LegacyCountValidator(); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorArrayLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorArrayLegacyApiTest.php new file mode 100644 index 0000000000..43f18105ee --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorArrayLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyCountValidatorArrayLegacyApiTest extends CountValidatorArrayTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorCountable2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorCountable2Dot4ApiTest.php new file mode 100644 index 0000000000..037ff2dac2 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorCountable2Dot4ApiTest.php @@ -0,0 +1,32 @@ + + * + * 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\LegacyCountValidator; +use Symfony\Component\Validator\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyCountValidatorCountable2Dot4ApiTest extends CountValidatorCountableTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } + + protected function createValidator() + { + return new LegacyCountValidator(); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorCountableLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorCountableLegacyApiTest.php new file mode 100644 index 0000000000..89e0f3ed24 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCountValidatorCountableLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyCountValidatorCountableLegacyApiTest extends CountValidatorCountableTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCurrencyValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCurrencyValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..5a042f0d5c --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCurrencyValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyCurrencyValidator2Dot4ApiTest extends CurrencyValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyCurrencyValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCurrencyValidatorLegacyApiTest.php new file mode 100644 index 0000000000..ba291920ef --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyCurrencyValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyCurrencyValidatorLegacyApiTest extends CurrencyValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyDateTimeValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyDateTimeValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..27d35a85d7 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyDateTimeValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyDateTimeValidator2Dot4ApiTest extends DateTimeValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyDateTimeValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyDateTimeValidatorLegacyApiTest.php new file mode 100644 index 0000000000..120d077280 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyDateTimeValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyDateTimeValidatorLegacyApiTest extends DateTimeValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyDateValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyDateValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..7d54e42839 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyDateValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyDateValidator2Dot4ApiTest extends DateValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyDateValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyDateValidatorLegacyApiTest.php new file mode 100644 index 0000000000..03e329e048 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyDateValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyDateValidatorLegacyApiTest extends DateValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyEmailValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyEmailValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..a29f918d15 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyEmailValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyEmailValidator2Dot4ApiTest extends EmailValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyEmailValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyEmailValidatorLegacyApiTest.php new file mode 100644 index 0000000000..477ce14d40 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyEmailValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyEmailValidatorLegacyApiTest extends EmailValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyEqualToValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyEqualToValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..6f1d2ccbc1 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyEqualToValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyEqualToValidator2Dot4ApiTest extends EqualToValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyEqualToValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyEqualToValidatorLegacyApiTest.php new file mode 100644 index 0000000000..16f71123ef --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyEqualToValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyEqualToValidatorLegacyApiTest extends EqualToValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyExpressionValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyExpressionValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..5188c36965 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyExpressionValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyExpressionValidator2Dot4ApiTest extends ExpressionValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyExpressionValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyExpressionValidatorLegacyApiTest.php new file mode 100644 index 0000000000..8b3ab71b5e --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyExpressionValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyExpressionValidatorLegacyApiTest extends ExpressionValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyFalseValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyFalseValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..cbd1791cc9 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyFalseValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyFalseValidator2Dot4ApiTest extends FalseValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyFalseValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyFalseValidatorLegacyApiTest.php new file mode 100644 index 0000000000..0fc46b4cb6 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyFalseValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyFalseValidatorLegacyApiTest extends FalseValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorObject2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorObject2Dot4ApiTest.php new file mode 100644 index 0000000000..27896a6445 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorObject2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyFileValidatorObject2Dot4ApiTest extends FileValidatorObjectTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorObjectLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorObjectLegacyApiTest.php new file mode 100644 index 0000000000..0ff1e739ec --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorObjectLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyFileValidatorObjectLegacyApiTest extends FileValidatorObjectTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorPath2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorPath2Dot4ApiTest.php new file mode 100644 index 0000000000..c195a13d37 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorPath2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyFileValidatorPath2Dot4ApiTest extends FileValidatorPathTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorPathLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorPathLegacyApiTest.php new file mode 100644 index 0000000000..c04544b53c --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyFileValidatorPathLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyFileValidatorPathLegacyApiTest extends FileValidatorPathTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanOrEqualValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanOrEqualValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..90ef99e8f2 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanOrEqualValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyGreaterThanOrEqualValidator2Dot4ApiTest extends GreaterThanOrEqualValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanOrEqualValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanOrEqualValidatorLegacyApiTest.php new file mode 100644 index 0000000000..99912358ca --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanOrEqualValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyGreaterThanOrEqualValidatorLegacyApiTest extends GreaterThanOrEqualValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..3edb2ffc17 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyGreaterThanValidator2Dot4ApiTest extends GreaterThanValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanValidatorLegacyApiTest.php new file mode 100644 index 0000000000..7d04e1e7e6 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyGreaterThanValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyGreaterThanValidatorLegacyApiTest extends GreaterThanValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyIbanValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIbanValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..b89c2f168c --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIbanValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyIbanValidator2Dot4ApiTest extends IbanValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyIbanValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIbanValidatorLegacyApiTest.php new file mode 100644 index 0000000000..97b322bd67 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIbanValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyIbanValidatorLegacyApiTest extends IbanValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyIdenticalToValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIdenticalToValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..2847e79623 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIdenticalToValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyIdenticalToValidator2Dot4ApiTest extends IdenticalToValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyIdenticalToValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIdenticalToValidatorLegacyApiTest.php new file mode 100644 index 0000000000..c337f4927c --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIdenticalToValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyIdenticalToValidatorLegacyApiTest extends IdenticalToValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyImageValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyImageValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..c4b56aa65e --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyImageValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyImageValidator2Dot4ApiTest extends ImageValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyImageValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyImageValidatorLegacyApiTest.php new file mode 100644 index 0000000000..c8171232e0 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyImageValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyImageValidatorLegacyApiTest extends ImageValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyIpValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIpValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..ca3b506449 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIpValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyIpValidator2Dot4ApiTest extends IpValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyIpValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIpValidatorLegacyApiTest.php new file mode 100644 index 0000000000..edc2acc6f6 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIpValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyIpValidatorLegacyApiTest extends IpValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyIsbnValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIsbnValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..d2b6adfaf7 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIsbnValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyIsbnValidator2Dot4ApiTest extends IsbnValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyIsbnValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIsbnValidatorLegacyApiTest.php new file mode 100644 index 0000000000..33525c1398 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIsbnValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyIsbnValidatorLegacyApiTest extends IsbnValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyIssnValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIssnValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..1c37e38134 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIssnValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyIssnValidator2Dot4ApiTest extends IssnValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyIssnValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIssnValidatorLegacyApiTest.php new file mode 100644 index 0000000000..0273310cd0 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyIssnValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyIssnValidatorLegacyApiTest extends IssnValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyLanguageValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLanguageValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..4a08c77b9c --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLanguageValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyLanguageValidator2Dot4ApiTest extends LanguageValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyLanguageValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLanguageValidatorLegacyApiTest.php new file mode 100644 index 0000000000..f2f974fef8 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLanguageValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyLanguageValidatorLegacyApiTest extends LanguageValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyLengthValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLengthValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..54faa262d1 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLengthValidator2Dot4ApiTest.php @@ -0,0 +1,32 @@ + + * + * 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\LegacyLengthValidator; +use Symfony\Component\Validator\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyLengthValidator2Dot4ApiTest extends LengthValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } + + protected function createValidator() + { + return new LegacyLengthValidator(); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyLengthValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLengthValidatorLegacyApiTest.php new file mode 100644 index 0000000000..784cd76493 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLengthValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyLengthValidatorLegacyApiTest extends LengthValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanOrEqualValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanOrEqualValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..7a817fe795 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanOrEqualValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyLessThanOrEqualValidator2Dot4ApiTest extends LessThanOrEqualValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanOrEqualValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanOrEqualValidatorLegacyApiTest.php new file mode 100644 index 0000000000..d74d8e42d8 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanOrEqualValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyLessThanOrEqualValidatorLegacyApiTest extends LessThanOrEqualValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..4e11330d8a --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyLessThanValidator2Dot4ApiTest extends LessThanValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanValidatorLegacyApiTest.php new file mode 100644 index 0000000000..ef436fab08 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLessThanValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyLessThanValidatorLegacyApiTest extends LessThanValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyLocaleValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLocaleValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..2120384dae --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLocaleValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyLocaleValidator2Dot4ApiTest extends LocaleValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyLocaleValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLocaleValidatorLegacyApiTest.php new file mode 100644 index 0000000000..e95902efe7 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLocaleValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyLocaleValidatorLegacyApiTest extends LocaleValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyLuhnValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLuhnValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..49b2cebd6f --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLuhnValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyLuhnValidator2Dot4ApiTest extends LuhnValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyLuhnValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLuhnValidatorLegacyApiTest.php new file mode 100644 index 0000000000..fb8c31ca30 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyLuhnValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyLuhnValidatorLegacyApiTest extends LuhnValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotBlankValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotBlankValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..f5ac29017a --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotBlankValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyNotBlankValidator2Dot4ApiTest extends NotBlankValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotBlankValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotBlankValidatorLegacyApiTest.php new file mode 100644 index 0000000000..f34c6c7dba --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotBlankValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyNotBlankValidatorLegacyApiTest extends NotBlankValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotEqualToValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotEqualToValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..f9e51a8ada --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotEqualToValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyNotEqualToValidator2Dot4ApiTest extends NotEqualToValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotEqualToValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotEqualToValidatorLegacyApiTest.php new file mode 100644 index 0000000000..7ea366085b --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotEqualToValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyNotEqualToValidatorLegacyApiTest extends NotEqualToValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotIdenticalToValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotIdenticalToValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..9a38be7bb8 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotIdenticalToValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyNotIdenticalToValidator2Dot4ApiTest extends NotIdenticalToValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotIdenticalToValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotIdenticalToValidatorLegacyApiTest.php new file mode 100644 index 0000000000..ed1fbc7f0b --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotIdenticalToValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyNotIdenticalToValidatorLegacyApiTest extends NotIdenticalToValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotNullValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotNullValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..98197c7439 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotNullValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyNotNullValidator2Dot4ApiTest extends NotNullValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotNullValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotNullValidatorLegacyApiTest.php new file mode 100644 index 0000000000..d40d759635 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNotNullValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyNotNullValidatorLegacyApiTest extends NotNullValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyNullValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNullValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..dacf1d2023 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNullValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyNullValidator2Dot4ApiTest extends NullValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyNullValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNullValidatorLegacyApiTest.php new file mode 100644 index 0000000000..390e325394 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyNullValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyNullValidatorLegacyApiTest extends NullValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyRangeValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyRangeValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..a3df8dfefe --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyRangeValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyRangeValidator2Dot4ApiTest extends RangeValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyRangeValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyRangeValidatorLegacyApiTest.php new file mode 100644 index 0000000000..efe7f85c42 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyRangeValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyRangeValidatorLegacyApiTest extends RangeValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyRegexValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyRegexValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..50f25f0303 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyRegexValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyRegexValidator2Dot4ApiTest extends RegexValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyRegexValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyRegexValidatorLegacyApiTest.php new file mode 100644 index 0000000000..c58b1a134f --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyRegexValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyRegexValidatorLegacyApiTest extends RegexValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyTimeValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyTimeValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..318597590b --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyTimeValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyTimeValidator2Dot4ApiTest extends TimeValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyTimeValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyTimeValidatorLegacyApiTest.php new file mode 100644 index 0000000000..ba0e30d553 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyTimeValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyTimeValidatorLegacyApiTest extends TimeValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyTrueValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyTrueValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..8d8c54ceb9 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyTrueValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyTrueValidator2Dot4ApiTest extends TrueValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyTrueValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyTrueValidatorLegacyApiTest.php new file mode 100644 index 0000000000..8a199e0a98 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyTrueValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyTrueValidatorLegacyApiTest extends TrueValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyTypeValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyTypeValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..c249240e7f --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyTypeValidator2Dot4ApiTest.php @@ -0,0 +1,36 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyTypeValidator2Dot4ApiTest extends TypeValidatorTest +{ + /** + * PhpUnit calls data providers of test suites before launching the test + * suite. If this property is not replicated in every test class, only one + * file will ever be created and stored in TypeValidatorTest::$file. After + * the execution of the first TypeValidator test case, tearDownAfterClass() + * is called and closes the file. Hence the resource is not available + * anymore in the other TypeValidator test cases. + */ + protected static $file; + + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyTypeValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyTypeValidatorLegacyApiTest.php new file mode 100644 index 0000000000..808c37fab3 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyTypeValidatorLegacyApiTest.php @@ -0,0 +1,28 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyTypeValidatorLegacyApiTest extends TypeValidatorTest +{ + protected static $file; + + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyUrlValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyUrlValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..55564c9f91 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyUrlValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyUrlValidator2Dot4ApiTest extends UrlValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyUrlValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyUrlValidatorLegacyApiTest.php new file mode 100644 index 0000000000..8e1eb20841 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyUrlValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyUrlValidatorLegacyApiTest extends UrlValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyUuidValidator2Dot4ApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyUuidValidator2Dot4ApiTest.php new file mode 100644 index 0000000000..c421404bfe --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyUuidValidator2Dot4ApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyUuidValidator2Dot4ApiTest extends UrlValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_4; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LegacyUuidValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LegacyUuidValidatorLegacyApiTest.php new file mode 100644 index 0000000000..1fd6f337af --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/LegacyUuidValidatorLegacyApiTest.php @@ -0,0 +1,26 @@ + + * + * 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\Validation; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + */ +class LegacyUuidValidatorLegacyApiTest extends UuidValidatorTest +{ + protected function getApiVersion() + { + return Validation::API_VERSION_2_5_BC; + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php index db6339449d..f320658721 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php @@ -13,39 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\LengthValidator; +use Symfony\Component\Validator\Validation; -class LengthValidatorTest extends \PHPUnit_Framework_TestCase +class LengthValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new LengthValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new LengthValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Length(6)); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Length(6)); + + $this->assertNoViolation(); } /** @@ -111,11 +104,10 @@ class LengthValidatorTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('mb_strlen does not exist'); } - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new Length(array('min' => 5)); $this->validator->validate($value, $constraint); + + $this->assertNoViolation(); } /** @@ -127,11 +119,10 @@ class LengthValidatorTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('mb_strlen does not exist'); } - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new Length(array('max' => 3)); $this->validator->validate($value, $constraint); + + $this->assertNoViolation(); } /** @@ -143,11 +134,10 @@ class LengthValidatorTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('mb_strlen does not exist'); } - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new Length(4); $this->validator->validate($value, $constraint); + + $this->assertNoViolation(); } /** @@ -164,14 +154,12 @@ class LengthValidatorTest extends \PHPUnit_Framework_TestCase 'minMessage' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', $this->identicalTo(array( - '{{ value }}' => (string) $value, - '{{ limit }}' => 4, - )), $this->identicalTo($value), 4); - $this->validator->validate($value, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => (string) $value, + '{{ limit }}' => 4, + ), 'property.path', $value, 4); } /** @@ -188,14 +176,12 @@ class LengthValidatorTest extends \PHPUnit_Framework_TestCase 'maxMessage' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', $this->identicalTo(array( - '{{ value }}' => (string) $value, - '{{ limit }}' => 4, - )), $this->identicalTo($value), 4); - $this->validator->validate($value, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => (string) $value, + '{{ limit }}' => 4, + ), 'property.path', $value, 4); } /** @@ -213,14 +199,12 @@ class LengthValidatorTest extends \PHPUnit_Framework_TestCase 'exactMessage' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', $this->identicalTo(array( - '{{ value }}' => (string) $value, - '{{ limit }}' => 4, - )), $this->identicalTo($value), 4); - $this->validator->validate($value, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => (string) $value, + '{{ limit }}' => 4, + ), 'property.path', $value, 4); } public function testConstraintGetDefaultOption() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php index 15d68e9382..fafb246d74 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php @@ -13,12 +13,18 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\LessThanOrEqual; use Symfony\Component\Validator\Constraints\LessThanOrEqualValidator; +use Symfony\Component\Validator\Validation; /** * @author Daniel Holmes */ class LessThanOrEqualValidatorTest extends AbstractComparisonValidatorTestCase { + protected function getApiVersion() + { + return Validation::API_VERSION_2_5; + } + protected function createValidator() { return new LessThanOrEqualValidator(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php index 8d42d83f31..3eac5d09f9 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php @@ -13,12 +13,18 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\LessThan; use Symfony\Component\Validator\Constraints\LessThanValidator; +use Symfony\Component\Validator\Validation; /** * @author Daniel Holmes */ class LessThanValidatorTest extends AbstractComparisonValidatorTestCase { + protected function getApiVersion() + { + return Validation::API_VERSION_2_5; + } + protected function createValidator() { return new LessThanValidator(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php index 41feba0c71..052e4742e1 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php @@ -14,41 +14,39 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Intl\Util\IntlTestHelper; use Symfony\Component\Validator\Constraints\Locale; use Symfony\Component\Validator\Constraints\LocaleValidator; +use Symfony\Component\Validator\Validation; -class LocaleValidatorTest extends \PHPUnit_Framework_TestCase +class LocaleValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; + protected function getApiVersion() + { + return Validation::API_VERSION_2_5; + } + + protected function createValidator() + { + return new LocaleValidator(); + } protected function setUp() { IntlTestHelper::requireIntl($this); - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new LocaleValidator(); - $this->validator->initialize($this->context); - } - - protected function tearDown() - { - $this->context = null; - $this->validator = null; + parent::setUp(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Locale()); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Locale()); + + $this->assertNoViolation(); } /** @@ -64,10 +62,9 @@ class LocaleValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidLocales($locale) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($locale, new Locale()); + + $this->assertNoViolation(); } public function getValidLocales() @@ -90,13 +87,11 @@ class LocaleValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $locale, - )); - $this->validator->validate($locale, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $locale, + )); } public function getInvalidLocales() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php index 11c6a7cad5..e166e030ec 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php @@ -13,39 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Luhn; use Symfony\Component\Validator\Constraints\LuhnValidator; +use Symfony\Component\Validator\Validation; -class LuhnValidatorTest extends \PHPUnit_Framework_TestCase +class LuhnValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new LuhnValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new LuhnValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Luhn()); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Luhn()); + + $this->assertNoViolation(); } /** @@ -53,10 +46,9 @@ class LuhnValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidNumbers($number) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($number, new Luhn()); + + $this->assertNoViolation(); } public function getValidNumbers() @@ -88,13 +80,13 @@ class LuhnValidatorTest extends \PHPUnit_Framework_TestCase */ public function testInvalidNumbers($number) { - $constraint = new Luhn(); - - $this->context->expects($this->once()) - ->method('addViolation') - ->with($constraint->message); + $constraint = new Luhn(array( + 'message' => 'myMessage', + )); $this->validator->validate($number, $constraint); + + $this->assertViolation('myMessage'); } public function getInvalidNumbers() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php index 7273986a87..effe6fb5cd 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php @@ -13,23 +13,18 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\NotBlankValidator; +use Symfony\Component\Validator\Validation; -class NotBlankValidatorTest extends \PHPUnit_Framework_TestCase +class NotBlankValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new NotBlankValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new NotBlankValidator(); } /** @@ -37,10 +32,9 @@ class NotBlankValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidValues($value) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($value, new NotBlank()); + + $this->assertNoViolation(); } public function getValidValues() @@ -60,11 +54,9 @@ class NotBlankValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage'); - $this->validator->validate(null, $constraint); + + $this->assertViolation('myMessage'); } public function testBlankIsInvalid() @@ -73,11 +65,9 @@ class NotBlankValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage'); - $this->validator->validate('', $constraint); + + $this->assertViolation('myMessage'); } public function testFalseIsInvalid() @@ -86,11 +76,9 @@ class NotBlankValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage'); - $this->validator->validate(false, $constraint); + + $this->assertViolation('myMessage'); } public function testEmptyArrayIsInvalid() @@ -99,10 +87,8 @@ class NotBlankValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage'); - $this->validator->validate(array(), $constraint); + + $this->assertViolation('myMessage'); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php index 3ad33a6f0c..d4abec3483 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php @@ -13,12 +13,18 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\NotEqualTo; use Symfony\Component\Validator\Constraints\NotEqualToValidator; +use Symfony\Component\Validator\Validation; /** * @author Daniel Holmes */ class NotEqualToValidatorTest extends AbstractComparisonValidatorTestCase { + protected function getApiVersion() + { + return Validation::API_VERSION_2_5; + } + protected function createValidator() { return new NotEqualToValidator(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php index f5b4a90c08..c908cb7b00 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php @@ -13,12 +13,18 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\NotIdenticalTo; use Symfony\Component\Validator\Constraints\NotIdenticalToValidator; +use Symfony\Component\Validator\Validation; /** * @author Daniel Holmes */ class NotIdenticalToValidatorTest extends AbstractComparisonValidatorTestCase { + protected function getApiVersion() + { + return Validation::API_VERSION_2_5; + } + protected function createValidator() { return new NotIdenticalToValidator(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php index 96f74a1ba0..27d79315fb 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php @@ -13,23 +13,18 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\Constraints\NotNullValidator; +use Symfony\Component\Validator\Validation; -class NotNullValidatorTest extends \PHPUnit_Framework_TestCase +class NotNullValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new NotNullValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new NotNullValidator(); } /** @@ -37,10 +32,9 @@ class NotNullValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidValues($value) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($value, new NotNull()); + + $this->assertNoViolation(); } public function getValidValues() @@ -59,11 +53,8 @@ class NotNullValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - )); - $this->validator->validate(null, $constraint); + + $this->assertViolation('myMessage'); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NullValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NullValidatorTest.php index d343c869fd..9809bdfa8c 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NullValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NullValidatorTest.php @@ -13,31 +13,25 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Null; use Symfony\Component\Validator\Constraints\NullValidator; +use Symfony\Component\Validator\Validation; -class NullValidatorTest extends \PHPUnit_Framework_TestCase +class NullValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new NullValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new NullValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Null()); + + $this->assertNoViolation(); } /** @@ -49,13 +43,11 @@ class NullValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $readableValue, - )); - $this->validator->validate($value, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $readableValue, + )); } public function getInvalidValues() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php index c44b0ea6ce..5ae5e43ef7 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php @@ -13,25 +13,25 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Range; use Symfony\Component\Validator\Constraints\RangeValidator; +use Symfony\Component\Validator\Validation; -class RangeValidatorTest extends \PHPUnit_Framework_TestCase +class RangeValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new RangeValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; + } + + protected function createValidator() + { + return new RangeValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Range(array('min' => 10, 'max' => 20))); + + $this->assertNoViolation(); } public function getTenToTwenty() @@ -73,11 +73,10 @@ class RangeValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidValuesMin($value) { - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new Range(array('min' => 10)); $this->validator->validate($value, $constraint); + + $this->assertNoViolation(); } /** @@ -85,11 +84,10 @@ class RangeValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidValuesMax($value) { - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new Range(array('max' => 20)); $this->validator->validate($value, $constraint); + + $this->assertNoViolation(); } /** @@ -97,11 +95,10 @@ class RangeValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidValuesMinMax($value) { - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new Range(array('min' => 10, 'max' => 20)); $this->validator->validate($value, $constraint); + + $this->assertNoViolation(); } /** @@ -114,14 +111,12 @@ class RangeValidatorTest extends \PHPUnit_Framework_TestCase 'minMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', $this->identicalTo(array( - '{{ value }}' => $value, - '{{ limit }}' => 10, - ))); - $this->validator->validate($value, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $value, + '{{ limit }}' => 10, + )); } /** @@ -134,14 +129,12 @@ class RangeValidatorTest extends \PHPUnit_Framework_TestCase 'maxMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', $this->identicalTo(array( - '{{ value }}' => $value, - '{{ limit }}' => 20, - ))); - $this->validator->validate($value, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $value, + '{{ limit }}' => 20, + )); } /** @@ -156,14 +149,12 @@ class RangeValidatorTest extends \PHPUnit_Framework_TestCase 'maxMessage' => 'myMaxMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMaxMessage', $this->identicalTo(array( - '{{ value }}' => $value, - '{{ limit }}' => 20, - ))); - $this->validator->validate($value, $constraint); + + $this->assertViolation('myMaxMessage', array( + '{{ value }}' => $value, + '{{ limit }}' => 20, + )); } /** @@ -178,14 +169,12 @@ class RangeValidatorTest extends \PHPUnit_Framework_TestCase 'maxMessage' => 'myMaxMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMinMessage', $this->identicalTo(array( + $this->validator->validate($value, $constraint); + + $this->assertViolation('myMinMessage', array( '{{ value }}' => $value, '{{ limit }}' => 10, - ))); - - $this->validator->validate($value, $constraint); + )); } public function getInvalidValues() @@ -207,14 +196,12 @@ class RangeValidatorTest extends \PHPUnit_Framework_TestCase 'minMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => 9, - '{{ limit }}' => 10, - )); - $this->validator->validate(9, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => 9, + '{{ limit }}' => 10, + )); } public function testMaxMessageIsSet() @@ -225,13 +212,11 @@ class RangeValidatorTest extends \PHPUnit_Framework_TestCase 'maxMessage' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => 21, - '{{ limit }}' => 20, - )); - $this->validator->validate(21, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => 21, + '{{ limit }}' => 20, + )); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php index 1ea79fb8e2..17546b0879 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php @@ -13,39 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Regex; use Symfony\Component\Validator\Constraints\RegexValidator; +use Symfony\Component\Validator\Validation; -class RegexValidatorTest extends \PHPUnit_Framework_TestCase +class RegexValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new RegexValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new RegexValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Regex(array('pattern' => '/^[0-9]+$/'))); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Regex(array('pattern' => '/^[0-9]+$/'))); + + $this->assertNoViolation(); } /** @@ -61,11 +54,10 @@ class RegexValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidValues($value) { - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new Regex(array('pattern' => '/^[0-9]+$/')); $this->validator->validate($value, $constraint); + + $this->assertNoViolation(); } public function getValidValues() @@ -88,13 +80,11 @@ class RegexValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $value, - )); - $this->validator->validate($value, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $value, + )); } public function getInvalidValues() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php index ba398ab373..b68bd8dd1c 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php @@ -13,47 +13,39 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Time; use Symfony\Component\Validator\Constraints\TimeValidator; +use Symfony\Component\Validator\Validation; -class TimeValidatorTest extends \PHPUnit_Framework_TestCase +class TimeValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new TimeValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new TimeValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Time()); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Time()); + + $this->assertNoViolation(); } public function testDateTimeClassIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(new \DateTime(), new Time()); + + $this->assertNoViolation(); } /** @@ -69,10 +61,9 @@ class TimeValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidTimes($time) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($time, new Time()); + + $this->assertNoViolation(); } public function getValidTimes() @@ -93,13 +84,11 @@ class TimeValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $time, - )); - $this->validator->validate($time, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $time, + )); } public function getInvalidTimes() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TrueValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TrueValidatorTest.php index 25901793a0..e3c7f265d5 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TrueValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TrueValidatorTest.php @@ -13,39 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\True; use Symfony\Component\Validator\Constraints\TrueValidator; +use Symfony\Component\Validator\Validation; -class TrueValidatorTest extends \PHPUnit_Framework_TestCase +class TrueValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new TrueValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new TrueValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new True()); + + $this->assertNoViolation(); } public function testTrueIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(true, new True()); + + $this->assertNoViolation(); } public function testFalseIsInvalid() @@ -54,11 +47,8 @@ class TrueValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - )); - $this->validator->validate(false, $constraint); + + $this->assertViolation('myMessage'); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php index e5e6d0bf02..634418f245 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php @@ -13,49 +13,53 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Type; use Symfony\Component\Validator\Constraints\TypeValidator; +use Symfony\Component\Validator\Validation; -class TypeValidatorTest extends \PHPUnit_Framework_TestCase +class TypeValidatorTest extends AbstractConstraintValidatorTest { protected static $file; - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new TypeValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new TypeValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); + $constraint = new Type(array('type' => 'integer')); - $this->validator->validate(null, new Type(array('type' => 'integer'))); + $this->validator->validate(null, $constraint); + + $this->assertNoViolation(); } public function testEmptyIsValidIfString() { - $this->context->expects($this->never()) - ->method('addViolation'); + $constraint = new Type(array('type' => 'string')); - $this->validator->validate('', new Type(array('type' => 'string'))); + $this->validator->validate('', $constraint); + + $this->assertNoViolation(); } public function testEmptyIsInvalidIfNoString() { - $this->context->expects($this->once()) - ->method('addViolation'); + $constraint = new Type(array( + 'type' => 'integer', + 'message' => 'myMessage', + )); - $this->validator->validate('', new Type(array('type' => 'integer'))); + $this->validator->validate('', $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => '', + '{{ type }}' => 'integer', + )); } /** @@ -63,12 +67,11 @@ class TypeValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidValues($value, $type) { - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new Type(array('type' => $type)); $this->validator->validate($value, $constraint); + + $this->assertNoViolation(); } public function getValidValues() @@ -118,14 +121,12 @@ class TypeValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $valueAsString, - '{{ type }}' => $type, - )); - $this->validator->validate($value, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $valueAsString, + '{{ type }}' => $type, + )); } public function getInvalidValues() @@ -167,17 +168,18 @@ class TypeValidatorTest extends \PHPUnit_Framework_TestCase protected function createFile() { - if (!self::$file) { - self::$file = fopen(__FILE__, 'r'); + if (!static::$file) { + static::$file = fopen(__FILE__, 'r'); } - return self::$file; + return static::$file; } public static function tearDownAfterClass() { - if (self::$file) { - fclose(self::$file); + if (static::$file) { + fclose(static::$file); + static::$file = null; } } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php index 1cf4bb4d22..82fae79a2a 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php @@ -13,39 +13,32 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Url; use Symfony\Component\Validator\Constraints\UrlValidator; +use Symfony\Component\Validator\Validation; -class UrlValidatorTest extends \PHPUnit_Framework_TestCase +class UrlValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new UrlValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new UrlValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Url()); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Url()); + + $this->assertNoViolation(); } /** @@ -61,10 +54,9 @@ class UrlValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidUrls($url) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($url, new Url()); + + $this->assertNoViolation(); } public function getValidUrls() @@ -128,13 +120,11 @@ class UrlValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'myMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $url, - )); - $this->validator->validate($url, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $url, + )); } public function getInvalidUrls() @@ -163,14 +153,13 @@ class UrlValidatorTest extends \PHPUnit_Framework_TestCase */ public function testCustomProtocolIsValid($url) { - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new Url(array( 'protocols' => array('ftp', 'file', 'git') )); $this->validator->validate($url, $constraint); + + $this->assertNoViolation(); } public function getValidCustomUrls() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UuidValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UuidValidatorTest.php index ab04aac6c7..a590be271a 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UuidValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UuidValidatorTest.php @@ -13,42 +13,35 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Uuid; use Symfony\Component\Validator\Constraints\UuidValidator; +use Symfony\Component\Validator\Validation; /** * @author Colin O'Dell */ -class UuidValidatorTest extends \PHPUnit_Framework_TestCase +class UuidValidatorTest extends AbstractConstraintValidatorTest { - protected $context; - protected $validator; - - protected function setUp() + protected function getApiVersion() { - $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); - $this->validator = new UuidValidator(); - $this->validator->initialize($this->context); + return Validation::API_VERSION_2_5; } - protected function tearDown() + protected function createValidator() { - $this->context = null; - $this->validator = null; + return new UuidValidator(); } public function testNullIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate(null, new Uuid()); + + $this->assertNoViolation(); } public function testEmptyStringIsValid() { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate('', new Uuid()); + + $this->assertNoViolation(); } /** @@ -64,10 +57,9 @@ class UuidValidatorTest extends \PHPUnit_Framework_TestCase */ public function testValidStrictUuids($uuid) { - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($uuid, new Uuid()); + + $this->assertNoViolation(); } public function getValidStrictUuids() @@ -89,13 +81,11 @@ class UuidValidatorTest extends \PHPUnit_Framework_TestCase 'message' => 'testMessage' )); - $this->context->expects($this->once()) - ->method('addViolation') - ->with('testMessage', array( - '{{ value }}' => $uuid, - )); - $this->validator->validate($uuid, $constraint); + + $this->assertViolation('testMessage', array( + '{{ value }}' => $uuid, + )); } public function getInvalidStrictUuids() @@ -119,14 +109,13 @@ class UuidValidatorTest extends \PHPUnit_Framework_TestCase */ public function testVersionConstraintIsValid($uuid) { - $this->context->expects($this->never()) - ->method('addViolation'); - $constraint = new Uuid(array( 'versions' => array(Uuid::V1_MAC, Uuid::V4_RANDOM) )); $this->validator->validate($uuid, $constraint); + + $this->assertNoViolation(); } /** @@ -135,13 +124,15 @@ class UuidValidatorTest extends \PHPUnit_Framework_TestCase public function testVersionConstraintIsInvalid($uuid) { $constraint = new Uuid(array( - 'versions' => array(Uuid::V2_DCE, Uuid::V3_MD5) + 'versions' => array(Uuid::V2_DCE, Uuid::V3_MD5), + 'message' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation'); - $this->validator->validate($uuid, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $uuid, + )); } /** @@ -153,10 +144,9 @@ class UuidValidatorTest extends \PHPUnit_Framework_TestCase 'strict' => false )); - $this->context->expects($this->never()) - ->method('addViolation'); - $this->validator->validate($uuid, $constraint); + + $this->assertNoViolation(); } public function getValidNonStrictUuids() @@ -181,13 +171,15 @@ class UuidValidatorTest extends \PHPUnit_Framework_TestCase public function testInvalidNonStrictUuids($uuid) { $constraint = new Uuid(array( - 'strict' => false + 'strict' => false, + 'message' => 'myMessage', )); - $this->context->expects($this->once()) - ->method('addViolation'); - $this->validator->validate($uuid, $constraint); + + $this->assertViolation('myMessage', array( + '{{ value }}' => $uuid, + )); } public function getInvalidNonStrictUuids() diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/Countable.php b/src/Symfony/Component/Validator/Tests/Fixtures/Countable.php new file mode 100644 index 0000000000..282d78d45a --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Fixtures/Countable.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\Tests\Fixtures; + +class Countable implements \Countable +{ + private $content; + + public function __construct(array $content) + { + $this->content = $content; + } + + public function count() + { + return count($this->content); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/CustomArrayObject.php b/src/Symfony/Component/Validator/Tests/Fixtures/CustomArrayObject.php new file mode 100644 index 0000000000..41eac961ac --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Fixtures/CustomArrayObject.php @@ -0,0 +1,70 @@ + + * + * 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; + +/** + * This class is a hand written simplified version of PHP native `ArrayObject` + * class, to show that it behaves differently than the PHP native implementation. + */ +class CustomArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable +{ + private $array; + + public function __construct(array $array = null) + { + $this->array = $array ?: array(); + } + + public function offsetExists($offset) + { + return array_key_exists($offset, $this->array); + } + + public function offsetGet($offset) + { + return $this->array[$offset]; + } + + public function offsetSet($offset, $value) + { + if (null === $offset) { + $this->array[] = $value; + } else { + $this->array[$offset] = $value; + } + } + + public function offsetUnset($offset) + { + unset($this->array[$offset]); + } + + public function getIterator() + { + return new \ArrayIterator($this->array); + } + + public function count() + { + return count($this->array); + } + + public function serialize() + { + return serialize($this->array); + } + + public function unserialize($serialized) + { + $this->array = (array) unserialize((string) $serialized); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/StubGlobalExecutionContext.php b/src/Symfony/Component/Validator/Tests/Fixtures/StubGlobalExecutionContext.php new file mode 100644 index 0000000000..e80c5e28b5 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Fixtures/StubGlobalExecutionContext.php @@ -0,0 +1,71 @@ + + * + * 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\ConstraintViolationList; +use Symfony\Component\Validator\GlobalExecutionContextInterface; +use Symfony\Component\Validator\ValidationVisitorInterface; + +/** + * @since 2.5.3 + * @author Bernhard Schussek + * + * @deprecated + */ +class StubGlobalExecutionContext implements GlobalExecutionContextInterface +{ + private $violations; + + private $root; + + private $visitor; + + function __construct($root = null, ValidationVisitorInterface $visitor = null) + { + $this->violations = new ConstraintViolationList(); + $this->root = $root; + $this->visitor = $visitor; + } + + public function getViolations() + { + return $this->violations; + } + + public function setRoot($root) + { + $this->root = $root; + } + + public function getRoot() + { + return $this->root; + } + + public function setVisitor(ValidationVisitorInterface $visitor) + { + $this->visitor = $visitor; + } + + public function getVisitor() + { + return $this->visitor; + } + + public function getValidatorFactory() + { + } + + public function getMetadataFactory() + { + } +} diff --git a/src/Symfony/Component/Validator/Tests/Validator/LegacyValidator2Dot5ApiTest.php b/src/Symfony/Component/Validator/Tests/Validator/LegacyValidator2Dot5ApiTest.php index d468eea5d8..4a30ba2ec6 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/LegacyValidator2Dot5ApiTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/LegacyValidator2Dot5ApiTest.php @@ -11,9 +11,9 @@ namespace Symfony\Component\Validator\Tests\Validator; -use Symfony\Component\Validator\ConstraintValidatorFactory; use Symfony\Component\Validator\Context\LegacyExecutionContextFactory; use Symfony\Component\Validator\DefaultTranslator; +use Symfony\Component\Validator\LegacyConstraintValidatorFactory; use Symfony\Component\Validator\MetadataFactoryInterface; use Symfony\Component\Validator\Validator\LegacyValidator; @@ -31,7 +31,8 @@ class LegacyValidator2Dot5ApiTest extends Abstract2Dot5ApiTest protected function createValidator(MetadataFactoryInterface $metadataFactory, array $objectInitializers = array()) { $contextFactory = new LegacyExecutionContextFactory($metadataFactory, new DefaultTranslator()); + $validatorFactory = new LegacyConstraintValidatorFactory(); - return new LegacyValidator($contextFactory, $metadataFactory, new ConstraintValidatorFactory(), $objectInitializers); + return new LegacyValidator($contextFactory, $metadataFactory, $validatorFactory, $objectInitializers); } } diff --git a/src/Symfony/Component/Validator/Tests/Validator/LegacyValidatorLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Validator/LegacyValidatorLegacyApiTest.php index af46ae3bdf..7ebcb028cc 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/LegacyValidatorLegacyApiTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/LegacyValidatorLegacyApiTest.php @@ -11,9 +11,9 @@ namespace Symfony\Component\Validator\Tests\Validator; -use Symfony\Component\Validator\ConstraintValidatorFactory; use Symfony\Component\Validator\Context\LegacyExecutionContextFactory; use Symfony\Component\Validator\DefaultTranslator; +use Symfony\Component\Validator\LegacyConstraintValidatorFactory; use Symfony\Component\Validator\MetadataFactoryInterface; use Symfony\Component\Validator\Validator\LegacyValidator; @@ -31,7 +31,8 @@ class LegacyValidatorLegacyApiTest extends AbstractLegacyApiTest protected function createValidator(MetadataFactoryInterface $metadataFactory, array $objectInitializers = array()) { $contextFactory = new LegacyExecutionContextFactory($metadataFactory, new DefaultTranslator()); + $validatorFactory = new LegacyConstraintValidatorFactory(); - return new LegacyValidator($contextFactory, $metadataFactory, new ConstraintValidatorFactory(), $objectInitializers); + return new LegacyValidator($contextFactory, $metadataFactory, $validatorFactory, $objectInitializers); } } diff --git a/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidator2Dot5ApiTest.php b/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidator2Dot5ApiTest.php index 0fdce741d8..6235fda902 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidator2Dot5ApiTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidator2Dot5ApiTest.php @@ -22,7 +22,8 @@ class RecursiveValidator2Dot5ApiTest extends Abstract2Dot5ApiTest protected function createValidator(MetadataFactoryInterface $metadataFactory, array $objectInitializers = array()) { $contextFactory = new ExecutionContextFactory(new DefaultTranslator()); + $validatorFactory = new ConstraintValidatorFactory(); - return new RecursiveValidator($contextFactory, $metadataFactory, new ConstraintValidatorFactory(), $objectInitializers); + return new RecursiveValidator($contextFactory, $metadataFactory, $validatorFactory, $objectInitializers); } } diff --git a/src/Symfony/Component/Validator/ValidatorBuilder.php b/src/Symfony/Component/Validator/ValidatorBuilder.php index 284f2a5b5b..684668fb8b 100644 --- a/src/Symfony/Component/Validator/ValidatorBuilder.php +++ b/src/Symfony/Component/Validator/ValidatorBuilder.php @@ -17,6 +17,7 @@ use Doctrine\Common\Annotations\Reader; use Doctrine\Common\Cache\ArrayCache; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Component\Validator\Context\ExecutionContextFactory; use Symfony\Component\Validator\Context\LegacyExecutionContextFactory; use Symfony\Component\Validator\Exception\InvalidArgumentException; use Symfony\Component\Validator\Exception\ValidatorException; @@ -379,7 +380,7 @@ class ValidatorBuilder implements ValidatorBuilderInterface $metadataFactory = new ClassMetadataFactory($loader, $this->metadataCache); } - $validatorFactory = $this->validatorFactory ?: new ConstraintValidatorFactory($this->propertyAccessor); + $validatorFactory = $this->validatorFactory; $translator = $this->translator ?: new DefaultTranslator(); $apiVersion = $this->apiVersion; @@ -390,15 +391,21 @@ class ValidatorBuilder implements ValidatorBuilderInterface } if (Validation::API_VERSION_2_4 === $apiVersion) { + $validatorFactory = $validatorFactory ?: new ConstraintValidatorFactory($this->propertyAccessor); + return new ValidatorV24($metadataFactory, $validatorFactory, $translator, $this->translationDomain, $this->initializers); } - $contextFactory = new LegacyExecutionContextFactory($metadataFactory, $translator, $this->translationDomain); - if (Validation::API_VERSION_2_5 === $apiVersion) { + $contextFactory = new ExecutionContextFactory($metadataFactory, $translator, $this->translationDomain); + $validatorFactory = $validatorFactory ?: new ConstraintValidatorFactory($this->propertyAccessor); + return new RecursiveValidator($contextFactory, $metadataFactory, $validatorFactory, $this->initializers); } + $contextFactory = new LegacyExecutionContextFactory($metadataFactory, $translator, $this->translationDomain); + $validatorFactory = $validatorFactory ?: new LegacyConstraintValidatorFactory($this->propertyAccessor); + return new LegacyValidator($contextFactory, $metadataFactory, $validatorFactory, $this->initializers); } }