diff --git a/src/Symfony/Component/Validator/Constraint.php b/src/Symfony/Component/Validator/Constraint.php index 2f3cbdda5ad00..550580912cbc7 100644 --- a/src/Symfony/Component/Validator/Constraint.php +++ b/src/Symfony/Component/Validator/Constraint.php @@ -53,6 +53,11 @@ abstract class Constraint */ public $groups = array(self::DEFAULT_GROUP); + /** + * @var mixed + */ + public $code; + /** * Initializes the constraint with options. * diff --git a/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php b/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php index f6b919331fae7..0f08a306d625b 100644 --- a/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php +++ b/src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php @@ -35,7 +35,7 @@ public function validate($value, Constraint $constraint) '{{ value }}' => $this->valueToString($constraint->value), '{{ compared_value }}' => $this->valueToString($constraint->value), '{{ compared_value_type }}' => $this->valueToType($constraint->value) - )); + ), $constraint->value, null, $constraint::ERROR); } } diff --git a/src/Symfony/Component/Validator/Constraints/Blank.php b/src/Symfony/Component/Validator/Constraints/Blank.php index 509479d5e69d4..a72031e63cedb 100644 --- a/src/Symfony/Component/Validator/Constraints/Blank.php +++ b/src/Symfony/Component/Validator/Constraints/Blank.php @@ -22,5 +22,7 @@ */ class Blank extends Constraint { + const ERROR = '3dfbbd3d-faed-46de-b781-fb1c3c9bbac3'; + public $message = 'This value should be blank.'; } diff --git a/src/Symfony/Component/Validator/Constraints/BlankValidator.php b/src/Symfony/Component/Validator/Constraints/BlankValidator.php index 0a673588fc0f6..0b5e5bf559dcf 100644 --- a/src/Symfony/Component/Validator/Constraints/BlankValidator.php +++ b/src/Symfony/Component/Validator/Constraints/BlankValidator.php @@ -27,7 +27,7 @@ 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 }}' => $value), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/CardScheme.php b/src/Symfony/Component/Validator/Constraints/CardScheme.php index 0bc1c93afc747..d05a6f1d9967f 100644 --- a/src/Symfony/Component/Validator/Constraints/CardScheme.php +++ b/src/Symfony/Component/Validator/Constraints/CardScheme.php @@ -20,6 +20,8 @@ */ class CardScheme extends Constraint { + const ERROR = '300f90d4-23d9-4bfe-a922-ebecff115e9d'; + public $message = 'Unsupported card type or invalid card number.'; public $schemes; diff --git a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php index 1ece3fdd65275..115e5da138ec6 100644 --- a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php @@ -108,7 +108,7 @@ public function validate($value, Constraint $constraint) } if (!is_numeric($value)) { - $this->context->addViolation($constraint->message); + $this->context->addViolation($constraint->message, array(), $value, null, $constraint::ERROR); return; } @@ -124,6 +124,6 @@ public function validate($value, Constraint $constraint) } } - $this->context->addViolation($constraint->message); + $this->context->addViolation($constraint->message, array(), $value, null, $constraint::ERROR); } } diff --git a/src/Symfony/Component/Validator/Constraints/Choice.php b/src/Symfony/Component/Validator/Constraints/Choice.php index 50508aeed2b6a..2b11b63dd2d9e 100644 --- a/src/Symfony/Component/Validator/Constraints/Choice.php +++ b/src/Symfony/Component/Validator/Constraints/Choice.php @@ -22,6 +22,11 @@ */ class Choice extends Constraint { + const ERROR = '75d601e8-d9da-49a6-bf32-6df461244744'; + const ERROR_MULTIPLE = '695ad03b-1cdc-4b97-81d2-60c7de8424b5'; + const ERROR_MIN = '34f58897-1e70-4353-97d7-27ebd472406e'; + const ERROR_MAX = '73311798-3160-48b9-b71a-1502ba9e45d6'; + public $choices; public $callback; public $multiple = false; diff --git a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php index 294e7dbfc931f..d8f75184ec979 100644 --- a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php @@ -59,25 +59,25 @@ public function validate($value, Constraint $constraint) 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 }}' => $_value), $_value, null, $constraint::ERROR_MULTIPLE); } } $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, $constraint::ERROR_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, $constraint::ERROR_MAX); return; } } elseif (!in_array($value, $choices, $constraint->strict)) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Collection.php b/src/Symfony/Component/Validator/Constraints/Collection.php index d60f0c273d13b..b8b6607cd9ef6 100644 --- a/src/Symfony/Component/Validator/Constraints/Collection.php +++ b/src/Symfony/Component/Validator/Constraints/Collection.php @@ -12,8 +12,6 @@ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\Constraints\Required; -use Symfony\Component\Validator\Constraints\Optional; use Symfony\Component\Validator\Exception\ConstraintDefinitionException; /** @@ -25,6 +23,9 @@ */ class Collection extends Constraint { + const ERROR_EXTRA_FIELD = 'd3a68ca4-4836-42d9-a2c8-c21103a18b3f'; + const ERROR_MISSING_FIELD = 'fb668c0b-5d90-4bda-8a3e-1fe4f1d5335b'; + public $fields; public $allowExtraFields = false; public $allowMissingFields = false; diff --git a/src/Symfony/Component/Validator/Constraints/CollectionValidator.php b/src/Symfony/Component/Validator/Constraints/CollectionValidator.php index f59afe79ee5f3..927e221f965b1 100644 --- a/src/Symfony/Component/Validator/Constraints/CollectionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CollectionValidator.php @@ -14,7 +14,6 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\UnexpectedTypeException; -use Symfony\Component\Validator\Constraints\Optional; /** * @author Bernhard Schussek @@ -50,7 +49,7 @@ public function validate($value, Constraint $constraint) } elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) { $this->context->addViolationAt('['.$field.']', $constraint->missingFieldsMessage, array( '{{ field }}' => $field - ), null); + ), $field, $constraint::ERROR_MISSING_FIELD); } } @@ -59,7 +58,7 @@ public function validate($value, Constraint $constraint) if (!isset($constraint->fields[$field])) { $this->context->addViolationAt('['.$field.']', $constraint->extraFieldsMessage, array( '{{ field }}' => $field - ), $fieldValue); + ), $field, null, $constraint::ERROR_EXTRA_FIELD); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Count.php b/src/Symfony/Component/Validator/Constraints/Count.php index 4a233c19f6c5a..ebc188983e739 100644 --- a/src/Symfony/Component/Validator/Constraints/Count.php +++ b/src/Symfony/Component/Validator/Constraints/Count.php @@ -23,6 +23,10 @@ */ class Count extends Constraint { + const ERROR_MIN = '4b57ee81-3a6b-4b43-93ae-69441571d39e'; + const ERROR_MAX = '9537c665-37eb-4515-a1fd-7beff83e6c1f'; + const ERROR_EXACT = 'd3625fef-ce0a-4332-a89e-408078ed6e58'; + public $minMessage = 'This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.'; public $maxMessage = 'This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.'; public $exactMessage = 'This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.'; diff --git a/src/Symfony/Component/Validator/Constraints/CountValidator.php b/src/Symfony/Component/Validator/Constraints/CountValidator.php index 0a3be12f953ce..12d390bcceb01 100644 --- a/src/Symfony/Component/Validator/Constraints/CountValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CountValidator.php @@ -39,7 +39,7 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->exactMessage, array( '{{ count }}' => $count, '{{ limit }}' => $constraint->min, - ), $value, (int) $constraint->min); + ), $value, (int) $constraint->min, $constraint::ERROR_EXACT); return; } @@ -48,7 +48,7 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->maxMessage, array( '{{ count }}' => $count, '{{ limit }}' => $constraint->max, - ), $value, (int) $constraint->max); + ), $value, (int) $constraint->max, $constraint::ERROR_MAX); return; } @@ -57,7 +57,7 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->minMessage, array( '{{ count }}' => $count, '{{ limit }}' => $constraint->min, - ), $value, (int) $constraint->min); + ), $value, (int) $constraint->min, $constraint::ERROR_MIN); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Country.php b/src/Symfony/Component/Validator/Constraints/Country.php index 81fa7e05fd858..9f501b5e8f083 100644 --- a/src/Symfony/Component/Validator/Constraints/Country.php +++ b/src/Symfony/Component/Validator/Constraints/Country.php @@ -22,5 +22,7 @@ */ class Country extends Constraint { + const ERROR = '326b7f14-6fde-4489-8e9b-8458ecc2e559'; + public $message = 'This value is not a valid country.'; } diff --git a/src/Symfony/Component/Validator/Constraints/CountryValidator.php b/src/Symfony/Component/Validator/Constraints/CountryValidator.php index 1b3f8653e4ad6..2f011337969bc 100644 --- a/src/Symfony/Component/Validator/Constraints/CountryValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CountryValidator.php @@ -42,7 +42,7 @@ public function validate($value, Constraint $constraint) $countries = Intl::getRegionBundle()->getCountryNames(); if (!isset($countries[$value])) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Currency.php b/src/Symfony/Component/Validator/Constraints/Currency.php index b3bfc8f68b70c..c5246383e0601 100644 --- a/src/Symfony/Component/Validator/Constraints/Currency.php +++ b/src/Symfony/Component/Validator/Constraints/Currency.php @@ -22,5 +22,7 @@ */ class Currency extends Constraint { + const ERROR = 'f68a8d40-4231-4afd-83ac-0bcd818dc818'; + public $message = 'This value is not a valid currency.'; } diff --git a/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php b/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php index 4465e46dfeecf..2cc528333940b 100644 --- a/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php @@ -42,7 +42,7 @@ public function validate($value, Constraint $constraint) $currencies = Intl::getCurrencyBundle()->getCurrencyNames(); if (!isset($currencies[$value])) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Date.php b/src/Symfony/Component/Validator/Constraints/Date.php index f9923052e0cf1..37ab34d863522 100644 --- a/src/Symfony/Component/Validator/Constraints/Date.php +++ b/src/Symfony/Component/Validator/Constraints/Date.php @@ -22,5 +22,7 @@ */ class Date extends Constraint { + const ERROR = 'f360bec2-4636-46ad-8ef6-aecc65e08a00'; + public $message = 'This value is not a valid date.'; } diff --git a/src/Symfony/Component/Validator/Constraints/DateTime.php b/src/Symfony/Component/Validator/Constraints/DateTime.php index 0618bc9b99923..ab988b6d26a51 100644 --- a/src/Symfony/Component/Validator/Constraints/DateTime.php +++ b/src/Symfony/Component/Validator/Constraints/DateTime.php @@ -22,5 +22,7 @@ */ class DateTime extends Constraint { + const ERROR = '383654a2-f53e-4529-ace3-176742663f3a'; + public $message = 'This value is not a valid datetime.'; } diff --git a/src/Symfony/Component/Validator/Constraints/DateValidator.php b/src/Symfony/Component/Validator/Constraints/DateValidator.php index f891f9d621a9b..d7eb6349d4b73 100644 --- a/src/Symfony/Component/Validator/Constraints/DateValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateValidator.php @@ -40,7 +40,7 @@ public function validate($value, Constraint $constraint) $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), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Email.php b/src/Symfony/Component/Validator/Constraints/Email.php index 581dfb985f721..ba4e78b369b1f 100644 --- a/src/Symfony/Component/Validator/Constraints/Email.php +++ b/src/Symfony/Component/Validator/Constraints/Email.php @@ -22,6 +22,8 @@ */ class Email extends Constraint { + const ERROR = '38b1dcdc-501a-43c1-98e1-4ab0971ca1b2'; + public $message = 'This value is not a valid email address.'; public $checkMX = false; public $checkHost = false; diff --git a/src/Symfony/Component/Validator/Constraints/EmailValidator.php b/src/Symfony/Component/Validator/Constraints/EmailValidator.php index e0593102bc599..06a5274cde3ed 100644 --- a/src/Symfony/Component/Validator/Constraints/EmailValidator.php +++ b/src/Symfony/Component/Validator/Constraints/EmailValidator.php @@ -50,7 +50,7 @@ public function validate($value, Constraint $constraint) } if (!$valid) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR); } } diff --git a/src/Symfony/Component/Validator/Constraints/EqualTo.php b/src/Symfony/Component/Validator/Constraints/EqualTo.php index 3ae29a89fd201..fff218720f4d6 100644 --- a/src/Symfony/Component/Validator/Constraints/EqualTo.php +++ b/src/Symfony/Component/Validator/Constraints/EqualTo.php @@ -18,5 +18,7 @@ */ class EqualTo extends AbstractComparison { + const ERROR = 'f92206ec-df92-406d-931b-833343889cd7'; + public $message = 'This value should be equal to {{ compared_value }}.'; } diff --git a/src/Symfony/Component/Validator/Constraints/Expression.php b/src/Symfony/Component/Validator/Constraints/Expression.php index b845a32392b2c..cb0f049ca542c 100644 --- a/src/Symfony/Component/Validator/Constraints/Expression.php +++ b/src/Symfony/Component/Validator/Constraints/Expression.php @@ -21,6 +21,8 @@ */ class Expression extends Constraint { + const ERROR = '2fe78c81-b47e-4d20-952b-f571a301a8df'; + public $message = 'This value is not valid.'; public $expression; diff --git a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php index e27859b08c19c..d338d477eda5c 100644 --- a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php @@ -64,7 +64,7 @@ public function validate($value, Constraint $constraint) } if (!$this->getExpressionLanguage()->evaluate($constraint->expression, $variables)) { - $this->context->addViolation($constraint->message); + $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR); } } diff --git a/src/Symfony/Component/Validator/Constraints/False.php b/src/Symfony/Component/Validator/Constraints/False.php index fec54456fba0c..c860f3ef02a14 100644 --- a/src/Symfony/Component/Validator/Constraints/False.php +++ b/src/Symfony/Component/Validator/Constraints/False.php @@ -22,5 +22,7 @@ */ class False extends Constraint { + const ERROR = '890770b4-e5c4-49e5-a285-b480ab42b43a'; + public $message = 'This value should be false.'; } diff --git a/src/Symfony/Component/Validator/Constraints/FalseValidator.php b/src/Symfony/Component/Validator/Constraints/FalseValidator.php index 7cead615080a8..b4f85e9aaaecc 100644 --- a/src/Symfony/Component/Validator/Constraints/FalseValidator.php +++ b/src/Symfony/Component/Validator/Constraints/FalseValidator.php @@ -30,6 +30,6 @@ public function validate($value, Constraint $constraint) return; } - $this->context->addViolation($constraint->message); + $this->context->addViolation($constraint->message, array(), $value, null, $constraint::ERROR); } } diff --git a/src/Symfony/Component/Validator/Constraints/File.php b/src/Symfony/Component/Validator/Constraints/File.php index 9144c60472631..94c1b7b1488ac 100644 --- a/src/Symfony/Component/Validator/Constraints/File.php +++ b/src/Symfony/Component/Validator/Constraints/File.php @@ -22,6 +22,20 @@ */ class File extends Constraint { + const ERROR_NOT_FOUND = '61fbc820-360e-4635-8410-6e18c55d0793'; + const ERROR_NOT_READABLE = '27fb8e2a-e615-460a-8248-2b9fd7fb0f03'; + const ERROR_MAX_SIZE = '94ab2b21-4bb2-4f2c-8b0f-2f23ee3fa083'; + const ERROR_MIME_TYPE = 'aeaf332e-eb9f-4f5b-954b-73a4ee10099b'; + + const ERROR_UPLOAD_INI_SIZE = '3ccb63bf-288f-4a83-9ded-750eb60efeb7'; + const ERROR_UPLOAD_FORM_SIZE = 'd8af3119-4ca1-4b68-b6a8-742fd1713dfb'; + const ERROR_UPLOAD_PARTIAL = '9607840b-25a2-4a06-b6de-a443fdf7bc89'; + const ERROR_UPLOAD_NO_FILE = '5025cb15-812e-411c-8837-cae3106dec7c'; + const ERROR_UPLOAD_NO_TMP_DIR = '6507b3da-97db-4c89-9628-2b41b4772fed'; + const ERROR_UPLOAD_CANT_WRITE = '3da80e51-9c7d-41ea-b077-7385633c9bbc'; + const ERROR_UPLOAD_EXTENSION = 'fc050994-f85a-4226-b35f-7a7e55fe29d4'; + const ERROR_UPLOAD = '4e786105-6f8b-42fa-a409-f29792fa297a'; + public $maxSize = null; public $mimeTypes = array(); public $notFoundMessage = 'The file could not be found.'; diff --git a/src/Symfony/Component/Validator/Constraints/FileValidator.php b/src/Symfony/Component/Validator/Constraints/FileValidator.php index 06e16ebe2ca68..234dc8620b5dd 100644 --- a/src/Symfony/Component/Validator/Constraints/FileValidator.php +++ b/src/Symfony/Component/Validator/Constraints/FileValidator.php @@ -55,35 +55,35 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->uploadIniSizeErrorMessage, array( '{{ limit }}' => $maxSize, '{{ suffix }}' => 'bytes', - )); + ), $value, null, $constraint::ERROR_UPLOAD_INI_SIZE); return; case UPLOAD_ERR_FORM_SIZE: - $this->context->addViolation($constraint->uploadFormSizeErrorMessage); + $this->context->addViolation($constraint->uploadFormSizeErrorMessage, array(), $value, null, $constraint::ERROR_UPLOAD_FORM_SIZE); return; case UPLOAD_ERR_PARTIAL: - $this->context->addViolation($constraint->uploadPartialErrorMessage); + $this->context->addViolation($constraint->uploadPartialErrorMessage, array(), $value, null, $constraint::ERROR_UPLOAD_PARTIAL); return; case UPLOAD_ERR_NO_FILE: - $this->context->addViolation($constraint->uploadNoFileErrorMessage); + $this->context->addViolation($constraint->uploadNoFileErrorMessage, array(), $value, null, $constraint::ERROR_UPLOAD_NO_FILE); return; case UPLOAD_ERR_NO_TMP_DIR: - $this->context->addViolation($constraint->uploadNoTmpDirErrorMessage); + $this->context->addViolation($constraint->uploadNoTmpDirErrorMessage, array(), $value, null, $constraint::ERROR_UPLOAD_NO_TMP_DIR); return; case UPLOAD_ERR_CANT_WRITE: - $this->context->addViolation($constraint->uploadCantWriteErrorMessage); + $this->context->addViolation($constraint->uploadCantWriteErrorMessage, array(), $value, null, $constraint::ERROR_UPLOAD_CANT_WRITE); return; case UPLOAD_ERR_EXTENSION: - $this->context->addViolation($constraint->uploadExtensionErrorMessage); + $this->context->addViolation($constraint->uploadExtensionErrorMessage, array(), $value, null, $constraint::ERROR_UPLOAD_EXTENSION); return; default: - $this->context->addViolation($constraint->uploadErrorMessage); + $this->context->addViolation($constraint->uploadErrorMessage, array(), $value, null, $constraint::ERROR_UPLOAD); return; } @@ -96,13 +96,13 @@ public function validate($value, Constraint $constraint) $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 }}' => $path), $value, null, $constraint::ERROR_NOT_FOUND); return; } if (!is_readable($path)) { - $this->context->addViolation($constraint->notReadableMessage, array('{{ file }}' => $path)); + $this->context->addViolation($constraint->notReadableMessage, array('{{ file }}' => $path), $value, null, $constraint::ERROR_NOT_READABLE); return; } @@ -130,7 +130,7 @@ public function validate($value, Constraint $constraint) '{{ limit }}' => $limit, '{{ suffix }}' => $suffix, '{{ file }}' => $path, - )); + ), $value, null, $constraint::ERROR_MAX_SIZE); return; } @@ -164,7 +164,7 @@ public function validate($value, Constraint $constraint) '{{ type }}' => '"'.$mime.'"', '{{ types }}' => '"'.implode('", "', $mimeTypes) .'"', '{{ file }}' => $path, - )); + ), $value, null, $constraint::ERROR_MIME_TYPE); } } } diff --git a/src/Symfony/Component/Validator/Constraints/GreaterThan.php b/src/Symfony/Component/Validator/Constraints/GreaterThan.php index df911256604ed..814fd11463ba1 100644 --- a/src/Symfony/Component/Validator/Constraints/GreaterThan.php +++ b/src/Symfony/Component/Validator/Constraints/GreaterThan.php @@ -18,5 +18,7 @@ */ class GreaterThan extends AbstractComparison { + const ERROR = '48f4b8a5-832c-4ffc-92b5-64dcd6312c32'; + public $message = 'This value should be greater than {{ compared_value }}.'; } diff --git a/src/Symfony/Component/Validator/Constraints/GreaterThanOrEqual.php b/src/Symfony/Component/Validator/Constraints/GreaterThanOrEqual.php index 782893a04d514..f2323f9ba19e1 100644 --- a/src/Symfony/Component/Validator/Constraints/GreaterThanOrEqual.php +++ b/src/Symfony/Component/Validator/Constraints/GreaterThanOrEqual.php @@ -18,5 +18,7 @@ */ class GreaterThanOrEqual extends AbstractComparison { + const ERROR = 'd53fb887-5eef-4c1c-8898-02ca753e949b'; + public $message = 'This value should be greater than or equal to {{ compared_value }}.'; } diff --git a/src/Symfony/Component/Validator/Constraints/Iban.php b/src/Symfony/Component/Validator/Constraints/Iban.php index b1621959c91cd..698e8e1321716 100644 --- a/src/Symfony/Component/Validator/Constraints/Iban.php +++ b/src/Symfony/Component/Validator/Constraints/Iban.php @@ -18,5 +18,7 @@ */ class Iban extends Constraint { + const ERROR = '403389e4-59d7-4942-ad9c-b5ba5a0a6a92'; + public $message = 'This is not a valid International Bank Account Number (IBAN).'; } diff --git a/src/Symfony/Component/Validator/Constraints/IbanValidator.php b/src/Symfony/Component/Validator/Constraints/IbanValidator.php index 1afc8f01b7118..63af163c04cae 100644 --- a/src/Symfony/Component/Validator/Constraints/IbanValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IbanValidator.php @@ -33,7 +33,7 @@ public function validate($value, Constraint $constraint) $teststring = preg_replace('/\s+/', '', $value); if (strlen($teststring) < 4) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR); return; } @@ -55,7 +55,7 @@ public function validate($value, Constraint $constraint) } if ($rest != 1) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR); return; } diff --git a/src/Symfony/Component/Validator/Constraints/IdenticalTo.php b/src/Symfony/Component/Validator/Constraints/IdenticalTo.php index f4ae5becc3cf5..eef4bc2d3807b 100644 --- a/src/Symfony/Component/Validator/Constraints/IdenticalTo.php +++ b/src/Symfony/Component/Validator/Constraints/IdenticalTo.php @@ -18,5 +18,7 @@ */ class IdenticalTo extends AbstractComparison { + const ERROR = '5368c23a-37c0-4148-83bc-7ee8ac34a1af'; + public $message = 'This value should be identical to {{ compared_value_type }} {{ compared_value }}.'; } diff --git a/src/Symfony/Component/Validator/Constraints/Image.php b/src/Symfony/Component/Validator/Constraints/Image.php index 9fa8725c6da15..7b7b8ebbaac33 100644 --- a/src/Symfony/Component/Validator/Constraints/Image.php +++ b/src/Symfony/Component/Validator/Constraints/Image.php @@ -18,6 +18,17 @@ */ class Image extends File { + const ERROR_SIZE_NOT_DETECTED = '1ea61424-9a94-46e5-89b1-26fa91dacf55'; + const ERROR_MAX_WIDTH = 'a92d747a-9cd8-4194-bbba-ac9d40f438fe'; + const ERROR_MIN_WIDTH = '52479c81-46e9-4302-b15d-f9c36b6cd6ce'; + const ERROR_MAX_HEIGHT = '57d13e39-13ed-4dde-b562-2d5a8b52ef96'; + const ERROR_MIN_HEIGHT = '48378c83-eaf2-436a-b972-f28ca6cc5e2b'; + const ERROR_MAX_RATIO = '90ddd17c-3beb-4f89-84d2-444734ae4e71'; + const ERROR_MIN_RATIO = '17cd9582-15f0-4238-b778-f72a31b4debe'; + const ERROR_DONT_ALLOW_SQUARE = 'ac8f80d1-9432-419e-859f-10142f6daed9'; + const ERROR_DONT_ALLOW_LANDSCAPE = '2d77d2b1-1c41-405d-9dee-db260bae2fb8'; + const ERROR_DONT_ALLOW_PORTRAIT = '84451f62-d4e2-4ab1-96be-dc7c25e0e4d9'; + public $mimeTypes = 'image/*'; public $minWidth = null; public $maxWidth = null; @@ -29,6 +40,7 @@ class Image extends File public $allowLandscape = true; public $allowPortrait = true; + // The constant for a wrong MIME type is taken from the parent class. public $mimeTypesMessage = 'This file is not a valid image.'; public $sizeNotDetectedMessage = 'The size of the image could not be detected.'; public $maxWidthMessage = 'The image width is too big ({{ width }}px). Allowed maximum width is {{ max_width }}px.'; diff --git a/src/Symfony/Component/Validator/Constraints/ImageValidator.php b/src/Symfony/Component/Validator/Constraints/ImageValidator.php index 76ce8767fcea8..f1ff3e591f052 100644 --- a/src/Symfony/Component/Validator/Constraints/ImageValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ImageValidator.php @@ -46,7 +46,7 @@ public function validate($value, Constraint $constraint) $size = @getimagesize($value); if (empty($size) || ($size[0] === 0) || ($size[1] === 0)) { - $this->context->addViolation($constraint->sizeNotDetectedMessage); + $this->context->addViolation($constraint->sizeNotDetectedMessage, array(), $value, null, $constraint::ERROR_SIZE_NOT_DETECTED); return; } @@ -63,7 +63,7 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->minWidthMessage, array( '{{ width }}' => $width, '{{ min_width }}' => $constraint->minWidth - )); + ), $value, null, $constraint::ERROR_MIN_WIDTH); return; } @@ -78,7 +78,7 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->maxWidthMessage, array( '{{ width }}' => $width, '{{ max_width }}' => $constraint->maxWidth - )); + ), $value, null, $constraint::ERROR_MAX_WIDTH); return; } @@ -93,7 +93,7 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->minHeightMessage, array( '{{ height }}' => $height, '{{ min_height }}' => $constraint->minHeight - )); + ), $value, null, $constraint::ERROR_MIN_HEIGHT); return; } @@ -108,7 +108,7 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->maxHeightMessage, array( '{{ height }}' => $height, '{{ max_height }}' => $constraint->maxHeight - )); + ), $value, null, $constraint::ERROR_MAX_HEIGHT); } } @@ -123,7 +123,7 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->minRatioMessage, array( '{{ ratio }}' => $ratio, '{{ min_ratio }}' => $constraint->minRatio - )); + ), $value, null, $constraint::ERROR_MIN_RATIO); } } @@ -136,7 +136,7 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->maxRatioMessage, array( '{{ ratio }}' => $ratio, '{{ max_ratio }}' => $constraint->maxRatio - )); + ), $value, null, $constraint::ERROR_MAX_RATIO); } } @@ -144,21 +144,21 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->allowSquareMessage, array( '{{ width }}' => $width, '{{ height }}' => $height - )); + ), $value, null, $constraint::ERROR_DONT_ALLOW_SQUARE); } if (!$constraint->allowLandscape && $width > $height) { $this->context->addViolation($constraint->allowLandscapeMessage, array( '{{ width }}' => $width, '{{ height }}' => $height - )); + ), $value, null, $constraint::ERROR_DONT_ALLOW_LANDSCAPE); } if (!$constraint->allowPortrait && $width < $height) { $this->context->addViolation($constraint->allowPortraitMessage, array( '{{ width }}' => $width, '{{ height }}' => $height - )); + ), $value, null, $constraint::ERROR_DONT_ALLOW_PORTRAIT); } } diff --git a/src/Symfony/Component/Validator/Constraints/Ip.php b/src/Symfony/Component/Validator/Constraints/Ip.php index 099f2aabd7348..bb77c57452496 100644 --- a/src/Symfony/Component/Validator/Constraints/Ip.php +++ b/src/Symfony/Component/Validator/Constraints/Ip.php @@ -26,6 +26,8 @@ */ class Ip extends Constraint { + const ERROR = '77436b41-d7f5-4793-8e67-cd5e5d3722a1'; + const V4 = '4'; const V6 = '6'; const ALL = 'all'; diff --git a/src/Symfony/Component/Validator/Constraints/IpValidator.php b/src/Symfony/Component/Validator/Constraints/IpValidator.php index 3358ec25c4d81..f6e8ada24ca49 100644 --- a/src/Symfony/Component/Validator/Constraints/IpValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IpValidator.php @@ -91,7 +91,7 @@ public function validate($value, Constraint $constraint) } if (!filter_var($value, FILTER_VALIDATE_IP, $flag)) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Isbn.php b/src/Symfony/Component/Validator/Constraints/Isbn.php index 4a11e2344852a..261f57690bd62 100644 --- a/src/Symfony/Component/Validator/Constraints/Isbn.php +++ b/src/Symfony/Component/Validator/Constraints/Isbn.php @@ -21,6 +21,10 @@ */ class Isbn extends Constraint { + const ERROR = 'af6f41b0-3626-4b78-96a3-a6027832d1cb'; + const ERROR_ISBN10 = '7665fcb0-e6bf-4d31-8159-f9cf713bae5f'; + const ERROR_ISBN13 = '6aa1c63f-c281-4741-bb12-d8505011414f'; + public $isbn10Message = 'This value is not a valid ISBN-10.'; public $isbn13Message = 'This value is not a valid ISBN-13.'; public $bothIsbnMessage = 'This value is neither a valid ISBN-10 nor a valid ISBN-13.'; diff --git a/src/Symfony/Component/Validator/Constraints/IsbnValidator.php b/src/Symfony/Component/Validator/Constraints/IsbnValidator.php index 62a3b0388e3b6..2e03f497edb66 100644 --- a/src/Symfony/Component/Validator/Constraints/IsbnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IsbnValidator.php @@ -37,52 +37,53 @@ public function validate($value, Constraint $constraint) throw new UnexpectedTypeException($value, 'string'); } - if (!is_numeric($value)) { - $value = str_replace('-', '', $value); + $isbn = strtoupper($value); + + if (!is_numeric($isbn)) { + $isbn = str_replace('-', '', $isbn); } $validation = 0; - $value = strtoupper($value); - $valueLength = strlen($value); + $valueLength = strlen($isbn); if (10 === $valueLength && null !== $constraint->isbn10) { for ($i = 0; $i < 10; $i++) { - if ($value[$i] == 'X') { + if ($isbn[$i] == 'X') { $validation += 10 * intval(10 - $i); } else { - $validation += intval($value[$i]) * intval(10 - $i); + $validation += intval($isbn[$i]) * intval(10 - $i); } } if ($validation % 11 != 0) { if (null !== $constraint->isbn13) { - $this->context->addViolation($constraint->bothIsbnMessage); + $this->context->addViolation($constraint->bothIsbnMessage, array('{{ value }}' => $value), $value, null, $constraint::ERROR); } else { - $this->context->addViolation($constraint->isbn10Message); + $this->context->addViolation($constraint->isbn10Message, array('{{ value }}' => $value), $value, null, $constraint::ERROR_ISBN10); } } } elseif (13 === $valueLength && null !== $constraint->isbn13) { for ($i = 0; $i < 13; $i += 2) { - $validation += intval($value[$i]); + $validation += intval($isbn[$i]); } for ($i = 1; $i < 12; $i += 2) { - $validation += intval($value[$i]) * 3; + $validation += intval($isbn[$i]) * 3; } if ($validation % 10 != 0) { if (null !== $constraint->isbn10) { - $this->context->addViolation($constraint->bothIsbnMessage); + $this->context->addViolation($constraint->bothIsbnMessage, array('{{ value }}' => $value), $value, null, $constraint::ERROR); } else { - $this->context->addViolation($constraint->isbn13Message); + $this->context->addViolation($constraint->isbn13Message, array('{{ value }}' => $value), $value, null, $constraint::ERROR_ISBN13); } } } else { if (null !== $constraint->isbn10 && null !== $constraint->isbn13) { - $this->context->addViolation($constraint->bothIsbnMessage); + $this->context->addViolation($constraint->bothIsbnMessage, array('{{ value }}' => $value), $value, null, $constraint::ERROR); } elseif (null !== $constraint->isbn10) { - $this->context->addViolation($constraint->isbn10Message); + $this->context->addViolation($constraint->isbn10Message, array('{{ value }}' => $value), $value, null, $constraint::ERROR_ISBN10); } else { - $this->context->addViolation($constraint->isbn13Message); + $this->context->addViolation($constraint->isbn13Message, array('{{ value }}' => $value), $value, null, $constraint::ERROR_ISBN13); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Issn.php b/src/Symfony/Component/Validator/Constraints/Issn.php index d7d77b6571462..a80205f2bb89e 100644 --- a/src/Symfony/Component/Validator/Constraints/Issn.php +++ b/src/Symfony/Component/Validator/Constraints/Issn.php @@ -20,6 +20,8 @@ */ class Issn extends Constraint { + const ERROR = '3e3590ed-7890-4ccf-8d62-12b4966d0a39'; + public $message = 'This value is not a valid ISSN.'; public $caseSensitive = false; public $requireHyphen = false; diff --git a/src/Symfony/Component/Validator/Constraints/IssnValidator.php b/src/Symfony/Component/Validator/Constraints/IssnValidator.php index 7e0baa876dceb..6befe5694ba5a 100644 --- a/src/Symfony/Component/Validator/Constraints/IssnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IssnValidator.php @@ -43,7 +43,7 @@ public function validate($value, Constraint $constraint) $pattern = "/^".$digitsPattern.$checksumPattern."$/"; if (!preg_match($pattern, $value)) { - $this->context->addViolation($constraint->message); + $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR); } else { $digits = str_split(strtoupper(str_replace('-', '', $value))); @@ -55,7 +55,7 @@ public function validate($value, Constraint $constraint) $checksum = 'X' == reset($digits) ? 10 : (int) reset($digits); if (0 != ($sum + $checksum) % 11) { - $this->context->addViolation($constraint->message); + $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Language.php b/src/Symfony/Component/Validator/Constraints/Language.php index d14bcd922b8d3..aa4a2caa30d16 100644 --- a/src/Symfony/Component/Validator/Constraints/Language.php +++ b/src/Symfony/Component/Validator/Constraints/Language.php @@ -22,5 +22,7 @@ */ class Language extends Constraint { + const ERROR = 'eb2120ee-6f0d-4fa8-9e63-79af6289bda6'; + public $message = 'This value is not a valid language.'; } diff --git a/src/Symfony/Component/Validator/Constraints/LanguageValidator.php b/src/Symfony/Component/Validator/Constraints/LanguageValidator.php index 5c4dbed2980f5..6366cba1b721a 100644 --- a/src/Symfony/Component/Validator/Constraints/LanguageValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LanguageValidator.php @@ -42,7 +42,7 @@ public function validate($value, Constraint $constraint) $languages = Intl::getLanguageBundle()->getLanguageNames(); if (!isset($languages[$value])) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Length.php b/src/Symfony/Component/Validator/Constraints/Length.php index 84c7303e227bf..a86c1be66cae3 100644 --- a/src/Symfony/Component/Validator/Constraints/Length.php +++ b/src/Symfony/Component/Validator/Constraints/Length.php @@ -23,6 +23,10 @@ */ class Length extends Constraint { + const ERROR = 'cca1a7c3-beed-44c8-a12c-dd94e6208631'; + const ERROR_MAX = '2127fa68-8220-4d66-bdbd-6c9e12c4e529'; + const ERROR_MIN = '7ec9200c-b68d-4aff-b29f-d546912ed243'; + public $maxMessage = 'This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.'; public $minMessage = 'This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.'; public $exactMessage = 'This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.'; diff --git a/src/Symfony/Component/Validator/Constraints/LengthValidator.php b/src/Symfony/Component/Validator/Constraints/LengthValidator.php index 8090a2c6a8aa6..582109b4d71e4 100644 --- a/src/Symfony/Component/Validator/Constraints/LengthValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LengthValidator.php @@ -47,7 +47,7 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->exactMessage, array( '{{ value }}' => $stringValue, '{{ limit }}' => $constraint->min, - ), $value, (int) $constraint->min); + ), $value, (int) $constraint->min, $constraint::ERROR); return; } @@ -56,7 +56,7 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->maxMessage, array( '{{ value }}' => $stringValue, '{{ limit }}' => $constraint->max, - ), $value, (int) $constraint->max); + ), $value, (int) $constraint->max, $constraint::ERROR_MAX); return; } @@ -65,7 +65,7 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->minMessage, array( '{{ value }}' => $stringValue, '{{ limit }}' => $constraint->min, - ), $value, (int) $constraint->min); + ), $value, (int) $constraint->min, $constraint::ERROR_MIN); } } } diff --git a/src/Symfony/Component/Validator/Constraints/LessThan.php b/src/Symfony/Component/Validator/Constraints/LessThan.php index 3d30ba25d3bd3..5024b901ff501 100644 --- a/src/Symfony/Component/Validator/Constraints/LessThan.php +++ b/src/Symfony/Component/Validator/Constraints/LessThan.php @@ -18,5 +18,7 @@ */ class LessThan extends AbstractComparison { + const ERROR = '16a4f865-0060-40e9-9d60-8ab113bfb293'; + public $message = 'This value should be less than {{ compared_value }}.'; } diff --git a/src/Symfony/Component/Validator/Constraints/LessThanOrEqual.php b/src/Symfony/Component/Validator/Constraints/LessThanOrEqual.php index 5171c359af614..eb87b0fd3ebfc 100644 --- a/src/Symfony/Component/Validator/Constraints/LessThanOrEqual.php +++ b/src/Symfony/Component/Validator/Constraints/LessThanOrEqual.php @@ -18,5 +18,7 @@ */ class LessThanOrEqual extends AbstractComparison { + const ERROR = '8bb5f334-d139-4821-ad09-00c63d55b5a8'; + public $message = 'This value should be less than or equal to {{ compared_value }}.'; } diff --git a/src/Symfony/Component/Validator/Constraints/Locale.php b/src/Symfony/Component/Validator/Constraints/Locale.php index 9cdd7880d047d..be96bfeec7291 100644 --- a/src/Symfony/Component/Validator/Constraints/Locale.php +++ b/src/Symfony/Component/Validator/Constraints/Locale.php @@ -22,5 +22,7 @@ */ class Locale extends Constraint { + const ERROR = 'ccf90455-5e51-47d9-a927-61a31dc4338c'; + public $message = 'This value is not a valid locale.'; } diff --git a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php index 97c6aed97733a..f27b68b1afcde 100644 --- a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php @@ -42,7 +42,7 @@ public function validate($value, Constraint $constraint) $locales = Intl::getLocaleBundle()->getLocaleNames(); if (!isset($locales[$value])) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Luhn.php b/src/Symfony/Component/Validator/Constraints/Luhn.php index f8fd35c6c8038..b317e0958c973 100644 --- a/src/Symfony/Component/Validator/Constraints/Luhn.php +++ b/src/Symfony/Component/Validator/Constraints/Luhn.php @@ -20,5 +20,7 @@ */ class Luhn extends Constraint { + const ERROR = 'e146c87e-3063-47ad-bde0-37cd2f5f117b'; + public $message = 'Invalid card number.'; } diff --git a/src/Symfony/Component/Validator/Constraints/LuhnValidator.php b/src/Symfony/Component/Validator/Constraints/LuhnValidator.php index 0b60eee159c9b..348a83963c037 100644 --- a/src/Symfony/Component/Validator/Constraints/LuhnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LuhnValidator.php @@ -39,7 +39,7 @@ public function validate($value, Constraint $constraint) } if (!is_numeric($value)) { - $this->context->addViolation($constraint->message); + $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR); return; } @@ -52,7 +52,7 @@ public function validate($value, Constraint $constraint) } if ($sum === 0 || ($sum % 10) !== 0) { - $this->context->addViolation($constraint->message); + $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/NotBlank.php b/src/Symfony/Component/Validator/Constraints/NotBlank.php index 4365ca298ae81..802437a5a8980 100644 --- a/src/Symfony/Component/Validator/Constraints/NotBlank.php +++ b/src/Symfony/Component/Validator/Constraints/NotBlank.php @@ -22,5 +22,7 @@ */ class NotBlank extends Constraint { + const ERROR = 'ca626403-7b11-487f-9dfb-c177a9040ce7'; + public $message = 'This value should not be blank.'; } diff --git a/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php b/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php index dd3dbdd8498a1..e16017c0dbaa8 100644 --- a/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php @@ -27,7 +27,7 @@ class NotBlankValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (false === $value || (empty($value) && '0' != $value)) { - $this->context->addViolation($constraint->message); + $this->context->addViolation($constraint->message, array(), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/NotEqualTo.php b/src/Symfony/Component/Validator/Constraints/NotEqualTo.php index c532565978e58..4ccbcffc15dc7 100644 --- a/src/Symfony/Component/Validator/Constraints/NotEqualTo.php +++ b/src/Symfony/Component/Validator/Constraints/NotEqualTo.php @@ -18,5 +18,7 @@ */ class NotEqualTo extends AbstractComparison { + const ERROR = 'fc9de329-a897-45c9-8fea-83ea2d1c8aed'; + public $message = 'This value should not be equal to {{ compared_value }}.'; } diff --git a/src/Symfony/Component/Validator/Constraints/NotIdenticalTo.php b/src/Symfony/Component/Validator/Constraints/NotIdenticalTo.php index 49da8586bbb5f..809fa1f6f7a8e 100644 --- a/src/Symfony/Component/Validator/Constraints/NotIdenticalTo.php +++ b/src/Symfony/Component/Validator/Constraints/NotIdenticalTo.php @@ -18,5 +18,7 @@ */ class NotIdenticalTo extends AbstractComparison { + const ERROR = '2c96e376-8e6f-488c-9936-840a73fd3163'; + public $message = 'This value should not be identical to {{ compared_value_type }} {{ compared_value }}.'; } diff --git a/src/Symfony/Component/Validator/Constraints/NotNull.php b/src/Symfony/Component/Validator/Constraints/NotNull.php index 6b1c7c0836325..8a9d1d781afdb 100644 --- a/src/Symfony/Component/Validator/Constraints/NotNull.php +++ b/src/Symfony/Component/Validator/Constraints/NotNull.php @@ -22,5 +22,7 @@ */ class NotNull extends Constraint { + const ERROR = '80ab39d6-9e19-4191-afd9-03aab806e7b8'; + public $message = 'This value should not be null.'; } diff --git a/src/Symfony/Component/Validator/Constraints/NotNullValidator.php b/src/Symfony/Component/Validator/Constraints/NotNullValidator.php index 4ee65928ef0e0..e83a354e6e7a4 100644 --- a/src/Symfony/Component/Validator/Constraints/NotNullValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NotNullValidator.php @@ -27,7 +27,7 @@ class NotNullValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (null === $value) { - $this->context->addViolation($constraint->message); + $this->context->addViolation($constraint->message, array(), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Null.php b/src/Symfony/Component/Validator/Constraints/Null.php index e0a00221d1978..725bfe88fc64b 100644 --- a/src/Symfony/Component/Validator/Constraints/Null.php +++ b/src/Symfony/Component/Validator/Constraints/Null.php @@ -22,5 +22,7 @@ */ class Null extends Constraint { + const ERROR = '05b25fe2-0bfa-4ba3-b0aa-2491f80840a9'; + public $message = 'This value should be null.'; } diff --git a/src/Symfony/Component/Validator/Constraints/NullValidator.php b/src/Symfony/Component/Validator/Constraints/NullValidator.php index e8fa24ed74959..23dc3b1cafabd 100644 --- a/src/Symfony/Component/Validator/Constraints/NullValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NullValidator.php @@ -27,7 +27,7 @@ class NullValidator extends ConstraintValidator public function validate($value, Constraint $constraint) { if (null !== $value) { - $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); + $this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Range.php b/src/Symfony/Component/Validator/Constraints/Range.php index e705175521bba..fa63c2ebf6402 100644 --- a/src/Symfony/Component/Validator/Constraints/Range.php +++ b/src/Symfony/Component/Validator/Constraints/Range.php @@ -23,6 +23,10 @@ */ class Range extends Constraint { + const ERROR = 'bc619de0-7f99-4d29-b5cb-f93bce9f6274'; + const ERROR_MIN = '0be45eb8-3d65-452b-9cbe-3b398c5c08c7'; + const ERROR_MAX = 'ac98b917-6b0a-4bea-8bac-e937064d3b42'; + public $minMessage = 'This value should be {{ limit }} or more.'; public $maxMessage = 'This value should be {{ limit }} or less.'; public $invalidMessage = 'This value should be a valid number.'; diff --git a/src/Symfony/Component/Validator/Constraints/RangeValidator.php b/src/Symfony/Component/Validator/Constraints/RangeValidator.php index 1a8ba15ac35ee..89e2d8eb5d011 100644 --- a/src/Symfony/Component/Validator/Constraints/RangeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/RangeValidator.php @@ -31,7 +31,7 @@ public function validate($value, Constraint $constraint) if (!is_numeric($value)) { $this->context->addViolation($constraint->invalidMessage, array( '{{ value }}' => $value, - )); + ), $value, null, $constraint::ERROR); return; } @@ -40,7 +40,7 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->maxMessage, array( '{{ value }}' => $value, '{{ limit }}' => $constraint->max, - )); + ), $value, null, $constraint::ERROR_MAX); return; } @@ -49,7 +49,7 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->minMessage, array( '{{ value }}' => $value, '{{ limit }}' => $constraint->min, - )); + ), $value, null, $constraint::ERROR_MIN); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Regex.php b/src/Symfony/Component/Validator/Constraints/Regex.php index beec99b1d1911..a968516f84cc2 100644 --- a/src/Symfony/Component/Validator/Constraints/Regex.php +++ b/src/Symfony/Component/Validator/Constraints/Regex.php @@ -22,6 +22,8 @@ */ class Regex extends Constraint { + const ERROR = '3feb30b5-8882-4179-bf27-81155fcc71fc'; + public $message = 'This value is not valid.'; public $pattern; public $htmlPattern = null; diff --git a/src/Symfony/Component/Validator/Constraints/RegexValidator.php b/src/Symfony/Component/Validator/Constraints/RegexValidator.php index c39869d2882b5..d7578fdf83486 100644 --- a/src/Symfony/Component/Validator/Constraints/RegexValidator.php +++ b/src/Symfony/Component/Validator/Constraints/RegexValidator.php @@ -41,7 +41,7 @@ public function validate($value, Constraint $constraint) $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), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Time.php b/src/Symfony/Component/Validator/Constraints/Time.php index e7982ac6d6618..dcfca7328293c 100644 --- a/src/Symfony/Component/Validator/Constraints/Time.php +++ b/src/Symfony/Component/Validator/Constraints/Time.php @@ -22,5 +22,7 @@ */ class Time extends Constraint { + const ERROR = 'a487eb1b-b785-49e0-97d8-b3eb6a165185'; + public $message = 'This value is not a valid time.'; } diff --git a/src/Symfony/Component/Validator/Constraints/TimeValidator.php b/src/Symfony/Component/Validator/Constraints/TimeValidator.php index 31259cc4b3773..4a8e940c6ae85 100644 --- a/src/Symfony/Component/Validator/Constraints/TimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TimeValidator.php @@ -40,7 +40,7 @@ public function validate($value, Constraint $constraint) $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), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/True.php b/src/Symfony/Component/Validator/Constraints/True.php index 9e1d994ba22e2..d7709cd8d7a58 100644 --- a/src/Symfony/Component/Validator/Constraints/True.php +++ b/src/Symfony/Component/Validator/Constraints/True.php @@ -22,5 +22,7 @@ */ class True extends Constraint { + const ERROR = '36f92ba4-67e3-4e0b-a5ca-fe819568ed0d'; + public $message = 'This value should be true.'; } diff --git a/src/Symfony/Component/Validator/Constraints/TrueValidator.php b/src/Symfony/Component/Validator/Constraints/TrueValidator.php index 2fbe0478ce1f0..0da2de8b8446e 100644 --- a/src/Symfony/Component/Validator/Constraints/TrueValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TrueValidator.php @@ -31,7 +31,7 @@ public function validate($value, Constraint $constraint) } if (true !== $value && 1 !== $value && '1' !== $value) { - $this->context->addViolation($constraint->message); + $this->context->addViolation($constraint->message, array(), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Type.php b/src/Symfony/Component/Validator/Constraints/Type.php index cdcc10c91a39a..219492e3187df 100644 --- a/src/Symfony/Component/Validator/Constraints/Type.php +++ b/src/Symfony/Component/Validator/Constraints/Type.php @@ -22,6 +22,8 @@ */ class Type extends Constraint { + const ERROR = 'f42711f9-d10d-4272-9b1c-76de264f642c'; + public $message = 'This value should be of type {{ type }}.'; public $type; diff --git a/src/Symfony/Component/Validator/Constraints/TypeValidator.php b/src/Symfony/Component/Validator/Constraints/TypeValidator.php index ecc88dfbd16d1..44e18085982a8 100644 --- a/src/Symfony/Component/Validator/Constraints/TypeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TypeValidator.php @@ -46,6 +46,6 @@ public function validate($value, Constraint $constraint) $this->context->addViolation($constraint->message, array( '{{ value }}' => is_object($value) ? get_class($value) : (is_array($value) ? 'Array' : (string) $value), '{{ type }}' => $constraint->type, - )); + ), $value, null, $constraint::ERROR); } } diff --git a/src/Symfony/Component/Validator/Constraints/Url.php b/src/Symfony/Component/Validator/Constraints/Url.php index 3585e1b0183eb..7016db5a14996 100644 --- a/src/Symfony/Component/Validator/Constraints/Url.php +++ b/src/Symfony/Component/Validator/Constraints/Url.php @@ -22,6 +22,8 @@ */ class Url extends Constraint { + const ERROR = '23af3103-a5ca-4459-b0ae-3a2043479a98'; + public $message = 'This value is not a valid URL.'; public $protocols = array('http', 'https'); } diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index 1fc380ea9e7cd..c02ade176f925 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -55,7 +55,7 @@ public function validate($value, Constraint $constraint) $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), $value, null, $constraint::ERROR); } } } diff --git a/src/Symfony/Component/Validator/ExecutionContextInterface.php b/src/Symfony/Component/Validator/ExecutionContextInterface.php index 0b6c86633d6e5..042ab71483af9 100644 --- a/src/Symfony/Component/Validator/ExecutionContextInterface.php +++ b/src/Symfony/Component/Validator/ExecutionContextInterface.php @@ -92,7 +92,7 @@ interface ExecutionContextInterface * @param array $params The parameters substituted in the error message. * @param mixed $invalidValue The invalid, validated value. * @param integer|null $pluralization The number to use to pluralize of the message. - * @param integer|null $code The violation code. + * @param mixed $code The violation code. * * @api */ @@ -107,7 +107,7 @@ public function addViolation($message, array $params = array(), $invalidValue = * @param array $params The parameters substituted in the error message. * @param mixed $invalidValue The invalid, validated value. * @param integer|null $pluralization The number to use to pluralize of the message. - * @param integer|null $code The violation code. + * @param mixed $code The violation code. * * @api */ diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php index 36405e3de88e5..262465be84f6b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php @@ -105,7 +105,7 @@ public function testInvalidComparisonToValue($dirtyValue, $comparedValue, $compa '{{ value }}' => $comparedValueString, '{{ compared_value }}' => $comparedValueString, '{{ compared_value_type }}' => $comparedValueType - )); + ), $comparedValue, null, $constraint::ERROR); $this->validator->validate($dirtyValue, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php index 0fbe5e6fbb0d0..f7b27e0d60b84 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php @@ -61,7 +61,7 @@ public function testInvalidValues($value) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $value, - )); + ), $this->identicalTo($value), null, Blank::ERROR); $this->validator->validate($value, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php index ee7cc7a60a381..f4b5aefacc266 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php @@ -64,10 +64,16 @@ public function testValidNumbers($scheme, $number) */ public function testInvalidNumbers($scheme, $number) { + $constraint = new CardScheme(array( + 'schemes' => $scheme, + 'message' => 'myMessage' + )); + $this->context->expects($this->once()) - ->method('addViolation'); + ->method('addViolation') + ->with('myMessage', array(), $this->identicalTo($number), null, CardScheme::ERROR); - $this->validator->validate($number, new CardScheme(array('schemes' => $scheme))); + $this->validator->validate($number, $constraint); } public function getValidNumbers() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php index c1618b6771c18..655f2bc46813b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php @@ -14,7 +14,7 @@ use Symfony\Component\Validator\Constraints\Choice; use Symfony\Component\Validator\Constraints\ChoiceValidator; -function choice_callback() +function choiceCallback() { return array('foo', 'bar'); } @@ -95,7 +95,7 @@ public function testValidChoiceArray() public function testValidChoiceCallbackFunction() { - $constraint = new Choice(array('callback' => __NAMESPACE__.'\choice_callback')); + $constraint = new Choice(array('callback' => __NAMESPACE__.'\choiceCallback')); $this->context->expects($this->never()) ->method('addViolation'); @@ -105,7 +105,7 @@ public function testValidChoiceCallbackFunction() public function testValidChoiceCallbackClosure() { - $constraint = new Choice(array('callback' => function() { + $constraint = new Choice(array('callback' => function () { return array('foo', 'bar'); })); @@ -159,7 +159,7 @@ public function testInvalidChoice() ->method('addViolation') ->with('myMessage', array( '{{ value }}' => 'baz', - ), null, null); + ), $this->identicalTo('baz'), null, Choice::ERROR); $this->validator->validate('baz', $constraint); } @@ -176,7 +176,7 @@ public function testInvalidChoiceMultiple() ->method('addViolation') ->with('myMessage', array( '{{ value }}' => 'baz', - )); + ), $this->identicalTo('baz'), null, Choice::ERROR_MULTIPLE); $this->validator->validate(array('foo', 'baz'), $constraint); } @@ -194,7 +194,7 @@ public function testTooFewChoices() ->method('addViolation') ->with('myMessage', array( '{{ limit }}' => 2, - ), null, 2); + ), null, 2, Choice::ERROR_MIN); $this->validator->validate(array('foo'), $constraint); } @@ -212,7 +212,7 @@ public function testTooManyChoices() ->method('addViolation') ->with('myMessage', array( '{{ limit }}' => 2, - ), null, 2); + ), null, 2, Choice::ERROR_MAX); $this->validator->validate(array('foo', 'bar', 'moo'), $constraint); } @@ -256,7 +256,7 @@ public function testStrictDisallowsDifferentType() ->method('addViolation') ->with('myMessage', array( '{{ value }}' => '2', - )); + ), $this->identicalTo('2'), null, Choice::ERROR); $this->validator->validate('2', $constraint); } @@ -288,7 +288,7 @@ public function testStrictWithMultipleChoices() ->method('addViolation') ->with('myMessage', array( '{{ value }}' => '3', - )); + ), $this->identicalTo('3'), null, Choice::ERROR_MULTIPLE); $this->validator->validate(array(2, '3'), $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php index 4a13234b69550..fd80dc6100393 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php @@ -148,7 +148,7 @@ public function testExtraFieldsDisallowed() ->method('addViolationAt') ->with('[baz]', 'myMessage', array( '{{ field }}' => 'baz' - )); + ), 'baz', null, Collection::ERROR_EXTRA_FIELD); $this->validator->validate($data, new Collection(array( 'fields' => array( @@ -212,7 +212,7 @@ public function testMissingFieldsDisallowed() ->method('addViolationAt') ->with('[foo]', 'myMessage', array( '{{ field }}' => 'foo', - )); + ), 'foo', Collection::ERROR_MISSING_FIELD); $this->validator->validate($data, $constraint); } @@ -332,7 +332,7 @@ public function testRequiredFieldNotPresent() ->method('addViolationAt') ->with('[foo]', 'myMessage', array( '{{ field }}' => 'foo', - )); + ), 'foo', Collection::ERROR_MISSING_FIELD); $this->validator->validate($data, new Collection(array( 'fields' => array( diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php index 9c4a38d56c7e3..5b3b280b5439f 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php @@ -139,7 +139,7 @@ public function testInvalidValuesMax($value) ->with('myMessage', $this->identicalTo(array( '{{ count }}' => count($value), '{{ limit }}' => 4, - )), $value, 4); + )), $value, 4, Count::ERROR_MAX); $this->validator->validate($value, $constraint); } @@ -159,7 +159,7 @@ public function testInvalidValuesMin($value) ->with('myMessage', $this->identicalTo(array( '{{ count }}' => count($value), '{{ limit }}' => 4, - )), $value, 4); + )), $value, 4, Count::ERROR_MIN); $this->validator->validate($value, $constraint); } @@ -180,7 +180,7 @@ public function testInvalidValuesExact($value) ->with('myMessage', $this->identicalTo(array( '{{ count }}' => count($value), '{{ limit }}' => 4, - )), $value, 4); + )), $value, 4, Count::ERROR_EXACT); $this->validator->validate($value, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php index 95851e8097ad7..da3ded9b24f62 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php @@ -92,7 +92,7 @@ public function testInvalidCountries($country) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $country, - )); + ), $country, Country::ERROR); $this->validator->validate($country, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php index d2e233ca3798c..8967723c42f51 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php @@ -94,7 +94,7 @@ public function testInvalidCurrencies($currency) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $currency, - )); + ), $currency, null, Currency::ERROR); $this->validator->validate($currency, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php index 0776848fdbd47..be4e4a2a75233 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php @@ -97,7 +97,7 @@ public function testInvalidDateTimes($dateTime) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $dateTime, - )); + ), $dateTime, null, DateTime::ERROR); $this->validator->validate($dateTime, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php index b9cf8816b76a5..c3252af064a3c 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php @@ -97,7 +97,7 @@ public function testInvalidDates($date) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $date, - )); + ), $date, null, Date::ERROR); $this->validator->validate($date, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php index 701ab1f556df2..c45a4b7960425 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php @@ -89,7 +89,7 @@ public function testInvalidEmails($email) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $email, - )); + ), $email, null, Email::ERROR); $this->validator->validate($email, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FalseValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FalseValidatorTest.php index 1bc16c20bd48a..68999472149cd 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FalseValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FalseValidatorTest.php @@ -56,7 +56,20 @@ public function testTrueIsInvalid() $this->context->expects($this->once()) ->method('addViolation') - ->with('myMessage', array()); + ->with('myMessage', array(), true, null, False::ERROR); + + $this->validator->validate(true, $constraint); + } + + public function testReturnedCode() + { + $constraint = new False(array( + 'message' => 'myMessage', + )); + + $this->context->expects($this->once()) + ->method('addViolation') + ->with('myMessage', array(), true, null, False::ERROR); $this->validator->validate(true, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php index c4b93cdcd3424..016b4c0da4e13 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php @@ -30,7 +30,7 @@ public function testFileNotFound() ->method('addViolation') ->with('myMessage', array( '{{ file }}' => 'foobar', - )); + ), 'foobar', null, File::ERROR_NOT_FOUND); $this->validator->validate('foobar', $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php index 0927aedacdd5c..20ccc0a11babf 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php @@ -98,7 +98,7 @@ public function testTooLargeBytes() '{{ size }}' => '11', '{{ suffix }}' => 'bytes', '{{ file }}' => $this->path, - )); + ), $this->path, null, File::ERROR_MAX_SIZE); $this->validator->validate($this->getFile($this->path), $constraint); } @@ -119,7 +119,7 @@ public function testTooLargeKiloBytes() '{{ size }}' => '1.4', '{{ suffix }}' => 'kB', '{{ file }}' => $this->path, - )); + ), $this->path, null, File::ERROR_MAX_SIZE); $this->validator->validate($this->getFile($this->path), $constraint); } @@ -140,7 +140,7 @@ public function testTooLargeMegaBytes() '{{ size }}' => '1.4', '{{ suffix }}' => 'MB', '{{ file }}' => $this->path, - )); + ), $this->path, null, File::ERROR_MAX_SIZE); $this->validator->validate($this->getFile($this->path), $constraint); } @@ -242,7 +242,7 @@ public function testInvalidMimeType() '{{ type }}' => '"application/pdf"', '{{ types }}' => '"image/png", "image/jpg"', '{{ file }}' => $this->path, - )); + ), $file, null, File::ERROR_MIME_TYPE); $this->validator->validate($file, $constraint); } @@ -276,7 +276,7 @@ public function testInvalidWildcardMimeType() '{{ type }}' => '"application/pdf"', '{{ types }}' => '"image/*", "image/jpg"', '{{ file }}' => $this->path, - )); + ), $file, null, File::ERROR_MIME_TYPE); $this->validator->validate($file, $constraint); } @@ -284,7 +284,7 @@ public function testInvalidWildcardMimeType() /** * @dataProvider uploadedFileErrorProvider */ - public function testUploadedFileError($error, $message, array $params = array(), $maxSize = null) + public function testUploadedFileError($error, $message, $constraintErrorCode, array $params = array(), $maxSize = null) { $file = new UploadedFile('/path/to/file', 'originalName', 'mime', 0, $error); @@ -295,7 +295,7 @@ public function testUploadedFileError($error, $message, array $params = array(), $this->context->expects($this->once()) ->method('addViolation') - ->with('myMessage', $params); + ->with('myMessage', $params, $file, null, $constraintErrorCode); $this->validator->validate($file, $constraint); @@ -304,30 +304,30 @@ public function testUploadedFileError($error, $message, array $params = array(), public function uploadedFileErrorProvider() { $tests = array( - array(UPLOAD_ERR_FORM_SIZE, 'uploadFormSizeErrorMessage'), - array(UPLOAD_ERR_PARTIAL, 'uploadPartialErrorMessage'), - array(UPLOAD_ERR_NO_FILE, 'uploadNoFileErrorMessage'), - array(UPLOAD_ERR_NO_TMP_DIR, 'uploadNoTmpDirErrorMessage'), - array(UPLOAD_ERR_CANT_WRITE, 'uploadCantWriteErrorMessage'), - array(UPLOAD_ERR_EXTENSION, 'uploadExtensionErrorMessage'), + array(UPLOAD_ERR_FORM_SIZE, 'uploadFormSizeErrorMessage', File::ERROR_UPLOAD_FORM_SIZE), + array(UPLOAD_ERR_PARTIAL, 'uploadPartialErrorMessage', File::ERROR_UPLOAD_PARTIAL), + array(UPLOAD_ERR_NO_FILE, 'uploadNoFileErrorMessage', File::ERROR_UPLOAD_NO_FILE), + array(UPLOAD_ERR_NO_TMP_DIR, 'uploadNoTmpDirErrorMessage', File::ERROR_UPLOAD_NO_TMP_DIR), + array(UPLOAD_ERR_CANT_WRITE, 'uploadCantWriteErrorMessage', File::ERROR_UPLOAD_CANT_WRITE), + array(UPLOAD_ERR_EXTENSION, 'uploadExtensionErrorMessage', File::ERROR_UPLOAD_EXTENSION), ); if (class_exists('Symfony\Component\HttpFoundation\File\UploadedFile')) { // when no maxSize is specified on constraint, it should use the ini value - $tests[] = array(UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', array( + $tests[] = array(UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', File::ERROR_UPLOAD_INI_SIZE, array( '{{ limit }}' => UploadedFile::getMaxFilesize(), '{{ suffix }}' => 'bytes', )); // it should use the smaller limitation (maxSize option in this case) - $tests[] = array(UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', array( + $tests[] = array(UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', File::ERROR_UPLOAD_INI_SIZE, array( '{{ limit }}' => 1, '{{ suffix }}' => 'bytes', ), '1'); // it correctly parses the maxSize option and not only uses simple string comparison // 1000M should be bigger than the ini value - $tests[] = array(UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', array( + $tests[] = array(UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', File::ERROR_UPLOAD_INI_SIZE, array( '{{ limit }}' => UploadedFile::getMaxFilesize(), '{{ suffix }}' => 'bytes', ), '1000M'); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php index cfd9f2cd8f438..c871232f51a35 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php @@ -165,7 +165,7 @@ public function testInvalidIbans($iban) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $iban, - )); + ), $iban, null, Iban::ERROR); $this->validator->validate($iban, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php index 114c2d2f0499e..237447d3b7513 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php @@ -84,7 +84,7 @@ public function testWidthTooSmall() ->with('myMessage', array( '{{ width }}' => '2', '{{ min_width }}' => '3', - )); + ), $this->image, null, Image::ERROR_MIN_WIDTH); $this->validator->validate($this->image, $constraint); } @@ -101,7 +101,7 @@ public function testWidthTooBig() ->with('myMessage', array( '{{ width }}' => '2', '{{ max_width }}' => '1', - )); + ), $this->image, null, Image::ERROR_MAX_WIDTH); $this->validator->validate($this->image, $constraint); } @@ -118,7 +118,7 @@ public function testHeightTooSmall() ->with('myMessage', array( '{{ height }}' => '2', '{{ min_height }}' => '3', - )); + ), $this->image, null, Image::ERROR_MIN_HEIGHT); $this->validator->validate($this->image, $constraint); } @@ -135,7 +135,7 @@ public function testHeightTooBig() ->with('myMessage', array( '{{ height }}' => '2', '{{ max_height }}' => '1', - )); + ), $this->image, null, Image::ERROR_MAX_HEIGHT); $this->validator->validate($this->image, $constraint); } @@ -200,7 +200,7 @@ public function testRatioTooSmall() ->with('myMessage', array( '{{ ratio }}' => 1, '{{ min_ratio }}' => 2, - )); + ), $this->image, null, Image::ERROR_MIN_RATIO); $this->validator->validate($this->image, $constraint); } @@ -217,7 +217,7 @@ public function testRatioTooBig() ->with('myMessage', array( '{{ ratio }}' => 1, '{{ max_ratio }}' => 0.5, - )); + ), $this->image, null, Image::ERROR_MAX_RATIO); $this->validator->validate($this->image, $constraint); } @@ -258,7 +258,7 @@ public function testSquareNotAllowed() ->with('myMessage', array( '{{ width }}' => 2, '{{ height }}' => 2, - )); + ), $this->image, null, Image::ERROR_DONT_ALLOW_SQUARE); $this->validator->validate($this->image, $constraint); } @@ -275,7 +275,7 @@ public function testLandscapeNotAllowed() ->with('myMessage', array( '{{ width }}' => 2, '{{ height }}' => 1, - )); + ), $this->imageLandscape, null, Image::ERROR_DONT_ALLOW_LANDSCAPE); $this->validator->validate($this->imageLandscape, $constraint); } @@ -292,7 +292,7 @@ public function testPortraitNotAllowed() ->with('myMessage', array( '{{ width }}' => 1, '{{ height }}' => 2, - )); + ), $this->imagePortrait, null, Image::ERROR_DONT_ALLOW_PORTRAIT); $this->validator->validate($this->imagePortrait, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php index bdf61928802f2..9c11d5bf561c6 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php @@ -163,7 +163,7 @@ public function testInvalidIpsV4($ip) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $ip, - )); + ), $ip, null, Ip::ERROR); $this->validator->validate($ip, $constraint); } @@ -197,7 +197,7 @@ public function testInvalidPrivateIpsV4($ip) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $ip, - )); + ), $ip, null, Ip::ERROR); $this->validator->validate($ip, $constraint); } @@ -225,7 +225,7 @@ public function testInvalidReservedIpsV4($ip) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $ip, - )); + ), $ip, null, Ip::ERROR); $this->validator->validate($ip, $constraint); } @@ -253,7 +253,7 @@ public function testInvalidPublicIpsV4($ip) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $ip, - )); + ), $ip, null, Ip::ERROR); $this->validator->validate($ip, $constraint); } @@ -277,7 +277,7 @@ public function testInvalidIpsV6($ip) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $ip, - )); + ), $ip, null, Ip::ERROR); $this->validator->validate($ip, $constraint); } @@ -315,7 +315,7 @@ public function testInvalidPrivateIpsV6($ip) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $ip, - )); + ), $ip, null, Ip::ERROR); $this->validator->validate($ip, $constraint); } @@ -343,7 +343,7 @@ public function testInvalidReservedIpsV6($ip) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $ip, - )); + ), $ip, null, Ip::ERROR); $this->validator->validate($ip, $constraint); } @@ -370,7 +370,7 @@ public function testInvalidPublicIpsV6($ip) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $ip, - )); + ), $ip, null, Ip::ERROR); $this->validator->validate($ip, $constraint); } @@ -394,7 +394,7 @@ public function testInvalidIpsAll($ip) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $ip, - )); + ), $ip, null, Ip::ERROR); $this->validator->validate($ip, $constraint); } @@ -418,7 +418,7 @@ public function testInvalidPrivateIpsAll($ip) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $ip, - )); + ), $ip, null, Ip::ERROR); $this->validator->validate($ip, $constraint); } @@ -442,7 +442,7 @@ public function testInvalidReservedIpsAll($ip) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $ip, - )); + ), $ip, null, Ip::ERROR); $this->validator->validate($ip, $constraint); } @@ -466,7 +466,7 @@ public function testInvalidPublicIpsAll($ip) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $ip, - )); + ), $ip, null, Ip::ERROR); $this->validator->validate($ip, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IsbnValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IsbnValidatorTest.php index 7f0859b999e08..127b2101a8695 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IsbnValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IsbnValidatorTest.php @@ -162,7 +162,9 @@ public function testInvalidIsbn10($isbn) $this->context ->expects($this->once()) ->method('addViolation') - ->with($constraint->isbn10Message); + ->with($constraint->isbn10Message, array( + '{{ value }}' => $isbn, + ), $isbn, null, Isbn::ERROR_ISBN10); $this->validator->validate($isbn, $constraint); } @@ -189,7 +191,9 @@ public function testInvalidIsbn13($isbn) $this->context ->expects($this->once()) ->method('addViolation') - ->with($constraint->isbn13Message); + ->with($constraint->isbn13Message, array( + '{{ value }}' => $isbn, + ), $isbn, null, Isbn::ERROR_ISBN13); $this->validator->validate($isbn, $constraint); } @@ -216,7 +220,9 @@ public function testInvalidIsbn($isbn) $this->context ->expects($this->once()) ->method('addViolation') - ->with($constraint->bothIsbnMessage); + ->with($constraint->bothIsbnMessage, array( + '{{ value }}' => $isbn, + ), $isbn, null, Isbn::ERROR); $this->validator->validate($isbn, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IssnValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IssnValidatorTest.php index d9e48846625ed..a9153a9542d39 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IssnValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IssnValidatorTest.php @@ -145,7 +145,9 @@ public function testCaseSensitiveIssns($issn) $this->context ->expects($this->once()) ->method('addViolation') - ->with($constraint->message); + ->with($constraint->message, array( + '{{ value }}' => $issn, + ), $issn, null, Issn::ERROR); $this->validator->validate($issn, $constraint); } @@ -159,7 +161,9 @@ public function testRequireHyphenIssns($issn) $this->context ->expects($this->once()) ->method('addViolation') - ->with($constraint->message); + ->with($constraint->message, array( + '{{ value }}' => $issn, + ), $issn, null, Issn::ERROR); $this->validator->validate($issn, $constraint); } @@ -186,7 +190,9 @@ public function testInvalidFormatIssn($issn) $this->context ->expects($this->once()) ->method('addViolation') - ->with($constraint->message); + ->with($constraint->message, array( + '{{ value }}' => $issn, + ), $issn, null, Issn::ERROR); $this->validator->validate($issn, $constraint); } @@ -200,7 +206,9 @@ public function testInvalidValueIssn($issn) $this->context ->expects($this->once()) ->method('addViolation') - ->with($constraint->message); + ->with($constraint->message, array( + '{{ value }}' => $issn, + ), $issn, null, Issn::ERROR); $this->validator->validate($issn, $constraint); } @@ -213,7 +221,9 @@ public function testInvalidIssn($issn) $constraint = new Issn(); $this->context ->expects($this->once()) - ->method('addViolation'); + ->method('addViolation', array( + '{{ value }}' => $issn, + ), $issn, null, Issn::ERROR); $this->validator->validate($issn, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php index 3588887d74998..afc8543e4f0d6 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php @@ -92,7 +92,7 @@ public function testInvalidLanguages($language) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $language, - )); + ), $language, null, Language::ERROR); $this->validator->validate($language, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php index db6339449d90e..ad471065b48e2 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php @@ -169,7 +169,7 @@ public function testInvalidValuesMin($value, $mbOnly = false) ->with('myMessage', $this->identicalTo(array( '{{ value }}' => (string) $value, '{{ limit }}' => 4, - )), $this->identicalTo($value), 4); + )), $this->identicalTo($value), 4, Length::ERROR_MIN); $this->validator->validate($value, $constraint); } @@ -193,7 +193,7 @@ public function testInvalidValuesMax($value, $mbOnly = false) ->with('myMessage', $this->identicalTo(array( '{{ value }}' => (string) $value, '{{ limit }}' => 4, - )), $this->identicalTo($value), 4); + )), $this->identicalTo($value), 4, Length::ERROR_MAX); $this->validator->validate($value, $constraint); } @@ -218,7 +218,7 @@ public function testInvalidValuesExact($value, $mbOnly = false) ->with('myMessage', $this->identicalTo(array( '{{ value }}' => (string) $value, '{{ limit }}' => 4, - )), $this->identicalTo($value), 4); + )), $this->identicalTo($value), 4, Length::ERROR); $this->validator->validate($value, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php index 41feba0c7123a..811c370d3ee6a 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php @@ -94,7 +94,7 @@ public function testInvalidLocales($locale) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $locale, - )); + ), $locale, null, Locale::ERROR); $this->validator->validate($locale, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php index 963710860b172..f099b89fa0311 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php @@ -92,7 +92,9 @@ public function testInvalidNumbers($number) $this->context->expects($this->once()) ->method('addViolation') - ->with($constraint->message); + ->with($constraint->message, array( + '{{ value }}' => $number, + ), $number, null, Luhn::ERROR); $this->validator->validate($number, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php index 85db95ddca6f1..7423153a4feb8 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php @@ -62,7 +62,7 @@ public function testNullIsInvalid() $this->context->expects($this->once()) ->method('addViolation') - ->with('myMessage'); + ->with('myMessage', array(), null, null, NotBlank::ERROR); $this->validator->validate(null, $constraint); } @@ -75,7 +75,7 @@ public function testBlankIsInvalid() $this->context->expects($this->once()) ->method('addViolation') - ->with('myMessage'); + ->with('myMessage', array(), '', null, NotBlank::ERROR); $this->validator->validate('', $constraint); } @@ -88,7 +88,7 @@ public function testFalseIsInvalid() $this->context->expects($this->once()) ->method('addViolation') - ->with('myMessage'); + ->with('myMessage', array(), false, null, NotBlank::ERROR); $this->validator->validate(false, $constraint); } @@ -101,7 +101,7 @@ public function testEmptyArrayIsInvalid() $this->context->expects($this->once()) ->method('addViolation') - ->with('myMessage'); + ->with('myMessage', array(), array(), null, NotBlank::ERROR); $this->validator->validate(array(), $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php index 96f74a1ba02ac..ac230d7e9904b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php @@ -62,7 +62,7 @@ public function testNullIsInvalid() $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - )); + ), null, null, NotNull::ERROR); $this->validator->validate(null, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NullValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NullValidatorTest.php index 4466aa17c9df6..89bb7192e8c73 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NullValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NullValidatorTest.php @@ -53,7 +53,7 @@ public function testInvalidValues($value) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $value, - )); + ), $value, null, Null::ERROR); $this->validator->validate($value, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php index c44b0ea6ce439..5cb275b224785 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php @@ -119,7 +119,7 @@ public function testInvalidValuesMin($value) ->with('myMessage', $this->identicalTo(array( '{{ value }}' => $value, '{{ limit }}' => 10, - ))); + )), $value, null, Range::ERROR_MIN); $this->validator->validate($value, $constraint); } @@ -139,7 +139,7 @@ public function testInvalidValuesMax($value) ->with('myMessage', $this->identicalTo(array( '{{ value }}' => $value, '{{ limit }}' => 20, - ))); + )), $value, null, Range::ERROR_MAX); $this->validator->validate($value, $constraint); } @@ -161,7 +161,7 @@ public function testInvalidValuesCombinedMax($value) ->with('myMaxMessage', $this->identicalTo(array( '{{ value }}' => $value, '{{ limit }}' => 20, - ))); + )), $value, null, Range::ERROR_MAX); $this->validator->validate($value, $constraint); } @@ -183,7 +183,7 @@ public function testInvalidValuesCombinedMin($value) ->with('myMinMessage', $this->identicalTo(array( '{{ value }}' => $value, '{{ limit }}' => 10, - ))); + )), $value, null, Range::ERROR_MIN); $this->validator->validate($value, $constraint); } @@ -212,7 +212,7 @@ public function testMinMessageIsSet() ->with('myMessage', array( '{{ value }}' => 9, '{{ limit }}' => 10, - )); + ), 9, null, Range::ERROR_MIN); $this->validator->validate(9, $constraint); } @@ -230,7 +230,7 @@ public function testMaxMessageIsSet() ->with('myMessage', array( '{{ value }}' => 21, '{{ limit }}' => 20, - )); + ), 21, null, Range::ERROR_MAX); $this->validator->validate(21, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php index 1ea79fb8e29b1..03344e94fc8d5 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php @@ -92,7 +92,7 @@ public function testInvalidValues($value) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $value, - )); + ), $value, null, Regex::ERROR); $this->validator->validate($value, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php index ba398ab373b16..a15f507c7678b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php @@ -97,7 +97,7 @@ public function testInvalidTimes($time) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $time, - )); + ), $time, null, Time::ERROR); $this->validator->validate($time, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TrueValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TrueValidatorTest.php index 25901793a07bb..9c5480e09a6bc 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TrueValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TrueValidatorTest.php @@ -57,7 +57,7 @@ public function testFalseIsInvalid() $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( - )); + ), false, null, True::ERROR); $this->validator->validate(false, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php index e5e6d0bf025e7..392263cb22a5f 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php @@ -52,10 +52,19 @@ public function testEmptyIsValidIfString() public function testEmptyIsInvalidIfNoString() { + $constraint = new Type(array( + 'type' => 'integer', + 'message' => 'myMessage' + )); + $this->context->expects($this->once()) - ->method('addViolation'); + ->method('addViolation') + ->with('myMessage', array( + '{{ value }}' => '', + '{{ type }}' => 'integer' + ), '', null, Type::ERROR); - $this->validator->validate('', new Type(array('type' => 'integer'))); + $this->validator->validate('', $constraint); } /** @@ -123,7 +132,7 @@ public function testInvalidValues($value, $type, $valueAsString) ->with('myMessage', array( '{{ value }}' => $valueAsString, '{{ type }}' => $type, - )); + ), $this->identicalTo($value), null, Type::ERROR); $this->validator->validate($value, $constraint); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php index b335ae30a82f3..294b36853583b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php @@ -117,7 +117,7 @@ public function testInvalidUrls($url) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => $url, - )); + ), $url, null, Url::ERROR); $this->validator->validate($url, $constraint); }