diff --git a/src/Symfony/Component/Validator/Constraints/MaxLengthValidator.php b/src/Symfony/Component/Validator/Constraints/MaxLengthValidator.php index cb040ee42d..e7f8d72758 100644 --- a/src/Symfony/Component/Validator/Constraints/MaxLengthValidator.php +++ b/src/Symfony/Component/Validator/Constraints/MaxLengthValidator.php @@ -40,21 +40,21 @@ class MaxLengthValidator extends ConstraintValidator throw new UnexpectedTypeException($value, 'string'); } - $value = (string) $value; + $stringValue = (string) $value; if (function_exists('grapheme_strlen') && 'UTF-8' === $constraint->charset) { - $length = grapheme_strlen($value); + $length = grapheme_strlen($stringValue); } elseif (function_exists('mb_strlen')) { - $length = mb_strlen($value, $constraint->charset); + $length = mb_strlen($stringValue, $constraint->charset); } else { - $length = strlen($value); + $length = strlen($stringValue); } if ($length > $constraint->limit) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $stringValue, '{{ limit }}' => $constraint->limit, - ), null, (int) $constraint->limit); + ), $value, (int) $constraint->limit); } } } diff --git a/src/Symfony/Component/Validator/Constraints/MinLengthValidator.php b/src/Symfony/Component/Validator/Constraints/MinLengthValidator.php index 5b3ea0c883..77d833e998 100644 --- a/src/Symfony/Component/Validator/Constraints/MinLengthValidator.php +++ b/src/Symfony/Component/Validator/Constraints/MinLengthValidator.php @@ -40,21 +40,21 @@ class MinLengthValidator extends ConstraintValidator throw new UnexpectedTypeException($value, 'string'); } - $value = (string) $value; + $stringValue = (string) $value; if (function_exists('grapheme_strlen') && 'UTF-8' === $constraint->charset) { - $length = grapheme_strlen($value); + $length = grapheme_strlen($stringValue); } elseif (function_exists('mb_strlen')) { - $length = mb_strlen($value, $constraint->charset); + $length = mb_strlen($stringValue, $constraint->charset); } else { - $length = strlen($value); + $length = strlen($stringValue); } if ($length < $constraint->limit) { $this->context->addViolation($constraint->message, array( - '{{ value }}' => $value, + '{{ value }}' => $stringValue, '{{ limit }}' => $constraint->limit, - ), null, (int) $constraint->limit); + ), $value, (int) $constraint->limit); } } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/MaxLengthValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/MaxLengthValidatorTest.php index c68e3cc93f..12091b7a5e 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/MaxLengthValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/MaxLengthValidatorTest.php @@ -98,10 +98,10 @@ class MaxLengthValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $value, + ->with('myMessage', $this->identicalTo(array( + '{{ value }}' => (string) $value, '{{ limit }}' => 5, - ), null, 5); + )), $this->identicalTo($value), 5); $this->validator->validate($value, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/MinLengthValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/MinLengthValidatorTest.php index a3c0d618f8..e3a1d01ad0 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/MinLengthValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/MinLengthValidatorTest.php @@ -98,10 +98,10 @@ class MinLengthValidatorTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('addViolation') - ->with('myMessage', array( - '{{ value }}' => $value, + ->with('myMessage', $this->identicalTo(array( + '{{ value }}' => (string) $value, '{{ limit }}' => 5, - ), null, 5); + )), $this->identicalTo($value), 5); $this->validator->validate($value, $constraint); }