Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Validator] Fixed string conversion in constraint violations #10687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 30, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Validator] Fixed date-to-string conversion tests to match ICU 51
  • Loading branch information
webmozart committed Jul 24, 2014
commit cea4155d3982c4f7842b4207230fbeae47b4843d
17 changes: 17 additions & 0 deletions 17 src/Symfony/Component/Validator/ConstraintValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,21 @@ protected function valueToString($value, $formatDates = false)

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indexing by $key should not be necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify what you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, didn't see you replace the interated array values. Maybe using another array like $convertedValues[] = ... would be cleaner.

}

return implode(', ', $values);
}
}
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Validator/Constraints/FileValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ public function validate($value, Constraint $constraint)

if (false === $valid) {
$this->context->addViolation($constraint->mimeTypesMessage, array(
'{{ type }}' => '"'.$mime.'"',
'{{ types }}' => '"'.implode('", "', $mimeTypes) .'"',
'{{ type }}' => $this->valueToString($mime),
'{{ types }}' => $this->valuesToString($mimeTypes),
'{{ file }}' => $path,
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Validator\Tests\Constraints;

use Symfony\Component\Intl\Util\IntlTestHelper;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\AbstractComparisonValidator;

Expand Down Expand Up @@ -73,12 +74,19 @@ abstract public function provideValidComparisons();
/**
* @dataProvider provideInvalidComparisons
* @param mixed $dirtyValue
* @param mixed $dirtyValueAsString
* @param mixed $comparedValue
* @param mixed $comparedValueString
* @param string $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->message = 'Constraint Message';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function provideInvalidComparisons()
return array(
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')
array(new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', 'DateTime')
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function provideInvalidComparisons()
{
return array(
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')
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function provideInvalidComparisons()
return array(
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(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')
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public function provideInvalidComparisons()
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')
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')
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function provideInvalidComparisons()
{
return array(
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')
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function provideInvalidComparisons()
return array(
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(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'),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function provideInvalidComparisons()
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')
array(new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', 'DateTime')
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function provideInvalidComparisons()
return array(
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')
array($date, 'Jan 1, 2000, 12:00 AM', $date, 'Jan 1, 2000, 12:00 AM', 'DateTime')
);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.