diff --git a/src/Symfony/Component/Validator/ConstraintValidator.php b/src/Symfony/Component/Validator/ConstraintValidator.php index 201db0f230..fe3758f65b 100644 --- a/src/Symfony/Component/Validator/ConstraintValidator.php +++ b/src/Symfony/Component/Validator/ConstraintValidator.php @@ -32,4 +32,67 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface { $this->context = $context; } + + /** + * Returns a string representation of the type of the value. + * + * @param mixed $value + * + * @return string + */ + protected function valueToType($value) + { + return is_object($value) ? get_class($value) : gettype($value); + } + + /** + * Returns a string representation of the value. + * + * @param mixed $value + * + * @return string + */ + protected function valueToString($value) + { + if ($value instanceof \DateTime) { + if (class_exists('IntlDateFormatter')) { + $locale = \Locale::getDefault(); + $formatter = new \IntlDateFormatter($locale, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT); + + return $formatter->format($value); + } + + return $value->format('Y-m-d H:i:s'); + } + + if (is_object($value)) { + return 'Object('.get_class($value).')'; + } + + if (is_array($value)) { + return 'Array'; + } + + if (is_string($value)) { + return '"'.$value.'"'; + } + + if (is_resource($value)) { + return sprintf('Resource(%s#%d)', get_resource_type($value), $value); + } + + if (null === $value) { + return 'null'; + } + + if (false === $value) { + return 'false'; + } + + if (true === $value) { + return 'true'; + } + + return (string) $value; + } } diff --git a/src/Symfony/Component/Validator/ConstraintViolation.php b/src/Symfony/Component/Validator/ConstraintViolation.php index ddd14dbdc0..02b77be0bf 100644 --- a/src/Symfony/Component/Validator/ConstraintViolation.php +++ b/src/Symfony/Component/Validator/ConstraintViolation.php @@ -96,9 +96,9 @@ class ConstraintViolation implements ConstraintViolationInterface public function __toString() { if (is_object($this->root)) { - $class = get_class($this->root); + $class = 'Object('.get_class($this->root).')'; } elseif (is_array($this->root)) { - $class = "Array"; + $class = 'Array'; } else { $class = (string) $this->root; } diff --git a/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php b/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php index a561ddc759..351ce73491 100644 --- a/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php +++ b/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php @@ -39,34 +39,6 @@ abstract class AbstractComparisonValidator extends ConstraintValidator } } - /** - * Returns a string representation of the type of the value. - * - * @param mixed $value - * - * @return string - */ - private function valueToType($value) - { - return is_object($value) ? get_class($value) : gettype($value); - } - - /** - * Returns a string representation of the value. - * - * @param mixed $value - * - * @return string - */ - private function valueToString($value) - { - if ($value instanceof \DateTime) { - return $value->format('Y-m-d H:i:s'); - } - - return var_export($value, true); - } - /** * Compares the two given values to find if their relationship is valid * diff --git a/src/Symfony/Component/Validator/Constraints/BlankValidator.php b/src/Symfony/Component/Validator/Constraints/BlankValidator.php index 06064620f1..7bb57ddd0e 100644 --- a/src/Symfony/Component/Validator/Constraints/BlankValidator.php +++ b/src/Symfony/Component/Validator/Constraints/BlankValidator.php @@ -27,7 +27,9 @@ class BlankValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if ('' !== $value && null !== $value) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array( + '{{ value }}' => $this->valueToString($value) + )); } } } diff --git a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php index 1ece3fdd65..eae71a92d4 100644 --- a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php @@ -108,7 +108,9 @@ class CardSchemeValidator extends ConstraintValidator } if (!is_numeric($value)) { - $this->context->addViolation($constraint->message); + $this->context->addViolation($constraint->message, array( + '{{ value }}' => $this->valueToString($value), + )); return; } @@ -124,6 +126,8 @@ class CardSchemeValidator extends ConstraintValidator } } - $this->context->addViolation($constraint->message); + $this->context->addViolation($constraint->message, array( + '{{ value }}' => $value, + )); } } diff --git a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php index ef9ae6e3ad..c4f3b56c8b 100644 --- a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php @@ -59,25 +59,33 @@ class ChoiceValidator extends ConstraintValidator if ($constraint->multiple) { foreach ($value as $_value) { if (!in_array($_value, $choices, $constraint->strict)) { - $this->context->addViolation($constraint->multipleMessage, array('{{ value }}' => $_value)); + $this->context->addViolation($constraint->multipleMessage, array( + '{{ value }}' => $this->valueToString($_value), + )); } } $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 + ), null, (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 + ), null, (int) $constraint->max); return; } } elseif (!in_array($value, $choices, $constraint->strict)) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array( + '{{ value }}' => $this->valueToString($value) + )); } } } diff --git a/src/Symfony/Component/Validator/Constraints/CountryValidator.php b/src/Symfony/Component/Validator/Constraints/CountryValidator.php index 6a8d1d6446..c912a650a6 100644 --- a/src/Symfony/Component/Validator/Constraints/CountryValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CountryValidator.php @@ -42,7 +42,9 @@ class CountryValidator extends ConstraintValidator $countries = Intl::getRegionBundle()->getCountryNames(); if (!isset($countries[$value])) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array( + '{{ value }}' => $value, + )); } } } diff --git a/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php b/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php index 4451047cdd..d12952fc81 100644 --- a/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php @@ -42,7 +42,9 @@ class CurrencyValidator extends ConstraintValidator $currencies = Intl::getCurrencyBundle()->getCurrencyNames(); if (!isset($currencies[$value])) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array( + '{{ value }}' => $value, + )); } } } diff --git a/src/Symfony/Component/Validator/Constraints/DateValidator.php b/src/Symfony/Component/Validator/Constraints/DateValidator.php index 733a3b7f5e..1170314a70 100644 --- a/src/Symfony/Component/Validator/Constraints/DateValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateValidator.php @@ -40,7 +40,9 @@ class DateValidator extends ConstraintValidator $value = (string) $value; if (!preg_match(static::PATTERN, $value, $matches) || !checkdate($matches[2], $matches[3], $matches[1])) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array( + '{{ value }}' => $value, + )); } } } diff --git a/src/Symfony/Component/Validator/Constraints/EmailValidator.php b/src/Symfony/Component/Validator/Constraints/EmailValidator.php index e14546ce82..5b433a768f 100644 --- a/src/Symfony/Component/Validator/Constraints/EmailValidator.php +++ b/src/Symfony/Component/Validator/Constraints/EmailValidator.php @@ -50,7 +50,9 @@ class EmailValidator extends ConstraintValidator } if (!$valid) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array( + '{{ value }}' => $value, + )); } } diff --git a/src/Symfony/Component/Validator/Constraints/FileValidator.php b/src/Symfony/Component/Validator/Constraints/FileValidator.php index 5f499810e6..dce0480a0e 100644 --- a/src/Symfony/Component/Validator/Constraints/FileValidator.php +++ b/src/Symfony/Component/Validator/Constraints/FileValidator.php @@ -126,10 +126,10 @@ class FileValidator extends ConstraintValidator if ($size > $limit) { $this->context->addViolation($constraint->maxSizeMessage, array( - '{{ size }}' => $size, - '{{ limit }}' => $limit, - '{{ suffix }}' => $suffix, - '{{ file }}' => $path, + '{{ size }}' => $size, + '{{ limit }}' => $limit, + '{{ suffix }}' => $suffix, + '{{ file }}' => $path, )); return; @@ -161,9 +161,9 @@ class FileValidator extends ConstraintValidator if (false === $valid) { $this->context->addViolation($constraint->mimeTypesMessage, array( - '{{ type }}' => '"'.$mime.'"', - '{{ types }}' => '"'.implode('", "', $mimeTypes) .'"', - '{{ file }}' => $path, + '{{ type }}' => '"'.$mime.'"', + '{{ types }}' => '"'.implode('", "', $mimeTypes) .'"', + '{{ file }}' => $path, )); } } diff --git a/src/Symfony/Component/Validator/Constraints/IpValidator.php b/src/Symfony/Component/Validator/Constraints/IpValidator.php index 69afe61b71..ad5d9e2466 100644 --- a/src/Symfony/Component/Validator/Constraints/IpValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IpValidator.php @@ -91,7 +91,9 @@ class IpValidator extends ConstraintValidator } if (!filter_var($value, FILTER_VALIDATE_IP, $flag)) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array( + '{{ value }}' => $value, + )); } } } diff --git a/src/Symfony/Component/Validator/Constraints/LanguageValidator.php b/src/Symfony/Component/Validator/Constraints/LanguageValidator.php index 87019705db..02edb963f1 100644 --- a/src/Symfony/Component/Validator/Constraints/LanguageValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LanguageValidator.php @@ -42,7 +42,9 @@ class LanguageValidator extends ConstraintValidator $languages = Intl::getLanguageBundle()->getLanguageNames(); if (!isset($languages[$value])) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array( + '{{ value }}' => $value, + )); } } } diff --git a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php index daf594800b..cfd2105e90 100644 --- a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php @@ -42,7 +42,9 @@ class LocaleValidator extends ConstraintValidator $locales = Intl::getLocaleBundle()->getLocaleNames(); if (!isset($locales[$value])) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array( + '{{ value }}' => $value, + )); } } } diff --git a/src/Symfony/Component/Validator/Constraints/NullValidator.php b/src/Symfony/Component/Validator/Constraints/NullValidator.php index f0f09c492f..bc9bf4f38c 100644 --- a/src/Symfony/Component/Validator/Constraints/NullValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NullValidator.php @@ -33,7 +33,9 @@ class NullValidator extends ConstraintValidator $value = 'Array'; } - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array( + '{{ value }}' => $value, + )); } } } diff --git a/src/Symfony/Component/Validator/Constraints/RangeValidator.php b/src/Symfony/Component/Validator/Constraints/RangeValidator.php index 6f0ad51dba..fe79f54222 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 }}' => $value, + '{{ value }}' => $this->valueToString($value), )); return; diff --git a/src/Symfony/Component/Validator/Constraints/RegexValidator.php b/src/Symfony/Component/Validator/Constraints/RegexValidator.php index 1f2febbbca..f59d6a4e25 100644 --- a/src/Symfony/Component/Validator/Constraints/RegexValidator.php +++ b/src/Symfony/Component/Validator/Constraints/RegexValidator.php @@ -41,7 +41,9 @@ class RegexValidator extends ConstraintValidator $value = (string) $value; if ($constraint->match xor preg_match($constraint->pattern, $value)) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array( + '{{ value }}' => $value, + )); } } } diff --git a/src/Symfony/Component/Validator/Constraints/TimeValidator.php b/src/Symfony/Component/Validator/Constraints/TimeValidator.php index cbaa816d1a..36260e67d1 100644 --- a/src/Symfony/Component/Validator/Constraints/TimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TimeValidator.php @@ -40,7 +40,9 @@ class TimeValidator extends ConstraintValidator $value = (string) $value; if (!preg_match(static::PATTERN, $value)) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array( + '{{ value }}' => $value, + )); } } } diff --git a/src/Symfony/Component/Validator/Constraints/TypeValidator.php b/src/Symfony/Component/Validator/Constraints/TypeValidator.php index f75bb0fd8b..ff713ffeef 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 }}' => is_object($value) ? get_class($value) : (is_array($value) ? 'Array' : (string) $value), + '{{ value }}' => $this->valueToString($value), '{{ type }}' => $constraint->type, )); } diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index d743c3807f..4aeab117af 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -55,7 +55,9 @@ class UrlValidator extends ConstraintValidator $pattern = sprintf(static::PATTERN, implode('|', $constraint->protocols)); if (!preg_match($pattern, $value)) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array( + '{{ value }}' => $value, + )); } } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php index d72eaf23fa..c0ab0f7a53 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php @@ -29,6 +29,8 @@ abstract class AbstractComparisonValidatorTestCase extends \PHPUnit_Framework_Te ->disableOriginalConstructor() ->getMock(); $this->validator->initialize($this->context); + + \Locale::setDefault('en'); } /** @@ -75,7 +77,7 @@ abstract class AbstractComparisonValidatorTestCase extends \PHPUnit_Framework_Te * @param mixed $comparedValueString * @param string $comparedValueType */ - public function testInvalidComparisonToValue($dirtyValue, $comparedValue, $comparedValueString, $comparedValueType) + public function testInvalidComparisonToValue($dirtyValue, $dirtyValueAsString, $comparedValue, $comparedValueString, $comparedValueType) { $constraint = $this->createConstraint(array('value' => $comparedValue)); $constraint->message = 'Constraint Message'; @@ -87,7 +89,7 @@ abstract class AbstractComparisonValidatorTestCase extends \PHPUnit_Framework_Te $this->context->expects($this->once()) ->method('addViolation') ->with('Constraint Message', array( - '{{ value }}' => $comparedValueString, + '{{ value }}' => $dirtyValueAsString, '{{ compared_value }}' => $comparedValueString, '{{ compared_value_type }}' => $comparedValueType )); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php index 0fbe5e6fbb..fe4a30b638 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php @@ -51,7 +51,7 @@ class BlankValidatorTest extends \PHPUnit_Framework_TestCase /** * @dataProvider getInvalidValues */ - public function testInvalidValues($value) + public function testInvalidValues($value, $valueAsString) { $constraint = new Blank(array( 'message' => 'myMessage' @@ -60,7 +60,7 @@ class BlankValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => $value, + '{{ value }}' => $valueAsString, )); $this->validator->validate($value, $constraint); @@ -69,10 +69,10 @@ class BlankValidatorTest extends \PHPUnit_Framework_TestCase public function getInvalidValues() { return array( - array('foobar'), - array(0), - array(false), - array(1234), + array('foobar', '"foobar"'), + array(0, '0'), + array(false, 'false'), + array(1234, '1234'), ); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php index 9267fdb872..ad524b87ea 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php @@ -158,7 +158,7 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => 'baz', + '{{ value }}' => '"baz"', ), null, null); $this->validator->validate('baz', $constraint); @@ -175,7 +175,7 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => 'baz', + '{{ value }}' => '"baz"', )); $this->validator->validate(array('foo', 'baz'), $constraint); @@ -255,7 +255,7 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => '2', + '{{ value }}' => '"2"', )); $this->validator->validate('2', $constraint); @@ -287,7 +287,7 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - '{{ value }}' => '3', + '{{ value }}' => '"3"', )); $this->validator->validate(array(2, '3'), $constraint); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php index 45c9bd1dee..2cc624e7f3 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php @@ -49,9 +49,9 @@ class EqualToValidatorTest extends AbstractComparisonValidatorTestCase public function provideInvalidComparisons() { return array( - array(1, 2, '2', 'integer'), - array('22', '333', "'333'", 'string'), - array(new \DateTime('2001-01-01'), new \DateTime('2000-01-01'), '2000-01-01 00:00:00', 'DateTime') + array(1, '1', 2, '2', 'integer'), + array('22', '"22"', '333', '"333"', 'string'), + array(new \DateTime('2001-01-01'), 'Jan 1, 2001 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000 12:00 AM', 'DateTime') ); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php index 9393bec619..8dd27f7f4b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php @@ -51,9 +51,9 @@ class GreaterThanOrEqualValidatorTest extends AbstractComparisonValidatorTestCas public function provideInvalidComparisons() { return array( - array(1, 2, '2', 'integer'), - array(new \DateTime('2000/01/01'), new \DateTime('2005/01/01'), '2005-01-01 00:00:00', 'DateTime'), - array('b', 'c', "'c'", 'string') + array(1, '1', 2, '2', 'integer'), + array(new \DateTime('2000/01/01'), 'Jan 1, 2000 12:00 AM', new \DateTime('2005/01/01'), 'Jan 1, 2005 12:00 AM', 'DateTime'), + array('b', '"b"', 'c', '"c"', 'string') ); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php index 49c31727ff..e261c42c8b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php @@ -48,12 +48,12 @@ class GreaterThanValidatorTest extends AbstractComparisonValidatorTestCase public function provideInvalidComparisons() { return array( - array(1, 2, '2', 'integer'), - array(2, 2, '2', 'integer'), - array(new \DateTime('2000/01/01'), new \DateTime('2005/01/01'), '2005-01-01 00:00:00', 'DateTime'), - array(new \DateTime('2000/01/01'), new \DateTime('2000/01/01'), '2000-01-01 00:00:00', 'DateTime'), - array('22', '333', "'333'", 'string'), - array('22', '22', "'22'", 'string') + array(1, '1', 2, '2', 'integer'), + array(2, '2', 2, '2', 'integer'), + array(new \DateTime('2000/01/01'), 'Jan 1, 2000 12:00 AM', new \DateTime('2005/01/01'), 'Jan 1, 2005 12:00 AM', 'DateTime'), + array(new \DateTime('2000/01/01'), 'Jan 1, 2000 12:00 AM', new \DateTime('2000/01/01'), 'Jan 1, 2000 12:00 AM', 'DateTime'), + array('22', '"22"', '333', '"333"', 'string'), + array('22', '"22"', '22', '"22"', 'string') ); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php index ede2e43e7e..02f166c7cb 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php @@ -50,11 +50,11 @@ class IdenticalToValidatorTest extends AbstractComparisonValidatorTestCase public function provideInvalidComparisons() { return array( - array(1, 2, '2', 'integer'), - array(2, '2', "'2'", 'string'), - array('22', '333', "'333'", 'string'), - array(new \DateTime('2001-01-01'), new \DateTime('2001-01-01'), '2001-01-01 00:00:00', 'DateTime'), - array(new \DateTime('2001-01-01'), new \DateTime('1999-01-01'), '1999-01-01 00:00:00', 'DateTime') + array(1, '1', 2, '2', 'integer'), + array(2, '2', '2', '"2"', 'string'), + array('22', '"22"', '333', '"333"', 'string'), + array(new \DateTime('2001-01-01'), 'Jan 1, 2001 12:00 AM', new \DateTime('2001-01-01'), 'Jan 1, 2001 12:00 AM', 'DateTime'), + array(new \DateTime('2001-01-01'), 'Jan 1, 2001 12:00 AM', new \DateTime('1999-01-01'), 'Jan 1, 1999 12:00 AM', 'DateTime') ); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php index 9eca353e48..e2ce1bcbc1 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php @@ -51,9 +51,9 @@ class LessThanOrEqualValidatorTest extends AbstractComparisonValidatorTestCase public function provideInvalidComparisons() { return array( - array(2, 1, '1', 'integer'), - array(new \DateTime('2010-01-01'), new \DateTime('2000-01-01'), '2000-01-01 00:00:00', 'DateTime'), - array('c', 'b', "'b'", 'string') + array(2, '2', 1, '1', 'integer'), + array(new \DateTime('2010-01-01'), 'Jan 1, 2010 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000 12:00 AM', 'DateTime'), + array('c', '"c"', 'b', '"b"', 'string') ); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php index daee667254..9e88ac1e2b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php @@ -48,11 +48,11 @@ class LessThanValidatorTest extends AbstractComparisonValidatorTestCase public function provideInvalidComparisons() { return array( - array(3, 2, '2', 'integer'), - array(2, 2, '2', 'integer'), - array(new \DateTime('2010-01-01'), new \DateTime('2000-01-01'), '2000-01-01 00:00:00', 'DateTime'), - array(new \DateTime('2000-01-01'), new \DateTime('2000-01-01'), '2000-01-01 00:00:00', 'DateTime'), - array('333', '22', "'22'", 'string'), + array(3, '3', 2, '2', 'integer'), + array(2, '2', 2, '2', 'integer'), + array(new \DateTime('2010-01-01'), 'Jan 1, 2010 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000 12:00 AM', 'DateTime'), + array(new \DateTime('2000-01-01'), 'Jan 1, 2000 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000 12:00 AM', 'DateTime'), + array('333', '"333"', '22', '"22"', 'string'), ); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php index ecf89d79de..334aeb219a 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php @@ -48,10 +48,10 @@ class NotEqualToValidatorTest extends AbstractComparisonValidatorTestCase public function provideInvalidComparisons() { return array( - array(3, 3, '3', 'integer'), - array('2', 2, '2', 'integer'), - array('a', 'a', "'a'", 'string'), - array(new \DateTime('2000-01-01'), new \DateTime('2000-01-01'), '2000-01-01 00:00:00', 'DateTime') + array(3, '3', 3, '3', 'integer'), + array('2', '"2"', 2, '2', 'integer'), + array('a', '"a"', 'a', '"a"', 'string'), + array(new \DateTime('2000-01-01'), 'Jan 1, 2000 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000 12:00 AM', 'DateTime') ); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php index 6b518c92a9..406a10163f 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php @@ -52,9 +52,9 @@ class NotIdenticalToValidatorTest extends AbstractComparisonValidatorTestCase $date = new \DateTime('2000-01-01'); return array( - array(3, 3, '3', 'integer'), - array('a', 'a', "'a'", 'string'), - array($date, $date, '2000-01-01 00:00:00', 'DateTime') + array(3, '3', 3, '3', 'integer'), + array('a', '"a"', 'a', '"a"', 'string'), + array($date, 'Jan 1, 2000 12:00 AM', $date, 'Jan 1, 2000 12:00 AM', 'DateTime') ); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php index e5e6d0bf02..57d7f5c4c4 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php @@ -132,36 +132,37 @@ class TypeValidatorTest extends \PHPUnit_Framework_TestCase { $object = new \stdClass(); $file = $this->createFile(); + $fileAsString = 'Resource(stream#'.intval($file).')'; return array( - array('foobar', 'numeric', 'foobar'), - array('foobar', 'boolean', 'foobar'), - array('0', 'integer', '0'), - array('1.5', 'float', '1.5'), + array('foobar', 'numeric', '"foobar"'), + array('foobar', 'boolean', '"foobar"'), + array('0', 'integer', '"0"'), + array('1.5', 'float', '"1.5"'), array(12345, 'string', '12345'), - array($object, 'boolean', 'stdClass'), - array($object, 'numeric', 'stdClass'), - array($object, 'integer', 'stdClass'), - array($object, 'float', 'stdClass'), - array($object, 'string', 'stdClass'), - array($object, 'resource', 'stdClass'), - array($file, 'boolean', (string) $file), - array($file, 'numeric', (string) $file), - array($file, 'integer', (string) $file), - array($file, 'float', (string) $file), - array($file, 'string', (string) $file), - array($file, 'object', (string) $file), - array('12a34', 'digit', '12a34'), - array('1a#23', 'alnum', '1a#23'), - array('abcd1', 'alpha', 'abcd1'), - array("\nabc", 'cntrl', "\nabc"), - array("abc\n", 'graph', "abc\n"), - array('abCDE', 'lower', 'abCDE'), - array('ABcde', 'upper', 'ABcde'), - array("\nabc", 'print', "\nabc"), - array('abc&$!', 'punct', 'abc&$!'), - array("\nabc", 'space', "\nabc"), - array('AR1012', 'xdigit', 'AR1012'), + array($object, 'boolean', 'Object(stdClass)'), + array($object, 'numeric', 'Object(stdClass)'), + array($object, 'integer', 'Object(stdClass)'), + array($object, 'float', 'Object(stdClass)'), + array($object, 'string', 'Object(stdClass)'), + array($object, 'resource', 'Object(stdClass)'), + array($file, 'boolean', $fileAsString), + array($file, 'numeric', $fileAsString), + array($file, 'integer', $fileAsString), + array($file, 'float', $fileAsString), + array($file, 'string', $fileAsString), + array($file, 'object', $fileAsString), + array('12a34', 'digit', '"12a34"'), + array('1a#23', 'alnum', '"1a#23"'), + array('abcd1', 'alpha', '"abcd1"'), + array("\nabc", 'cntrl', "\"\nabc\""), + array("abc\n", 'graph', "\"abc\n\""), + array('abCDE', 'lower', '"abCDE"'), + array('ABcde', 'upper', '"ABcde"'), + array("\nabc", 'print', "\"\nabc\""), + array('abc&$!', 'punct', '"abc&$!"'), + array("\nabc", 'space', "\"\nabc\""), + array('AR1012', 'xdigit', '"AR1012"'), ); }