diff --git a/src/Symfony/Component/Validator/ConstraintValidator.php b/src/Symfony/Component/Validator/ConstraintValidator.php index 0cf50916df..bb3378cd93 100644 --- a/src/Symfony/Component/Validator/ConstraintValidator.php +++ b/src/Symfony/Component/Validator/ConstraintValidator.php @@ -40,7 +40,7 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface * * @return string */ - protected function valueToType($value) + protected function formatTypeOf($value) { return is_object($value) ? get_class($value) : gettype($value); } @@ -49,13 +49,13 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface * Returns a string representation of the value. * * @param mixed $value - * @param bool $formatDates + * @param bool $prettyDateTime * * @return string */ - protected function valueToString($value, $formatDates = false) + protected function formatValue($value, $prettyDateTime = false) { - if ($formatDates && $value instanceof \DateTime) { + if ($prettyDateTime && $value instanceof \DateTime) { if (class_exists('IntlDateFormatter')) { $locale = \Locale::getDefault(); $formatter = new \IntlDateFormatter($locale, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT); @@ -101,14 +101,14 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface * Returns a string representation of a list of values. * * @param array $values - * @param bool $formatDates + * @param bool $prettyDateTime * * @return string */ - protected function valuesToString(array $values, $formatDates = false) + protected function formatValues(array $values, $prettyDateTime = false) { foreach ($values as $key => $value) { - $values[$key] = $this->valueToString($value, $formatDates); + $values[$key] = $this->formatValue($value, $prettyDateTime); } return implode(', ', $values); diff --git a/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php b/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php index 7beebf703c..d2b15f2162 100644 --- a/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php +++ b/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php @@ -32,9 +32,9 @@ abstract class AbstractComparisonValidator extends ConstraintValidator if (!$this->compareValues($value, $constraint->value)) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $this->valueToString($value, true), - '{{ compared_value }}' => $this->valueToString($constraint->value, true), - '{{ compared_value_type }}' => $this->valueToType($constraint->value) + '{{ value }}' => $this->formatValue($value, true), + '{{ compared_value }}' => $this->formatValue($constraint->value, true), + '{{ compared_value_type }}' => $this->formatTypeOf($constraint->value) )); } } diff --git a/src/Symfony/Component/Validator/Constraints/BlankValidator.php b/src/Symfony/Component/Validator/Constraints/BlankValidator.php index 7bb57ddd0e..e8406a238e 100644 --- a/src/Symfony/Component/Validator/Constraints/BlankValidator.php +++ b/src/Symfony/Component/Validator/Constraints/BlankValidator.php @@ -28,7 +28,7 @@ class BlankValidator extends ConstraintValidator { if ('' !== $value && null !== $value) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $this->valueToString($value) + '{{ value }}' => $this->formatValue($value) )); } } diff --git a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php index eae71a92d4..73f602adce 100644 --- a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php @@ -109,7 +109,7 @@ class CardSchemeValidator extends ConstraintValidator if (!is_numeric($value)) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $this->valueToString($value), + '{{ value }}' => $this->formatValue($value), )); return; @@ -127,7 +127,7 @@ class CardSchemeValidator extends ConstraintValidator } $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php index c4f3b56c8b..2e0658cfa6 100644 --- a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php @@ -60,7 +60,7 @@ class ChoiceValidator extends ConstraintValidator foreach ($value as $_value) { if (!in_array($_value, $choices, $constraint->strict)) { $this->context->addViolation($constraint->multipleMessage, array( - '{{ value }}' => $this->valueToString($_value), + '{{ value }}' => $this->formatValue($_value), )); } } @@ -84,7 +84,7 @@ class ChoiceValidator extends ConstraintValidator } } elseif (!in_array($value, $choices, $constraint->strict)) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $this->valueToString($value) + '{{ value }}' => $this->formatValue($value) )); } } diff --git a/src/Symfony/Component/Validator/Constraints/CollectionValidator.php b/src/Symfony/Component/Validator/Constraints/CollectionValidator.php index 538ff7e346..a322ef49ad 100644 --- a/src/Symfony/Component/Validator/Constraints/CollectionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CollectionValidator.php @@ -48,7 +48,7 @@ class CollectionValidator extends ConstraintValidator } } elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) { $this->context->addViolationAt('['.$field.']', $constraint->missingFieldsMessage, array( - '{{ field }}' => $field + '{{ field }}' => $this->formatValue($field) ), null); } } @@ -57,7 +57,7 @@ class CollectionValidator extends ConstraintValidator foreach ($value as $field => $fieldValue) { if (!isset($constraint->fields[$field])) { $this->context->addViolationAt('['.$field.']', $constraint->extraFieldsMessage, array( - '{{ field }}' => $field + '{{ field }}' => $this->formatValue($field) ), $fieldValue); } } diff --git a/src/Symfony/Component/Validator/Constraints/CountryValidator.php b/src/Symfony/Component/Validator/Constraints/CountryValidator.php index c912a650a6..a094c10481 100644 --- a/src/Symfony/Component/Validator/Constraints/CountryValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CountryValidator.php @@ -43,7 +43,7 @@ class CountryValidator extends ConstraintValidator if (!isset($countries[$value])) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php b/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php index d12952fc81..d8c999af4d 100644 --- a/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php @@ -43,7 +43,7 @@ class CurrencyValidator extends ConstraintValidator if (!isset($currencies[$value])) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/DateValidator.php b/src/Symfony/Component/Validator/Constraints/DateValidator.php index 1170314a70..5e5250852f 100644 --- a/src/Symfony/Component/Validator/Constraints/DateValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateValidator.php @@ -41,7 +41,7 @@ class DateValidator extends ConstraintValidator if (!preg_match(static::PATTERN, $value, $matches) || !checkdate($matches[2], $matches[3], $matches[1])) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/EmailValidator.php b/src/Symfony/Component/Validator/Constraints/EmailValidator.php index 5b433a768f..b3789a130d 100644 --- a/src/Symfony/Component/Validator/Constraints/EmailValidator.php +++ b/src/Symfony/Component/Validator/Constraints/EmailValidator.php @@ -51,7 +51,7 @@ class EmailValidator extends ConstraintValidator if (!$valid) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/FalseValidator.php b/src/Symfony/Component/Validator/Constraints/FalseValidator.php index 76e370f348..280deba3c9 100644 --- a/src/Symfony/Component/Validator/Constraints/FalseValidator.php +++ b/src/Symfony/Component/Validator/Constraints/FalseValidator.php @@ -31,7 +31,7 @@ class FalseValidator extends ConstraintValidator } $this->context->addViolation($constraint->message, array( - '{{ value }}' => $this->valueToString($value), + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/FileValidator.php b/src/Symfony/Component/Validator/Constraints/FileValidator.php index 24e64f9ee9..006064594b 100644 --- a/src/Symfony/Component/Validator/Constraints/FileValidator.php +++ b/src/Symfony/Component/Validator/Constraints/FileValidator.php @@ -96,13 +96,17 @@ class FileValidator extends ConstraintValidator $path = $value instanceof FileObject ? $value->getPathname() : (string) $value; if (!is_file($path)) { - $this->context->addViolation($constraint->notFoundMessage, array('{{ file }}' => $path)); + $this->context->addViolation($constraint->notFoundMessage, array( + '{{ file }}' => $this->formatValue($path) + )); return; } if (!is_readable($path)) { - $this->context->addViolation($constraint->notReadableMessage, array('{{ file }}' => $path)); + $this->context->addViolation($constraint->notReadableMessage, array( + '{{ file }}' => $this->formatValue($path) + )); return; } @@ -129,7 +133,7 @@ class FileValidator extends ConstraintValidator '{{ size }}' => $size, '{{ limit }}' => $limit, '{{ suffix }}' => $suffix, - '{{ file }}' => $path, + '{{ file }}' => $this->formatValue($path), )); return; @@ -161,9 +165,9 @@ class FileValidator extends ConstraintValidator if (false === $valid) { $this->context->addViolation($constraint->mimeTypesMessage, array( - '{{ type }}' => $this->valueToString($mime), - '{{ types }}' => $this->valuesToString($mimeTypes), - '{{ file }}' => $path, + '{{ type }}' => $this->formatValue($mime), + '{{ types }}' => $this->formatValues($mimeTypes), + '{{ file }}' => $this->formatValue($path), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/IbanValidator.php b/src/Symfony/Component/Validator/Constraints/IbanValidator.php index 615518883b..699db7ea7a 100644 --- a/src/Symfony/Component/Validator/Constraints/IbanValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IbanValidator.php @@ -36,12 +36,14 @@ class IbanValidator extends ConstraintValidator throw new UnexpectedTypeException($value, 'string'); } + $value = (string) $value; + // Remove spaces $canonicalized = str_replace(' ', '', $value); if (strlen($canonicalized) < 4) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); return; @@ -52,7 +54,7 @@ class IbanValidator extends ConstraintValidator if (strlen($canonicalized) < 4 || !ctype_upper($canonicalized{0}) || !ctype_upper($canonicalized{1}) || !ctype_alnum($canonicalized)) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); return; @@ -72,7 +74,7 @@ class IbanValidator extends ConstraintValidator if (false === $checkSum) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); return; @@ -83,7 +85,7 @@ class IbanValidator extends ConstraintValidator // modulo step-wisely instead if (1 !== $this->bigModulo97($checkSum)) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); return; diff --git a/src/Symfony/Component/Validator/Constraints/IpValidator.php b/src/Symfony/Component/Validator/Constraints/IpValidator.php index ad5d9e2466..5ebda4e9e2 100644 --- a/src/Symfony/Component/Validator/Constraints/IpValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IpValidator.php @@ -92,7 +92,7 @@ class IpValidator extends ConstraintValidator if (!filter_var($value, FILTER_VALIDATE_IP, $flag)) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/IsbnValidator.php b/src/Symfony/Component/Validator/Constraints/IsbnValidator.php index 0e79c3289a..5fee10e718 100644 --- a/src/Symfony/Component/Validator/Constraints/IsbnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IsbnValidator.php @@ -51,15 +51,15 @@ class IsbnValidator extends ConstraintValidator if ($constraint->isbn10 && $constraint->isbn13) { $this->context->addViolation($constraint->bothIsbnMessage, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } elseif ($constraint->isbn10) { $this->context->addViolation($constraint->isbn10Message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } else { $this->context->addViolation($constraint->isbn13Message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/IssnValidator.php b/src/Symfony/Component/Validator/Constraints/IssnValidator.php index 2ae70ec2f3..301b40d2d9 100644 --- a/src/Symfony/Component/Validator/Constraints/IssnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IssnValidator.php @@ -46,7 +46,7 @@ class IssnValidator extends ConstraintValidator if (!preg_match($pattern, $value)) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); return; @@ -64,7 +64,7 @@ class IssnValidator extends ConstraintValidator if (0 !== $checkSum % 11) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/LanguageValidator.php b/src/Symfony/Component/Validator/Constraints/LanguageValidator.php index 02edb963f1..8b048b8a48 100644 --- a/src/Symfony/Component/Validator/Constraints/LanguageValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LanguageValidator.php @@ -43,7 +43,7 @@ class LanguageValidator extends ConstraintValidator if (!isset($languages[$value])) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/LengthValidator.php b/src/Symfony/Component/Validator/Constraints/LengthValidator.php index 8dc68483c8..ceccde5a61 100644 --- a/src/Symfony/Component/Validator/Constraints/LengthValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LengthValidator.php @@ -45,7 +45,7 @@ class LengthValidator extends ConstraintValidator if ($constraint->min == $constraint->max && $length != $constraint->min) { $this->context->addViolation($constraint->exactMessage, array( - '{{ value }}' => $stringValue, + '{{ value }}' => $this->formatValue($stringValue), '{{ limit }}' => $constraint->min, ), $value, (int) $constraint->min); @@ -54,7 +54,7 @@ class LengthValidator extends ConstraintValidator if (null !== $constraint->max && $length > $constraint->max) { $this->context->addViolation($constraint->maxMessage, array( - '{{ value }}' => $stringValue, + '{{ value }}' => $this->formatValue($stringValue), '{{ limit }}' => $constraint->max, ), $value, (int) $constraint->max); @@ -63,7 +63,7 @@ class LengthValidator extends ConstraintValidator if (null !== $constraint->min && $length < $constraint->min) { $this->context->addViolation($constraint->minMessage, array( - '{{ value }}' => $stringValue, + '{{ value }}' => $this->formatValue($stringValue), '{{ limit }}' => $constraint->min, ), $value, (int) $constraint->min); } diff --git a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php index cfd2105e90..1d887d58f0 100644 --- a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php @@ -43,7 +43,7 @@ class LocaleValidator extends ConstraintValidator if (!isset($locales[$value])) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/LuhnValidator.php b/src/Symfony/Component/Validator/Constraints/LuhnValidator.php index 4a59e9559d..1cc7a7b22f 100644 --- a/src/Symfony/Component/Validator/Constraints/LuhnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LuhnValidator.php @@ -50,7 +50,7 @@ class LuhnValidator extends ConstraintValidator if (!ctype_digit($value)) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); return; @@ -80,7 +80,7 @@ class LuhnValidator extends ConstraintValidator if (0 === $checkSum || 0 !== $checkSum % 10) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php b/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php index 20675a8da9..945803348b 100644 --- a/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php @@ -28,7 +28,7 @@ class NotBlankValidator extends ConstraintValidator { if (false === $value || (empty($value) && '0' != $value)) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $this->valueToString($value), + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/NullValidator.php b/src/Symfony/Component/Validator/Constraints/NullValidator.php index 8698585ffd..9c5deb36e7 100644 --- a/src/Symfony/Component/Validator/Constraints/NullValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NullValidator.php @@ -28,7 +28,7 @@ class NullValidator extends ConstraintValidator { if (null !== $value) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $this->valueToString($value), + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/RangeValidator.php b/src/Symfony/Component/Validator/Constraints/RangeValidator.php index fe79f54222..c2df195b81 100644 --- a/src/Symfony/Component/Validator/Constraints/RangeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/RangeValidator.php @@ -30,7 +30,7 @@ class RangeValidator extends ConstraintValidator if (!is_numeric($value)) { $this->context->addViolation($constraint->invalidMessage, array( - '{{ value }}' => $this->valueToString($value), + '{{ value }}' => $this->formatValue($value), )); return; diff --git a/src/Symfony/Component/Validator/Constraints/RegexValidator.php b/src/Symfony/Component/Validator/Constraints/RegexValidator.php index f59d6a4e25..88ea8ae05b 100644 --- a/src/Symfony/Component/Validator/Constraints/RegexValidator.php +++ b/src/Symfony/Component/Validator/Constraints/RegexValidator.php @@ -42,7 +42,7 @@ class RegexValidator extends ConstraintValidator if ($constraint->match xor preg_match($constraint->pattern, $value)) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/TimeValidator.php b/src/Symfony/Component/Validator/Constraints/TimeValidator.php index 36260e67d1..a7c2b27ad0 100644 --- a/src/Symfony/Component/Validator/Constraints/TimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TimeValidator.php @@ -41,7 +41,7 @@ class TimeValidator extends ConstraintValidator if (!preg_match(static::PATTERN, $value)) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/TrueValidator.php b/src/Symfony/Component/Validator/Constraints/TrueValidator.php index 69495dd6a3..480230a909 100644 --- a/src/Symfony/Component/Validator/Constraints/TrueValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TrueValidator.php @@ -32,7 +32,7 @@ class TrueValidator extends ConstraintValidator if (true !== $value && 1 !== $value && '1' !== $value) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $this->valueToString($value), + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Constraints/TypeValidator.php b/src/Symfony/Component/Validator/Constraints/TypeValidator.php index ff713ffeef..237546a5b9 100644 --- a/src/Symfony/Component/Validator/Constraints/TypeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TypeValidator.php @@ -44,7 +44,7 @@ class TypeValidator extends ConstraintValidator } $this->context->addViolation($constraint->message, array( - '{{ value }}' => $this->valueToString($value), + '{{ value }}' => $this->formatValue($value), '{{ type }}' => $constraint->type, )); } diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index 4aeab117af..748f824894 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -51,12 +51,11 @@ class UrlValidator extends ConstraintValidator } $value = (string) $value; - $pattern = sprintf(static::PATTERN, implode('|', $constraint->protocols)); if (!preg_match($pattern, $value)) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $this->formatValue($value), )); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php index 4a13234b69..e966aadae7 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php @@ -147,7 +147,7 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolationAt') ->with('[baz]', 'myMessage', array( - '{{ field }}' => 'baz' + '{{ field }}' => '"baz"' )); $this->validator->validate($data, new Collection(array( @@ -211,7 +211,7 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolationAt') ->with('[foo]', 'myMessage', array( - '{{ field }}' => 'foo', + '{{ field }}' => '"foo"', )); $this->validator->validate($data, $constraint); @@ -331,7 +331,7 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolationAt') ->with('[foo]', 'myMessage', array( - '{{ field }}' => 'foo', + '{{ field }}' => '"foo"', )); $this->validator->validate($data, new Collection(array( diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php index 0776848fdb..46079a8155 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php @@ -96,7 +96,7 @@ class DateTimeValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $dateTime, + '{{ value }}' => '"'.$dateTime.'"', )); $this->validator->validate($dateTime, $constraint); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php index b9cf8816b7..a62426ec8a 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php @@ -96,7 +96,7 @@ class DateValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $date, + '{{ value }}' => '"'.$date.'"', )); $this->validator->validate($date, $constraint); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php index 701ab1f556..4b7a8bd6c3 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php @@ -88,7 +88,7 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $email, + '{{ value }}' => '"'.$email.'"', )); $this->validator->validate($email, $constraint); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php index c4b93cdcd3..7701d7faf4 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php @@ -29,7 +29,7 @@ class FileValidatorPathTest extends FileValidatorTest $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ file }}' => 'foobar', + '{{ file }}' => '"foobar"', )); $this->validator->validate('foobar', $constraint); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php index fcbbb04b83..47952f061c 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php @@ -101,7 +101,7 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase '{{ limit }}' => '10', '{{ size }}' => '11', '{{ suffix }}' => 'bytes', - '{{ file }}' => $this->path, + '{{ file }}' => '"'.$this->path.'"', )); $this->validator->validate($this->getFile($this->path), $constraint); @@ -122,7 +122,7 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase '{{ limit }}' => '1', '{{ size }}' => '1.4', '{{ suffix }}' => 'kB', - '{{ file }}' => $this->path, + '{{ file }}' => '"'.$this->path.'"', )); $this->validator->validate($this->getFile($this->path), $constraint); @@ -143,7 +143,7 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase '{{ limit }}' => '1', '{{ size }}' => '1.4', '{{ suffix }}' => 'MB', - '{{ file }}' => $this->path, + '{{ file }}' => '"'.$this->path.'"', )); $this->validator->validate($this->getFile($this->path), $constraint); @@ -245,7 +245,7 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase ->with('myMessage', array( '{{ type }}' => '"application/pdf"', '{{ types }}' => '"image/png", "image/jpg"', - '{{ file }}' => $this->path, + '{{ file }}' => '"'.$this->path.'"', )); $this->validator->validate($file, $constraint); @@ -279,7 +279,7 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase ->with('myMessage', array( '{{ type }}' => '"application/pdf"', '{{ types }}' => '"image/*", "image/jpg"', - '{{ file }}' => $this->path, + '{{ file }}' => '"'.$this->path.'"', )); $this->validator->validate($file, $constraint); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php index cf0802fed2..49b3943017 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php @@ -164,7 +164,7 @@ class IbanValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $iban, + '{{ value }}' => '"'.$iban.'"', )); $this->validator->validate($iban, $constraint); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php index bdf6192880..25cd5d44f8 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php @@ -162,7 +162,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $ip, + '{{ value }}' => '"'.$ip.'"', )); $this->validator->validate($ip, $constraint); @@ -196,7 +196,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $ip, + '{{ value }}' => '"'.$ip.'"', )); $this->validator->validate($ip, $constraint); @@ -224,7 +224,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $ip, + '{{ value }}' => '"'.$ip.'"', )); $this->validator->validate($ip, $constraint); @@ -252,7 +252,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $ip, + '{{ value }}' => '"'.$ip.'"', )); $this->validator->validate($ip, $constraint); @@ -276,7 +276,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $ip, + '{{ value }}' => '"'.$ip.'"', )); $this->validator->validate($ip, $constraint); @@ -314,7 +314,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $ip, + '{{ value }}' => '"'.$ip.'"', )); $this->validator->validate($ip, $constraint); @@ -342,7 +342,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $ip, + '{{ value }}' => '"'.$ip.'"', )); $this->validator->validate($ip, $constraint); @@ -369,7 +369,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $ip, + '{{ value }}' => '"'.$ip.'"', )); $this->validator->validate($ip, $constraint); @@ -393,7 +393,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $ip, + '{{ value }}' => '"'.$ip.'"', )); $this->validator->validate($ip, $constraint); @@ -417,7 +417,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $ip, + '{{ value }}' => '"'.$ip.'"', )); $this->validator->validate($ip, $constraint); @@ -441,7 +441,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $ip, + '{{ value }}' => '"'.$ip.'"', )); $this->validator->validate($ip, $constraint); @@ -465,7 +465,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $ip, + '{{ value }}' => '"'.$ip.'"', )); $this->validator->validate($ip, $constraint); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php index db6339449d..267f05b1b6 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php @@ -167,7 +167,7 @@ class LengthValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', $this->identicalTo(array( - '{{ value }}' => (string) $value, + '{{ value }}' => '"'.$value.'"', '{{ limit }}' => 4, )), $this->identicalTo($value), 4); @@ -191,7 +191,7 @@ class LengthValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', $this->identicalTo(array( - '{{ value }}' => (string) $value, + '{{ value }}' => '"'.$value.'"', '{{ limit }}' => 4, )), $this->identicalTo($value), 4); @@ -216,7 +216,7 @@ class LengthValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', $this->identicalTo(array( - '{{ value }}' => (string) $value, + '{{ value }}' => '"'.$value.'"', '{{ limit }}' => 4, )), $this->identicalTo($value), 4); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php index c44b0ea6ce..f7601de797 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php @@ -234,4 +234,19 @@ class RangeValidatorTest extends \PHPUnit_Framework_TestCase $this->validator->validate(21, $constraint); } + + public function testNonNumeric() + { + $this->context->expects($this->once()) + ->method('addViolation') + ->with('myMessage', array( + '{{ value }}' => '"abcd"', + )); + + $this->validator->validate('abcd', new Range(array( + 'min' => 10, + 'max' => 20, + 'invalidMessage' => 'myMessage', + ))); + } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php index 1ea79fb8e2..25b5006c33 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php @@ -91,7 +91,7 @@ class RegexValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $value, + '{{ value }}' => '"'.$value.'"', )); $this->validator->validate($value, $constraint); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php index ba398ab373..cfa24b80c7 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php @@ -96,7 +96,7 @@ class TimeValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $time, + '{{ value }}' => '"'.$time.'"', )); $this->validator->validate($time, $constraint); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php index 1cf4bb4d22..ac2cf9e360 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php @@ -131,7 +131,7 @@ class UrlValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $url, + '{{ value }}' => '"'.$url.'"', )); $this->validator->validate($url, $constraint);