[Validator] Fix a bug in the ExecutionContext

This commit is contained in:
Victor Berchet 2012-05-03 20:43:38 +02:00
parent f273edc176
commit 23e15bb878
2 changed files with 30 additions and 3 deletions

View File

@ -68,7 +68,7 @@ class ExecutionContext
$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
));
}
@ -91,7 +91,7 @@ class ExecutionContext
$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
));
}
@ -114,7 +114,7 @@ class ExecutionContext
$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
));
}

View File

@ -93,6 +93,7 @@ class ExecutionContextTest extends \PHPUnit_Framework_TestCase
{
// 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(
@ -102,6 +103,14 @@ class ExecutionContextTest extends \PHPUnit_Framework_TestCase
'foo.bar',
null
),
new ConstraintViolation(
'Error',
array('foo' => 'bar'),
'Root',
'foo.bar',
null,
1
),
)), $this->context->getViolations());
}
@ -140,6 +149,7 @@ class ExecutionContextTest extends \PHPUnit_Framework_TestCase
{
// 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(
@ -149,6 +159,14 @@ class ExecutionContextTest extends \PHPUnit_Framework_TestCase
'bar.baz',
null
),
new ConstraintViolation(
'Error',
array('foo' => 'bar'),
'Root',
'bar.baz',
null,
1
),
)), $this->context->getViolations());
}
@ -187,6 +205,7 @@ class ExecutionContextTest extends \PHPUnit_Framework_TestCase
{
// 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(
@ -196,6 +215,14 @@ class ExecutionContextTest extends \PHPUnit_Framework_TestCase
'foo.bar.bam.baz',
null
),
new ConstraintViolation(
'Error',
array('foo' => 'bar'),
'Root',
'foo.bar.bam.baz',
null,
1
),
)), $this->context->getViolations());
}