handle array root element
An array to string conversion notice was thrown when the root element of the thing being validated is an array.
This commit is contained in:
parent
ca5eea5c19
commit
17ed8bf563
@ -95,7 +95,14 @@ class ConstraintViolation implements ConstraintViolationInterface
|
|||||||
*/
|
*/
|
||||||
public function __toString()
|
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;
|
$propertyPath = (string) $this->propertyPath;
|
||||||
$code = $this->code;
|
$code = $this->code;
|
||||||
|
|
||||||
|
@ -33,4 +33,23 @@ EOF;
|
|||||||
|
|
||||||
$this->assertSame($expected, (string) $violation);
|
$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