bug #10123 handle array root element (greg0ire)
This PR was submitted for the 2.4 branch but it was merged into the 2.3 branch instead (closes #10123).
Discussion
----------
handle array root element
An array to string conversion notice was thrown when the root element of the thing being validated is an array.
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
Commits
-------
17ed8bf
handle array root element
This commit is contained in:
commit
22caebcd8e
@ -95,7 +95,14 @@ class ConstraintViolation implements ConstraintViolationInterface
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$class = (string) (is_object($this->root) ? get_class($this->root) : $this->root);
|
||||
if (is_object($this->root)) {
|
||||
$class = get_class($this->root);
|
||||
} elseif (is_array($this->root)) {
|
||||
$class = "Array";
|
||||
} else {
|
||||
$class = (string) $this->root;
|
||||
}
|
||||
|
||||
$propertyPath = (string) $this->propertyPath;
|
||||
$code = $this->code;
|
||||
|
||||
|
@ -33,4 +33,23 @@ EOF;
|
||||
|
||||
$this->assertSame($expected, (string) $violation);
|
||||
}
|
||||
|
||||
public function testToStringHandlesArrayRoots()
|
||||
{
|
||||
$violation = new ConstraintViolation(
|
||||
'42 cannot be used here',
|
||||
'this is the message template',
|
||||
array(),
|
||||
array('some_value' => 42),
|
||||
'some_value',
|
||||
null
|
||||
);
|
||||
|
||||
$expected = <<<EOF
|
||||
Array.some_value:
|
||||
42 cannot be used here
|
||||
EOF;
|
||||
|
||||
$this->assertSame($expected, (string) $violation);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user