Skip to content

Commit

Permalink
[Validator] Fix a bug in the ExecutionContext
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed May 7, 2012
1 parent f273edc commit 23e15bb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Symfony/Component/Validator/ExecutionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function addViolation($message, array $params = array(), $invalidValue =
$this->globalContext->getRoot(),
$this->propertyPath,
// check using func_num_args() to allow passing null values
func_num_args() === 3 ? $invalidValue : $this->value,
func_num_args() >= 3 ? $invalidValue : $this->value,
$pluralization
));
}
Expand All @@ -91,7 +91,7 @@ public function addViolationAtPath($propertyPath, $message, array $params = arra
$this->globalContext->getRoot(),
$propertyPath,
// check using func_num_args() to allow passing null values
func_num_args() === 4 ? $invalidValue : $this->value,
func_num_args() >= 4 ? $invalidValue : $this->value,
$pluralization
));
}
Expand All @@ -114,7 +114,7 @@ public function addViolationAtSubPath($subPath, $message, array $params = array(
$this->globalContext->getRoot(),
$this->getPropertyPath($subPath),
// check using func_num_args() to allow passing null values
func_num_args() === 4 ? $invalidValue : $this->value,
func_num_args() >= 4 ? $invalidValue : $this->value,
$pluralization
));
}
Expand Down
27 changes: 27 additions & 0 deletions src/Symfony/Component/Validator/Tests/ExecutionContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function testAddViolationUsesPassedNullValue()
{
// passed null value should override preconfigured value "invalid"
$this->context->addViolation('Error', array('foo' => 'bar'), null);
$this->context->addViolation('Error', array('foo' => 'bar'), null, 1);

$this->assertEquals(new ConstraintViolationList(array(
new ConstraintViolation(
Expand All @@ -102,6 +103,14 @@ public function testAddViolationUsesPassedNullValue()
'foo.bar',
null
),
new ConstraintViolation(
'Error',
array('foo' => 'bar'),
'Root',
'foo.bar',
null,
1
),
)), $this->context->getViolations());
}

Expand Down Expand Up @@ -140,6 +149,7 @@ public function testAddViolationAtPathUsesPassedNullValue()
{
// passed null value should override preconfigured value "invalid"
$this->context->addViolationAtPath('bar.baz', 'Error', array('foo' => 'bar'), null);
$this->context->addViolationAtPath('bar.baz', 'Error', array('foo' => 'bar'), null, 1);

$this->assertEquals(new ConstraintViolationList(array(
new ConstraintViolation(
Expand All @@ -149,6 +159,14 @@ public function testAddViolationAtPathUsesPassedNullValue()
'bar.baz',
null
),
new ConstraintViolation(
'Error',
array('foo' => 'bar'),
'Root',
'bar.baz',
null,
1
),
)), $this->context->getViolations());
}

Expand Down Expand Up @@ -187,6 +205,7 @@ public function testAddViolationAtSubPathUsesPassedNullValue()
{
// passed null value should override preconfigured value "invalid"
$this->context->addViolationAtSubPath('bam.baz', 'Error', array('foo' => 'bar'), null);
$this->context->addViolationAtSubPath('bam.baz', 'Error', array('foo' => 'bar'), null, 1);

$this->assertEquals(new ConstraintViolationList(array(
new ConstraintViolation(
Expand All @@ -196,6 +215,14 @@ public function testAddViolationAtSubPathUsesPassedNullValue()
'foo.bar.bam.baz',
null
),
new ConstraintViolation(
'Error',
array('foo' => 'bar'),
'Root',
'foo.bar.bam.baz',
null,
1
),
)), $this->context->getViolations());
}

Expand Down

0 comments on commit 23e15bb

Please sign in to comment.