Skip to content

Commit b9d2503

Browse files
committed
[Validator] Throw exception on Comparison constraints null options
1 parent bd99764 commit b9d2503

10 files changed

+25
-14
lines changed

Constraints/AbstractComparison.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ abstract class AbstractComparison extends Constraint
2929
*/
3030
public function __construct($options = null)
3131
{
32+
if (null === $options) {
33+
$options = array();
34+
}
35+
3236
if (is_array($options) && !isset($options['value'])) {
3337
throw new ConstraintDefinitionException(sprintf(
3438
'The %s constraint requires the "value" option to be set.',

Tests/Constraints/AbstractComparisonValidatorTestCase.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,21 @@ protected static function addPhp5Dot5Comparisons(array $comparisons)
6868
return $result;
6969
}
7070

71+
public function provideInvalidConstraintOptions()
72+
{
73+
return array(
74+
array(null),
75+
array(array()),
76+
);
77+
}
78+
7179
/**
80+
* @dataProvider provideInvalidConstraintOptions
7281
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
7382
*/
74-
public function testThrowsConstraintExceptionIfNoValueOrProperty()
83+
public function testThrowsConstraintExceptionIfNoValueOrProperty($options)
7584
{
76-
$comparison = $this->createConstraint(array());
77-
78-
$this->validator->validate('some value', $comparison);
85+
$this->createConstraint($options);
7986
}
8087

8188
/**
@@ -169,9 +176,9 @@ public function provideAllInvalidComparisons()
169176
abstract public function provideInvalidComparisons();
170177

171178
/**
172-
* @param array $options Options for the constraint
179+
* @param array|null $options Options for the constraint
173180
*
174181
* @return Constraint
175182
*/
176-
abstract protected function createConstraint(array $options);
183+
abstract protected function createConstraint(array $options = null);
177184
}

Tests/Constraints/EqualToValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function createValidator()
3030
return new EqualToValidator();
3131
}
3232

33-
protected function createConstraint(array $options)
33+
protected function createConstraint(array $options = null)
3434
{
3535
return new EqualTo($options);
3636
}

Tests/Constraints/GreaterThanOrEqualValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function createValidator()
3030
return new GreaterThanOrEqualValidator();
3131
}
3232

33-
protected function createConstraint(array $options)
33+
protected function createConstraint(array $options = null)
3434
{
3535
return new GreaterThanOrEqual($options);
3636
}

Tests/Constraints/GreaterThanValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function createValidator()
3030
return new GreaterThanValidator();
3131
}
3232

33-
protected function createConstraint(array $options)
33+
protected function createConstraint(array $options = null)
3434
{
3535
return new GreaterThan($options);
3636
}

Tests/Constraints/IdenticalToValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function createValidator()
3030
return new IdenticalToValidator();
3131
}
3232

33-
protected function createConstraint(array $options)
33+
protected function createConstraint(array $options = null)
3434
{
3535
return new IdenticalTo($options);
3636
}

Tests/Constraints/LessThanOrEqualValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function createValidator()
3030
return new LessThanOrEqualValidator();
3131
}
3232

33-
protected function createConstraint(array $options)
33+
protected function createConstraint(array $options = null)
3434
{
3535
return new LessThanOrEqual($options);
3636
}

Tests/Constraints/LessThanValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function createValidator()
3030
return new LessThanValidator();
3131
}
3232

33-
protected function createConstraint(array $options)
33+
protected function createConstraint(array $options = null)
3434
{
3535
return new LessThan($options);
3636
}

Tests/Constraints/NotEqualToValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function createValidator()
3030
return new NotEqualToValidator();
3131
}
3232

33-
protected function createConstraint(array $options)
33+
protected function createConstraint(array $options = null)
3434
{
3535
return new NotEqualTo($options);
3636
}

Tests/Constraints/NotIdenticalToValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function createValidator()
3030
return new NotIdenticalToValidator();
3131
}
3232

33-
protected function createConstraint(array $options)
33+
protected function createConstraint(array $options = null)
3434
{
3535
return new NotIdenticalTo($options);
3636
}

0 commit comments

Comments
 (0)