[Validator] Fixed date-to-string conversion tests to match ICU 51

This commit is contained in:
Bernhard Schussek 2014-05-22 10:30:24 +02:00
parent 5aa7e6dbe0
commit cea4155d39
11 changed files with 38 additions and 13 deletions

View File

@ -96,4 +96,21 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
return (string) $value; return (string) $value;
} }
/**
* Returns a string representation of a list of values.
*
* @param array $values
* @param Boolean $formatDates
*
* @return string
*/
protected function valuesToString(array $values, $formatDates = false)
{
foreach ($values as $key => $value) {
$values[$key] = $this->valueToString($value, $formatDates);
}
return implode(', ', $values);
}
} }

View File

@ -161,8 +161,8 @@ class FileValidator extends ConstraintValidator
if (false === $valid) { if (false === $valid) {
$this->context->addViolation($constraint->mimeTypesMessage, array( $this->context->addViolation($constraint->mimeTypesMessage, array(
'{{ type }}' => '"'.$mime.'"', '{{ type }}' => $this->valueToString($mime),
'{{ types }}' => '"'.implode('", "', $mimeTypes) .'"', '{{ types }}' => $this->valuesToString($mimeTypes),
'{{ file }}' => $path, '{{ file }}' => $path,
)); ));
} }

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Validator\Tests\Constraints; namespace Symfony\Component\Validator\Tests\Constraints;
use Symfony\Component\Intl\Util\IntlTestHelper;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\AbstractComparisonValidator; use Symfony\Component\Validator\Constraints\AbstractComparisonValidator;
@ -73,12 +74,19 @@ abstract class AbstractComparisonValidatorTestCase extends \PHPUnit_Framework_Te
/** /**
* @dataProvider provideInvalidComparisons * @dataProvider provideInvalidComparisons
* @param mixed $dirtyValue * @param mixed $dirtyValue
* @param mixed $dirtyValueAsString
* @param mixed $comparedValue * @param mixed $comparedValue
* @param mixed $comparedValueString * @param mixed $comparedValueString
* @param string $comparedValueType * @param string $comparedValueType
*/ */
public function testInvalidComparisonToValue($dirtyValue, $dirtyValueAsString, $comparedValue, $comparedValueString, $comparedValueType) public function testInvalidComparisonToValue($dirtyValue, $dirtyValueAsString, $comparedValue, $comparedValueString, $comparedValueType)
{ {
// Conversion of dates to string differs between ICU versions
// Make sure we have the correct version loaded
if ($dirtyValue instanceof \DateTime) {
IntlTestHelper::requireIntl($this);
}
$constraint = $this->createConstraint(array('value' => $comparedValue)); $constraint = $this->createConstraint(array('value' => $comparedValue));
$constraint->message = 'Constraint Message'; $constraint->message = 'Constraint Message';

View File

@ -51,7 +51,7 @@ class EqualToValidatorTest extends AbstractComparisonValidatorTestCase
return array( return array(
array(1, '1', 2, '2', 'integer'), array(1, '1', 2, '2', 'integer'),
array('22', '"22"', '333', '"333"', 'string'), 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') array(new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', 'DateTime')
); );
} }
} }

View File

@ -52,7 +52,7 @@ class GreaterThanOrEqualValidatorTest extends AbstractComparisonValidatorTestCas
{ {
return array( return array(
array(1, '1', 2, '2', 'integer'), 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(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') array('b', '"b"', 'c', '"c"', 'string')
); );
} }

View File

@ -50,8 +50,8 @@ class GreaterThanValidatorTest extends AbstractComparisonValidatorTestCase
return array( return array(
array(1, '1', 2, '2', 'integer'), array(1, '1', 2, '2', 'integer'),
array(2, '2', 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('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(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"', '333', '"333"', 'string'),
array('22', '"22"', '22', '"22"', 'string') array('22', '"22"', '22', '"22"', 'string')
); );

View File

@ -53,8 +53,8 @@ class IdenticalToValidatorTest extends AbstractComparisonValidatorTestCase
array(1, '1', 2, '2', 'integer'), array(1, '1', 2, '2', 'integer'),
array(2, '2', '2', '"2"', 'string'), array(2, '2', '2', '"2"', 'string'),
array('22', '"22"', '333', '"333"', '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('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') array(new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', new \DateTime('1999-01-01'), 'Jan 1, 1999, 12:00 AM', 'DateTime')
); );
} }
} }

View File

@ -52,7 +52,7 @@ class LessThanOrEqualValidatorTest extends AbstractComparisonValidatorTestCase
{ {
return array( return array(
array(2, '2', 1, '1', 'integer'), 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(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') array('c', '"c"', 'b', '"b"', 'string')
); );
} }

View File

@ -50,8 +50,8 @@ class LessThanValidatorTest extends AbstractComparisonValidatorTestCase
return array( return array(
array(3, '3', 2, '2', 'integer'), array(3, '3', 2, '2', 'integer'),
array(2, '2', 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('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(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'), array('333', '"333"', '22', '"22"', 'string'),
); );
} }

View File

@ -51,7 +51,7 @@ class NotEqualToValidatorTest extends AbstractComparisonValidatorTestCase
array(3, '3', 3, '3', 'integer'), array(3, '3', 3, '3', 'integer'),
array('2', '"2"', 2, '2', 'integer'), array('2', '"2"', 2, '2', 'integer'),
array('a', '"a"', 'a', '"a"', 'string'), 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') array(new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', 'DateTime')
); );
} }
} }

View File

@ -54,7 +54,7 @@ class NotIdenticalToValidatorTest extends AbstractComparisonValidatorTestCase
return array( return array(
array(3, '3', 3, '3', 'integer'), array(3, '3', 3, '3', 'integer'),
array('a', '"a"', 'a', '"a"', 'string'), array('a', '"a"', 'a', '"a"', 'string'),
array($date, 'Jan 1, 2000 12:00 AM', $date, 'Jan 1, 2000 12:00 AM', 'DateTime') array($date, 'Jan 1, 2000, 12:00 AM', $date, 'Jan 1, 2000, 12:00 AM', 'DateTime')
); );
} }
} }