[Validator] Renamed valueToString() to formatValue(); added missing formatValue() calls
This commit is contained in:
parent
71897d7e35
commit
d6a783f989
@ -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);
|
||||
|
@ -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)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ class CountryValidator extends ConstraintValidator
|
||||
|
||||
if (!isset($countries[$value])) {
|
||||
$this->context->addViolation($constraint->message, array(
|
||||
'{{ value }}' => $value,
|
||||
'{{ value }}' => $this->formatValue($value),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ class CurrencyValidator extends ConstraintValidator
|
||||
|
||||
if (!isset($currencies[$value])) {
|
||||
$this->context->addViolation($constraint->message, array(
|
||||
'{{ value }}' => $value,
|
||||
'{{ value }}' => $this->formatValue($value),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class EmailValidator extends ConstraintValidator
|
||||
|
||||
if (!$valid) {
|
||||
$this->context->addViolation($constraint->message, array(
|
||||
'{{ value }}' => $value,
|
||||
'{{ value }}' => $this->formatValue($value),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class FalseValidator extends ConstraintValidator
|
||||
}
|
||||
|
||||
$this->context->addViolation($constraint->message, array(
|
||||
'{{ value }}' => $this->valueToString($value),
|
||||
'{{ value }}' => $this->formatValue($value),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ class LanguageValidator extends ConstraintValidator
|
||||
|
||||
if (!isset($languages[$value])) {
|
||||
$this->context->addViolation($constraint->message, array(
|
||||
'{{ value }}' => $value,
|
||||
'{{ value }}' => $this->formatValue($value),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ class LocaleValidator extends ConstraintValidator
|
||||
|
||||
if (!isset($locales[$value])) {
|
||||
$this->context->addViolation($constraint->message, array(
|
||||
'{{ value }}' => $value,
|
||||
'{{ value }}' => $this->formatValue($value),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
));
|
||||
}
|
||||
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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',
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user