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
{
return (string) $this->value;
}
+
+ public function getValue()
+ {
+ return $this->value;
+ }
}
/**
/**
* @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
*
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
*