diff --git a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php index 44dfc853dfe5..3cf2cbcc6b0e 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php @@ -159,7 +159,10 @@ public function testValidateUniqueness() $this->validator->validate($entity2, $constraint); - $this->assertViolation('myMessage', array(), 'property.path.name', 'Foo'); + $this->buildViolation('myMessage') + ->atPath('property.path.name') + ->setInvalidValue('Foo') + ->assertRaised(); } public function testValidateCustomErrorPath() @@ -179,7 +182,10 @@ public function testValidateCustomErrorPath() $this->validator->validate($entity2, $constraint); - $this->assertViolation('myMessage', array(), 'property.path.bar', 'Foo'); + $this->buildViolation('myMessage') + ->atPath('property.path.bar') + ->setInvalidValue('Foo') + ->assertRaised(); } public function testValidateUniquenessWithNull() @@ -227,7 +233,10 @@ public function testValidateUniquenessWithIgnoreNull() $this->validator->validate($entity2, $constraint); - $this->assertViolation('myMessage', array(), 'property.path.name', 'Foo'); + $this->buildViolation('myMessage') + ->atPath('property.path.name') + ->setInvalidValue('Foo') + ->assertRaised(); } public function testValidateUniquenessUsingCustomRepositoryMethod() @@ -321,7 +330,10 @@ public function testAssociatedEntity() $this->validator->validate($associated2, $constraint); - $this->assertViolation('myMessage', array(), 'property.path.single', 1); + $this->buildViolation('myMessage') + ->atPath('property.path.single') + ->setInvalidValue(1) + ->assertRaised(); } public function testAssociatedEntityWithNull() diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php index 8032d6273d38..41c7439ba850 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php @@ -219,10 +219,12 @@ function () { throw new TransformationFailedException(); } $this->validator->validate($form, new Form()); - $this->assertViolation('invalid_message_key', array( - '{{ value }}' => 'foo', - '{{ foo }}' => 'bar', - ), 'property.path', 'foo', null, Form::ERR_INVALID); + $this->buildViolation('invalid_message_key') + ->setParameter('{{ value }}', 'foo') + ->setParameter('{{ foo }}', 'bar') + ->setInvalidValue('foo') + ->setCode(Form::ERR_INVALID) + ->assertRaised(); } public function testAddInvalidErrorEvenIfNoValidationGroups() @@ -251,10 +253,12 @@ function () { throw new TransformationFailedException(); } $this->validator->validate($form, new Form()); - $this->assertViolation('invalid_message_key', array( - '{{ value }}' => 'foo', - '{{ foo }}' => 'bar', - ), 'property.path', 'foo', null, Form::ERR_INVALID); + $this->buildViolation('invalid_message_key') + ->setParameter('{{ value }}', 'foo') + ->setParameter('{{ foo }}', 'bar') + ->setInvalidValue('foo') + ->setCode(Form::ERR_INVALID) + ->assertRaised(); } public function testDontValidateConstraintsIfNotSynchronized() @@ -283,9 +287,11 @@ function () { throw new TransformationFailedException(); } $this->validator->validate($form, new Form()); - $this->assertViolation('invalid_message_key', array( - '{{ value }}' => 'foo', - ), 'property.path','foo', null, Form::ERR_INVALID); + $this->buildViolation('invalid_message_key') + ->setParameter('{{ value }}', 'foo') + ->setInvalidValue('foo') + ->setCode(Form::ERR_INVALID) + ->assertRaised(); } // https://github.com/symfony/symfony/issues/4359 @@ -537,9 +543,10 @@ public function testViolationIfExtraData() $this->validator->validate($form, new Form()); - $this->assertViolation('Extra!', array( - '{{ extra_fields }}' => 'foo', - ), 'property.path', array('foo' => 'bar')); + $this->buildViolation('Extra!') + ->setParameter('{{ extra_fields }}', 'foo') + ->setInvalidValue(array('foo' => 'bar')) + ->assertRaised(); } /** diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php index 8ced06b1bdd1..b7117cc4ea1a 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php @@ -84,11 +84,11 @@ public function testInvalidComparisonToValue($dirtyValue, $dirtyValueAsString, $ $this->validator->validate($dirtyValue, $constraint); - $this->assertViolation('Constraint Message', array( - '{{ value }}' => $dirtyValueAsString, - '{{ compared_value }}' => $comparedValueString, - '{{ compared_value_type }}' => $comparedValueType, - )); + $this->buildViolation('Constraint Message') + ->setParameter('{{ value }}', $dirtyValueAsString) + ->setParameter('{{ compared_value }}', $comparedValueString) + ->setParameter('{{ compared_value_type }}', $comparedValueType) + ->assertRaised(); } /** diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php index 864b58a35b7d..2ba823eebc98 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php @@ -13,8 +13,7 @@ use Symfony\Component\Validator\ConstraintValidatorInterface; use Symfony\Component\Validator\ConstraintViolation; -use Symfony\Component\Validator\Context\ExecutionContext; -use Symfony\Component\Validator\Context\ExecutionContextInterface; +use Symfony\Component\Validator\ExecutionContextInterface; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\PropertyMetadata; use Symfony\Component\Validator\Tests\Fixtures\StubGlobalExecutionContext; @@ -80,6 +79,19 @@ protected function createContext() ->getMock(); } + /** + * @param $message + * @param array $parameters + * @param string $propertyPath + * @param string $invalidValue + * @param null $plural + * @param null $code + * + * @return ConstraintViolation + * + * @deprecated To be removed in Symfony 3.0. Use + * {@link buildViolation()} instead. + */ protected function createViolation($message, array $parameters = array(), $propertyPath = 'property.path', $invalidValue = 'InvalidValue', $plural = null, $code = null) { return new ConstraintViolation( @@ -169,14 +181,34 @@ protected function assertNoViolation() $this->assertCount(0, $this->context->getViolations()); } + /** + * @param $message + * @param array $parameters + * @param string $propertyPath + * @param string $invalidValue + * @param null $plural + * @param null $code + * + * @deprecated To be removed in Symfony 3.0. Use + * {@link buildViolation()} instead. + */ protected function assertViolation($message, array $parameters = array(), $propertyPath = 'property.path', $invalidValue = 'InvalidValue', $plural = null, $code = null) { - $violations = $this->context->getViolations(); - - $this->assertCount(1, $violations); - $this->assertEquals($this->createViolation($message, $parameters, $propertyPath, $invalidValue, $plural, $code), $violations[0]); + $this->buildViolation($message) + ->setParameters($parameters) + ->atPath($propertyPath) + ->setInvalidValue($invalidValue) + ->setCode($code) + ->setPlural($plural) + ->assertRaised(); } + /** + * @param array $expected + * + * @deprecated To be removed in Symfony 3.0. Use + * {@link buildViolation()} instead. + */ protected function assertViolations(array $expected) { $violations = $this->context->getViolations(); @@ -190,5 +222,137 @@ protected function assertViolations(array $expected) } } + /** + * @param $message + * + * @return ConstraintViolationAssertion + */ + protected function buildViolation($message) + { + return new ConstraintViolationAssertion($this->context, $message); + } + abstract protected function createValidator(); } + +/** + * @internal + */ +class ConstraintViolationAssertion +{ + /** + * @var ExecutionContextInterface + */ + private $context; + + /** + * @var ConstraintViolationAssertion[] + */ + private $assertions; + + private $message; + private $parameters = array(); + private $invalidValue = 'InvalidValue'; + private $propertyPath = 'property.path'; + private $translationDomain; + private $plural; + private $code; + + public function __construct(ExecutionContextInterface $context, $message, array $assertions = array()) + { + $this->context = $context; + $this->message = $message; + $this->assertions = $assertions; + } + + public function atPath($path) + { + $this->propertyPath = $path; + + return $this; + } + + public function setParameter($key, $value) + { + $this->parameters[$key] = $value; + + return $this; + } + + public function setParameters(array $parameters) + { + $this->parameters = $parameters; + + return $this; + } + + public function setTranslationDomain($translationDomain) + { + $this->translationDomain = $translationDomain; + + return $this; + } + + public function setInvalidValue($invalidValue) + { + $this->invalidValue = $invalidValue; + + return $this; + } + + public function setPlural($number) + { + $this->plural = $number; + + return $this; + } + + public function setCode($code) + { + $this->code = $code; + + return $this; + } + + public function buildNextViolation($message) + { + $assertions = $this->assertions; + $assertions[] = $this; + + return new self($this->context, $message, $assertions); + } + + public function assertRaised() + { + $expected = array(); + foreach ($this->assertions as $assertion) { + $expected[] = $assertion->getViolation(); + } + $expected[] = $this->getViolation(); + + $violations = iterator_to_array($this->context->getViolations()); + + \PHPUnit_Framework_Assert::assertCount(count($expected), $violations); + + reset($violations); + + foreach ($expected as $violation) { + \PHPUnit_Framework_Assert::assertEquals($violation, current($violations)); + next($violations); + } + } + + private function getViolation() + { + return new ConstraintViolation( + null, + $this->message, + $this->parameters, + $this->context->getRoot(), + $this->propertyPath, + $this->invalidValue, + $this->plural, + $this->code + ); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php index c73a4a9cf6b3..ef10c16b4ed2 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php @@ -46,10 +46,9 @@ public function testInvalidValues($value, $valueAsString) $this->validator->validate($value, $constraint); - $this->assertViolation( - 'myMessage', - array('{{ value }}' => $valueAsString) - ); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', $valueAsString) + ->assertRaised(); } public function getInvalidValues() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php index 377999bc76b8..384efdd3ec1b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php @@ -64,9 +64,9 @@ public function testSingleMethod() $this->validator->validate($object, $constraint); - $this->assertViolation('My message', array( - '{{ value }}' => 'foobar', - )); + $this->buildViolation('My message') + ->setParameter('{{ value }}', 'foobar') + ->assertRaised(); } public function testSingleMethodExplicitName() @@ -76,9 +76,9 @@ public function testSingleMethodExplicitName() $this->validator->validate($object, $constraint); - $this->assertViolation('My message', array( - '{{ value }}' => 'foobar', - )); + $this->buildViolation('My message') + ->setParameter('{{ value }}', 'foobar') + ->assertRaised(); } public function testMultipleMethods() @@ -88,14 +88,11 @@ public function testMultipleMethods() $this->validator->validate($object, $constraint); - $this->assertViolations(array( - $this->createViolation('My message', array( - '{{ value }}' => 'foobar', - )), - $this->createViolation('Static message', array( - '{{ value }}' => 'baz', - )), - )); + $this->buildViolation('My message') + ->setParameter('{{ value }}', 'foobar') + ->buildNextViolation('Static message') + ->setParameter('{{ value }}', 'baz') + ->assertRaised(); } public function testMultipleMethodsExplicitName() @@ -107,14 +104,11 @@ public function testMultipleMethodsExplicitName() $this->validator->validate($object, $constraint); - $this->assertViolations(array( - $this->createViolation('My message', array( - '{{ value }}' => 'foobar', - )), - $this->createViolation('Static message', array( - '{{ value }}' => 'baz', - )), - )); + $this->buildViolation('My message') + ->setParameter('{{ value }}', 'foobar') + ->buildNextViolation('Static message') + ->setParameter('{{ value }}', 'baz') + ->assertRaised(); } public function testSingleStaticMethod() @@ -126,9 +120,9 @@ public function testSingleStaticMethod() $this->validator->validate($object, $constraint); - $this->assertViolation('Callback message', array( - '{{ value }}' => 'foobar', - )); + $this->buildViolation('Callback message') + ->setParameter('{{ value }}', 'foobar') + ->assertRaised(); } public function testSingleStaticMethodExplicitName() @@ -140,9 +134,9 @@ public function testSingleStaticMethodExplicitName() $this->validator->validate($object, $constraint); - $this->assertViolation('Callback message', array( - '{{ value }}' => 'foobar', - )); + $this->buildViolation('Callback message') + ->setParameter('{{ value }}', 'foobar') + ->assertRaised(); } /** diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php index 0b3b04e067cd..9a786cb6acaf 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php @@ -57,9 +57,9 @@ public function testInvalidNumbers($scheme, $number) $this->validator->validate($number, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => is_string($number) ? '"'.$number.'"' : $number, - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', is_string($number) ? '"'.$number.'"' : $number) + ->assertRaised(); } public function getValidNumbers() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php index 335f62021897..6ac78f2a5360 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php @@ -138,9 +138,9 @@ public function testInvalidChoice() $this->validator->validate('baz', $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"baz"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"baz"') + ->assertRaised(); } public function testInvalidChoiceMultiple() @@ -153,9 +153,9 @@ public function testInvalidChoiceMultiple() $this->validator->validate(array('foo', 'baz'), $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"baz"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"baz"') + ->assertRaised(); } public function testTooFewChoices() @@ -173,9 +173,11 @@ public function testTooFewChoices() $this->validator->validate($value, $constraint); - $this->assertViolation('myMessage', array( - '{{ limit }}' => 2, - ), 'property.path', $value, 2); + $this->buildViolation('myMessage') + ->setParameter('{{ limit }}', 2) + ->setInvalidValue($value) + ->setPlural(2) + ->assertRaised(); } public function testTooManyChoices() @@ -193,9 +195,11 @@ public function testTooManyChoices() $this->validator->validate($value, $constraint); - $this->assertViolation('myMessage', array( - '{{ limit }}' => 2, - ), 'property.path', $value, 2); + $this->buildViolation('myMessage') + ->setParameter('{{ limit }}', 2) + ->setInvalidValue($value) + ->setPlural(2) + ->assertRaised(); } public function testNonStrict() @@ -233,9 +237,9 @@ public function testStrictDisallowsDifferentType() $this->validator->validate('2', $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"2"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"2"') + ->assertRaised(); } public function testNonStrictWithMultipleChoices() @@ -262,8 +266,8 @@ public function testStrictWithMultipleChoices() $this->validator->validate(array(2, '3'), $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"3"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"3"') + ->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php index a620ee576ca9..2fabf754c6c6 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php @@ -136,9 +136,11 @@ public function testExtraFieldsDisallowed() 'extraFieldsMessage' => 'myMessage', ))); - $this->assertViolation('myMessage', array( - '{{ field }}' => '"baz"', - ), 'property.path[baz]', 6); + $this->buildViolation('myMessage') + ->setParameter('{{ field }}', '"baz"') + ->atPath('property.path[baz]') + ->setInvalidValue(6) + ->assertRaised(); } // bug fix @@ -195,9 +197,11 @@ public function testMissingFieldsDisallowed() 'missingFieldsMessage' => 'myMessage', ))); - $this->assertViolation('myMessage', array( - '{{ field }}' => '"foo"', - ), 'property.path[foo]', null); + $this->buildViolation('myMessage') + ->setParameter('{{ field }}', '"foo"') + ->atPath('property.path[foo]') + ->setInvalidValue(null) + ->assertRaised(); } public function testMissingFieldsAllowed() @@ -305,9 +309,11 @@ public function testRequiredFieldNotPresent() 'missingFieldsMessage' => 'myMessage', ))); - $this->assertViolation('myMessage', array( - '{{ field }}' => '"foo"', - ), 'property.path[foo]', null); + $this->buildViolation('myMessage') + ->setParameter('{{ field }}', '"foo"') + ->atPath('property.path[foo]') + ->setInvalidValue(null) + ->assertRaised(); } public function testRequiredFieldSingleConstraint() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php index 1b8bb09232f2..f69995e79017 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php @@ -121,10 +121,12 @@ public function testInvalidValuesMax($value) $this->validator->validate($value, $constraint); - $this->assertViolation('myMessage', array( - '{{ count }}' => count($value), - '{{ limit }}' => 4, - ), 'property.path', $value, 4); + $this->buildViolation('myMessage') + ->setParameter('{{ count }}', count($value)) + ->setParameter('{{ limit }}', 4) + ->setInvalidValue($value) + ->setPlural(4) + ->assertRaised(); } /** @@ -139,10 +141,12 @@ public function testInvalidValuesMin($value) $this->validator->validate($value, $constraint); - $this->assertViolation('myMessage', array( - '{{ count }}' => count($value), - '{{ limit }}' => 4, - ), 'property.path', $value, 4); + $this->buildViolation('myMessage') + ->setParameter('{{ count }}', count($value)) + ->setParameter('{{ limit }}', 4) + ->setInvalidValue($value) + ->setPlural(4) + ->assertRaised(); } /** @@ -158,10 +162,12 @@ public function testInvalidValuesExact($value) $this->validator->validate($value, $constraint); - $this->assertViolation('myMessage', array( - '{{ count }}' => count($value), - '{{ limit }}' => 4, - ), 'property.path', $value, 4); + $this->buildViolation('myMessage') + ->setParameter('{{ count }}', count($value)) + ->setParameter('{{ limit }}', 4) + ->setInvalidValue($value) + ->setPlural(4) + ->assertRaised(); } public function testDefaultOption() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php index a8090aee2009..2a435a287a21 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php @@ -81,9 +81,9 @@ public function testInvalidCountries($country) $this->validator->validate($country, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$country.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$country.'"') + ->assertRaised(); } public function getInvalidCountries() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php index c9238c2711bc..9d26a6f5d105 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php @@ -95,9 +95,9 @@ public function testInvalidCurrencies($currency) $this->validator->validate($currency, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$currency.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$currency.'"') + ->assertRaised(); } public function getInvalidCurrencies() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php index 76961236d3bb..19f089efb3b2 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php @@ -80,9 +80,9 @@ public function testInvalidDateTimes($dateTime) $this->validator->validate($dateTime, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$dateTime.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$dateTime.'"') + ->assertRaised(); } public function getInvalidDateTimes() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php index 2adcd46a4360..e2e044541d36 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php @@ -80,9 +80,9 @@ public function testInvalidDates($date) $this->validator->validate($date, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$date.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$date.'"') + ->assertRaised(); } public function getInvalidDates() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php index 18e23b8b4d1b..e291124f298d 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php @@ -73,9 +73,9 @@ public function testInvalidEmails($email) $this->validator->validate($email, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$email.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$email.'"') + ->assertRaised(); } public function getInvalidEmails() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FalseValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FalseValidatorTest.php index 7de6b9c5ae4b..e74cf4acb810 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FalseValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FalseValidatorTest.php @@ -43,8 +43,8 @@ public function testTrueIsInvalid() $this->validator->validate(true, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => 'true', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', 'true') + ->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php index f1f8db692a60..25def64c19c9 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php @@ -28,8 +28,8 @@ public function testFileNotFound() $this->validator->validate('foobar', $constraint); - $this->assertViolation('myMessage', array( - '{{ file }}' => '"foobar"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ file }}', '"foobar"') + ->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php index c93a514304f1..19bbe3c47968 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php @@ -162,12 +162,12 @@ public function testMaxSizeExceeded($bytesWritten, $limit, $sizeAsString, $limit $this->validator->validate($this->getFile($this->path), $constraint); - $this->assertViolation('myMessage', array( - '{{ limit }}' => $limitAsString, - '{{ size }}' => $sizeAsString, - '{{ suffix }}' => $suffix, - '{{ file }}' => '"'.$this->path.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ limit }}', $limitAsString) + ->setParameter('{{ size }}', $sizeAsString) + ->setParameter('{{ suffix }}', $suffix) + ->setParameter('{{ file }}', '"'.$this->path.'"') + ->assertRaised(); } public function provideMaxSizeNotExceededTests() @@ -231,18 +231,15 @@ public function testValidMimeType() $file = $this ->getMockBuilder('Symfony\Component\HttpFoundation\File\File') ->setConstructorArgs(array(__DIR__.'/Fixtures/foo')) - ->getMock() - ; + ->getMock(); $file ->expects($this->once()) ->method('getPathname') - ->will($this->returnValue($this->path)) - ; + ->will($this->returnValue($this->path)); $file ->expects($this->once()) ->method('getMimeType') - ->will($this->returnValue('image/jpg')) - ; + ->will($this->returnValue('image/jpg')); $constraint = new File(array( 'mimeTypes' => array('image/png', 'image/jpg'), @@ -258,18 +255,15 @@ public function testValidWildcardMimeType() $file = $this ->getMockBuilder('Symfony\Component\HttpFoundation\File\File') ->setConstructorArgs(array(__DIR__.'/Fixtures/foo')) - ->getMock() - ; + ->getMock(); $file ->expects($this->once()) ->method('getPathname') - ->will($this->returnValue($this->path)) - ; + ->will($this->returnValue($this->path)); $file ->expects($this->once()) ->method('getMimeType') - ->will($this->returnValue('image/jpg')) - ; + ->will($this->returnValue('image/jpg')); $constraint = new File(array( 'mimeTypes' => array('image/*'), @@ -285,18 +279,15 @@ public function testInvalidMimeType() $file = $this ->getMockBuilder('Symfony\Component\HttpFoundation\File\File') ->setConstructorArgs(array(__DIR__.'/Fixtures/foo')) - ->getMock() - ; + ->getMock(); $file ->expects($this->once()) ->method('getPathname') - ->will($this->returnValue($this->path)) - ; + ->will($this->returnValue($this->path)); $file ->expects($this->once()) ->method('getMimeType') - ->will($this->returnValue('application/pdf')) - ; + ->will($this->returnValue('application/pdf')); $constraint = new File(array( 'mimeTypes' => array('image/png', 'image/jpg'), @@ -305,11 +296,11 @@ public function testInvalidMimeType() $this->validator->validate($file, $constraint); - $this->assertViolation('myMessage', array( - '{{ type }}' => '"application/pdf"', - '{{ types }}' => '"image/png", "image/jpg"', - '{{ file }}' => '"'.$this->path.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ type }}', '"application/pdf"') + ->setParameter('{{ types }}', '"image/png", "image/jpg"') + ->setParameter('{{ file }}', '"'.$this->path.'"') + ->assertRaised(); } public function testInvalidWildcardMimeType() @@ -317,18 +308,15 @@ public function testInvalidWildcardMimeType() $file = $this ->getMockBuilder('Symfony\Component\HttpFoundation\File\File') ->setConstructorArgs(array(__DIR__.'/Fixtures/foo')) - ->getMock() - ; + ->getMock(); $file ->expects($this->once()) ->method('getPathname') - ->will($this->returnValue($this->path)) - ; + ->will($this->returnValue($this->path)); $file ->expects($this->once()) ->method('getMimeType') - ->will($this->returnValue('application/pdf')) - ; + ->will($this->returnValue('application/pdf')); $constraint = new File(array( 'mimeTypes' => array('image/*', 'image/jpg'), @@ -337,11 +325,11 @@ public function testInvalidWildcardMimeType() $this->validator->validate($file, $constraint); - $this->assertViolation('myMessage', array( - '{{ type }}' => '"application/pdf"', - '{{ types }}' => '"image/*", "image/jpg"', - '{{ file }}' => '"'.$this->path.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ type }}', '"application/pdf"') + ->setParameter('{{ types }}', '"image/*", "image/jpg"') + ->setParameter('{{ file }}', '"'.$this->path.'"') + ->assertRaised(); } /** @@ -358,7 +346,9 @@ public function testUploadedFileError($error, $message, array $params = array(), $this->validator->validate($file, $constraint); - $this->assertViolation('myMessage', $params); + $this->buildViolation('myMessage') + ->setParameters($params) + ->assertRaised(); } public function uploadedFileErrorProvider() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php index 6a84a66324f6..13af71642924 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php @@ -158,9 +158,9 @@ public function testInvalidIbans($iban) $this->validator->validate($iban, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$iban.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$iban.'"') + ->assertRaised(); } public function getInvalidIbans() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php index 35a934ee27cb..bb7954ed72ac 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php @@ -81,10 +81,10 @@ public function testWidthTooSmall() $this->validator->validate($this->image, $constraint); - $this->assertViolation('myMessage', array( - '{{ width }}' => '2', - '{{ min_width }}' => '3', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ width }}', '2') + ->setParameter('{{ min_width }}', '3') + ->assertRaised(); } public function testWidthTooBig() @@ -96,10 +96,10 @@ public function testWidthTooBig() $this->validator->validate($this->image, $constraint); - $this->assertViolation('myMessage', array( - '{{ width }}' => '2', - '{{ max_width }}' => '1', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ width }}', '2') + ->setParameter('{{ max_width }}', '1') + ->assertRaised(); } public function testHeightTooSmall() @@ -111,10 +111,10 @@ public function testHeightTooSmall() $this->validator->validate($this->image, $constraint); - $this->assertViolation('myMessage', array( - '{{ height }}' => '2', - '{{ min_height }}' => '3', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ height }}', '2') + ->setParameter('{{ min_height }}', '3') + ->assertRaised(); } public function testHeightTooBig() @@ -126,10 +126,10 @@ public function testHeightTooBig() $this->validator->validate($this->image, $constraint); - $this->assertViolation('myMessage', array( - '{{ height }}' => '2', - '{{ max_height }}' => '1', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ height }}', '2') + ->setParameter('{{ max_height }}', '1') + ->assertRaised(); } /** diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php index 5316330623a0..5cc733020d5c 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php @@ -145,9 +145,9 @@ public function testInvalidIpsV4($ip) $this->validator->validate($ip, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$ip.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$ip.'"') + ->assertRaised(); } public function getInvalidIpsV4() @@ -177,9 +177,9 @@ public function testInvalidPrivateIpsV4($ip) $this->validator->validate($ip, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$ip.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$ip.'"') + ->assertRaised(); } public function getInvalidPrivateIpsV4() @@ -203,9 +203,9 @@ public function testInvalidReservedIpsV4($ip) $this->validator->validate($ip, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$ip.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$ip.'"') + ->assertRaised(); } public function getInvalidReservedIpsV4() @@ -229,9 +229,9 @@ public function testInvalidPublicIpsV4($ip) $this->validator->validate($ip, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$ip.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$ip.'"') + ->assertRaised(); } public function getInvalidPublicIpsV4() @@ -251,9 +251,9 @@ public function testInvalidIpsV6($ip) $this->validator->validate($ip, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$ip.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$ip.'"') + ->assertRaised(); } public function getInvalidIpsV6() @@ -287,9 +287,9 @@ public function testInvalidPrivateIpsV6($ip) $this->validator->validate($ip, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$ip.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$ip.'"') + ->assertRaised(); } public function getInvalidPrivateIpsV6() @@ -313,9 +313,9 @@ public function testInvalidReservedIpsV6($ip) $this->validator->validate($ip, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$ip.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$ip.'"') + ->assertRaised(); } public function getInvalidReservedIpsV6() @@ -338,9 +338,9 @@ public function testInvalidPublicIpsV6($ip) $this->validator->validate($ip, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$ip.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$ip.'"') + ->assertRaised(); } public function getInvalidPublicIpsV6() @@ -360,9 +360,9 @@ public function testInvalidIpsAll($ip) $this->validator->validate($ip, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$ip.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$ip.'"') + ->assertRaised(); } public function getInvalidIpsAll() @@ -382,9 +382,9 @@ public function testInvalidPrivateIpsAll($ip) $this->validator->validate($ip, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$ip.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$ip.'"') + ->assertRaised(); } public function getInvalidPrivateIpsAll() @@ -404,9 +404,9 @@ public function testInvalidReservedIpsAll($ip) $this->validator->validate($ip, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$ip.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$ip.'"') + ->assertRaised(); } public function getInvalidReservedIpsAll() @@ -426,9 +426,9 @@ public function testInvalidPublicIpsAll($ip) $this->validator->validate($ip, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$ip.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$ip.'"') + ->assertRaised(); } public function getInvalidPublicIpsAll() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IsbnValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IsbnValidatorTest.php index 8de704edee31..b5c4c8b1f7ab 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IsbnValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IsbnValidatorTest.php @@ -170,9 +170,9 @@ public function testInvalidIsbn10($isbn) $this->validator->validate($isbn, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$isbn.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$isbn.'"') + ->assertRaised(); } /** @@ -199,9 +199,9 @@ public function testInvalidIsbn13($isbn) $this->validator->validate($isbn, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$isbn.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$isbn.'"') + ->assertRaised(); } /** @@ -232,8 +232,8 @@ public function testInvalidIsbn($isbn) $this->validator->validate($isbn, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$isbn.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$isbn.'"') + ->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IssnValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IssnValidatorTest.php index 992536ebf29b..98b6e1fc3627 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IssnValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IssnValidatorTest.php @@ -140,9 +140,9 @@ public function testCaseSensitiveIssns($issn) $this->validator->validate($issn, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$issn.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$issn.'"') + ->assertRaised(); } /** @@ -157,9 +157,9 @@ public function testRequireHyphenIssns($issn) $this->validator->validate($issn, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$issn.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$issn.'"') + ->assertRaised(); } /** @@ -185,9 +185,9 @@ public function testInvalidFormatIssn($issn) $this->validator->validate($issn, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$issn.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$issn.'"') + ->assertRaised(); } /** @@ -201,9 +201,9 @@ public function testInvalidValueIssn($issn) $this->validator->validate($issn, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$issn.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$issn.'"') + ->assertRaised(); } /** @@ -217,8 +217,8 @@ public function testInvalidIssn($issn) $this->validator->validate($issn, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$issn.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$issn.'"') + ->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php index 5ef9d3a6efbd..a9197970be07 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php @@ -81,9 +81,9 @@ public function testInvalidLanguages($language) $this->validator->validate($language, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$language.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$language.'"') + ->assertRaised(); } public function getInvalidLanguages() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php index 4457d264dd00..1d492a53e147 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php @@ -150,10 +150,12 @@ public function testInvalidValuesMin($value, $mbOnly = false) $this->validator->validate($value, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$value.'"', - '{{ limit }}' => 4, - ), 'property.path', $value, 4); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$value.'"') + ->setParameter('{{ limit }}', 4) + ->setInvalidValue($value) + ->setPlural(4) + ->assertRaised(); } /** @@ -172,10 +174,12 @@ public function testInvalidValuesMax($value, $mbOnly = false) $this->validator->validate($value, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$value.'"', - '{{ limit }}' => 4, - ), 'property.path', $value, 4); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$value.'"') + ->setParameter('{{ limit }}', 4) + ->setInvalidValue($value) + ->setPlural(4) + ->assertRaised(); } /** @@ -195,10 +199,12 @@ public function testInvalidValuesExact($value, $mbOnly = false) $this->validator->validate($value, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$value.'"', - '{{ limit }}' => 4, - ), 'property.path', $value, 4); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$value.'"') + ->setParameter('{{ limit }}', 4) + ->setInvalidValue($value) + ->setPlural(4) + ->assertRaised(); } public function testConstraintGetDefaultOption() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php index 31d988df5953..f9bfcab95128 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php @@ -83,9 +83,9 @@ public function testInvalidLocales($locale) $this->validator->validate($locale, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$locale.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$locale.'"') + ->assertRaised(); } public function getInvalidLocales() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php index 830c0436ead9..974523d202fc 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php @@ -80,9 +80,9 @@ public function testInvalidNumbers($number) $this->validator->validate($number, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$number.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$number.'"') + ->assertRaised(); } public function getInvalidNumbers() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php index 0f9337b8b77d..abbe8c2a28c5 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php @@ -50,9 +50,9 @@ public function testNullIsInvalid() $this->validator->validate(null, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => 'null', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', 'null') + ->assertRaised(); } public function testBlankIsInvalid() @@ -63,9 +63,9 @@ public function testBlankIsInvalid() $this->validator->validate('', $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '""', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '""') + ->assertRaised(); } public function testFalseIsInvalid() @@ -76,9 +76,9 @@ public function testFalseIsInvalid() $this->validator->validate(false, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => 'false', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', 'false') + ->assertRaised(); } public function testEmptyArrayIsInvalid() @@ -89,8 +89,8 @@ public function testEmptyArrayIsInvalid() $this->validator->validate(array(), $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => 'array', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', 'array') + ->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php index f9de951b61fd..bd87878314ab 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php @@ -49,6 +49,6 @@ public function testNullIsInvalid() $this->validator->validate(null, $constraint); - $this->assertViolation('myMessage'); + $this->buildViolation('myMessage')->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NullValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NullValidatorTest.php index a66bf8341479..713eabf026ab 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NullValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NullValidatorTest.php @@ -39,9 +39,9 @@ public function testInvalidValues($value, $valueAsString) $this->validator->validate($value, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => $valueAsString, - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', $valueAsString) + ->assertRaised(); } public function getInvalidValues() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php index 3af24e896c76..fd46c634a1fd 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php @@ -107,10 +107,10 @@ public function testInvalidValuesMin($value) $this->validator->validate($value, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => $value, - '{{ limit }}' => 10, - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', $value) + ->setParameter('{{ limit }}', 10) + ->assertRaised(); } /** @@ -125,10 +125,10 @@ public function testInvalidValuesMax($value) $this->validator->validate($value, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => $value, - '{{ limit }}' => 20, - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', $value) + ->setParameter('{{ limit }}', 20) + ->assertRaised(); } /** @@ -145,10 +145,10 @@ public function testInvalidValuesCombinedMax($value) $this->validator->validate($value, $constraint); - $this->assertViolation('myMaxMessage', array( - '{{ value }}' => $value, - '{{ limit }}' => 20, - )); + $this->buildViolation('myMaxMessage') + ->setParameter('{{ value }}', $value) + ->setParameter('{{ limit }}', 20) + ->assertRaised(); } /** @@ -165,10 +165,10 @@ public function testInvalidValuesCombinedMin($value) $this->validator->validate($value, $constraint); - $this->assertViolation('myMinMessage', array( - '{{ value }}' => $value, - '{{ limit }}' => 10, - )); + $this->buildViolation('myMinMessage') + ->setParameter('{{ value }}', $value) + ->setParameter('{{ limit }}', 10) + ->assertRaised(); } public function getInvalidValues() @@ -192,10 +192,10 @@ public function testMinMessageIsSet() $this->validator->validate(9, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => 9, - '{{ limit }}' => 10, - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', 9) + ->setParameter('{{ limit }}', 10) + ->assertRaised(); } public function testMaxMessageIsSet() @@ -208,10 +208,10 @@ public function testMaxMessageIsSet() $this->validator->validate(21, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => 21, - '{{ limit }}' => 20, - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', 21) + ->setParameter('{{ limit }}', 20) + ->assertRaised(); } public function testNonNumeric() @@ -222,8 +222,8 @@ public function testNonNumeric() 'invalidMessage' => 'myMessage', ))); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"abcd"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"abcd"') + ->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php index e28a8e03ccea..8afb037752e1 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php @@ -76,9 +76,9 @@ public function testInvalidValues($value) $this->validator->validate($value, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$value.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$value.'"') + ->assertRaised(); } public function getInvalidValues() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php index 3536a72a25cc..4eb947899acc 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php @@ -80,9 +80,9 @@ public function testInvalidTimes($time) $this->validator->validate($time, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$time.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$time.'"') + ->assertRaised(); } public function getInvalidTimes() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TrueValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TrueValidatorTest.php index 68f207eba2e0..e0c3ce7875da 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TrueValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TrueValidatorTest.php @@ -43,8 +43,8 @@ public function testFalseIsInvalid() $this->validator->validate(false, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => 'false', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', 'false') + ->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php index 7a7fcea74eb9..2b735cbab2f3 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php @@ -50,10 +50,10 @@ public function testEmptyIsInvalidIfNoString() $this->validator->validate('', $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '""', - '{{ type }}' => 'integer', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '""') + ->setParameter('{{ type }}', 'integer') + ->assertRaised(); } /** @@ -117,10 +117,10 @@ public function testInvalidValues($value, $type, $valueAsString) $this->validator->validate($value, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => $valueAsString, - '{{ type }}' => $type, - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', $valueAsString) + ->setParameter('{{ type }}', $type) + ->assertRaised(); } public function getInvalidValues() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php index 353c9acc67f7..5406b354ce06 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php @@ -13,7 +13,6 @@ use Symfony\Component\Validator\Constraints\Url; use Symfony\Component\Validator\Constraints\UrlValidator; -use Symfony\Component\Validator\Validation; class UrlValidatorTest extends AbstractConstraintValidatorTest { @@ -119,9 +118,9 @@ public function testInvalidUrls($url) $this->validator->validate($url, $constraint); - $this->assertViolation('myMessage', array( - '{{ value }}' => '"'.$url.'"', - )); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"'.$url.'"') + ->assertRaised(); } public function getInvalidUrls()