X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fsymfony%2Fvalidator%2FTests%2FConstraints%2FAbstractComparisonValidatorTestCase.php;fp=vendor%2Fsymfony%2Fvalidator%2FTests%2FConstraints%2FAbstractComparisonValidatorTestCase.php;h=93898bc6ec89f7c258b75b88f1ee2274f3888aa1;hp=a613d18ead3fb38394ddf551a922d62d24ed1820;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/symfony/validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php b/vendor/symfony/validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php index a613d18ea..93898bc6e 100644 --- a/vendor/symfony/validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php +++ b/vendor/symfony/validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Intl\Util\IntlTestHelper; use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\Exception\ConstraintDefinitionException; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; class ComparisonTest_Class @@ -28,6 +29,11 @@ class ComparisonTest_Class { return (string) $this->value; } + + public function getValue() + { + return $this->value; + } } /** @@ -76,12 +82,25 @@ abstract class AbstractComparisonValidatorTestCase extends ConstraintValidatorTe /** * @dataProvider provideInvalidConstraintOptions * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException + * @expectedExceptionMessage requires either the "value" or "propertyPath" option to be set. */ - public function testThrowsConstraintExceptionIfNoValueOrProperty($options) + public function testThrowsConstraintExceptionIfNoValueOrPropertyPath($options) { $this->createConstraint($options); } + /** + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException + * @expectedExceptionMessage requires only one of the "value" or "propertyPath" options to be set, not both. + */ + public function testThrowsConstraintExceptionIfBothValueAndPropertyPath() + { + $this->createConstraint((array( + 'value' => 'value', + 'propertyPath' => 'propertyPath', + ))); + } + /** * @dataProvider provideAllValidComparisons * @@ -113,11 +132,75 @@ abstract class AbstractComparisonValidatorTestCase extends ConstraintValidatorTe return $comparisons; } + /** + * @dataProvider provideValidComparisonsToPropertyPath + */ + public function testValidComparisonToPropertyPath($comparedValue) + { + $constraint = $this->createConstraint(array('propertyPath' => 'value')); + + $object = new ComparisonTest_Class(5); + + $this->setObject($object); + + $this->validator->validate($comparedValue, $constraint); + + $this->assertNoViolation(); + } + + /** + * @dataProvider provideValidComparisonsToPropertyPath + */ + public function testValidComparisonToPropertyPathOnArray($comparedValue) + { + $constraint = $this->createConstraint(array('propertyPath' => '[root][value]')); + + $this->setObject(array('root' => array('value' => 5))); + + $this->validator->validate($comparedValue, $constraint); + + $this->assertNoViolation(); + } + + public function testNoViolationOnNullObjectWithPropertyPath() + { + $constraint = $this->createConstraint(array('propertyPath' => 'propertyPath')); + + $this->setObject(null); + + $this->validator->validate('some data', $constraint); + + $this->assertNoViolation(); + } + + public function testInvalidValuePath() + { + $constraint = $this->createConstraint(array('propertyPath' => 'foo')); + + if (method_exists($this, 'expectException')) { + $this->expectException(ConstraintDefinitionException::class); + $this->expectExceptionMessage(sprintf('Invalid property path "foo" provided to "%s" constraint', get_class($constraint))); + } else { + $this->setExpectedException(ConstraintDefinitionException::class, sprintf('Invalid property path "foo" provided to "%s" constraint', get_class($constraint))); + } + + $object = new ComparisonTest_Class(5); + + $this->setObject($object); + + $this->validator->validate(5, $constraint); + } + /** * @return array */ abstract public function provideValidComparisons(); + /** + * @return array + */ + abstract public function provideValidComparisonsToPropertyPath(); + /** * @dataProvider provideAllInvalidComparisons *