Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 17ed8bf

Browse filesBrowse files
Grégoire Parisfabpot
authored andcommitted
handle array root element
An array to string conversion notice was thrown when the root element of the thing being validated is an array.
1 parent ca5eea5 commit 17ed8bf
Copy full SHA for 17ed8bf

File tree

Expand file treeCollapse file tree

2 files changed

+27
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+27
-1
lines changed

‎src/Symfony/Component/Validator/ConstraintViolation.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/ConstraintViolation.php
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,14 @@ public function __construct($message, $messageTemplate, array $messageParameters
9595
*/
9696
public function __toString()
9797
{
98-
$class = (string) (is_object($this->root) ? get_class($this->root) : $this->root);
98+
if (is_object($this->root)) {
99+
$class = get_class($this->root);
100+
} elseif (is_array($this->root)) {
101+
$class = "Array";
102+
} else {
103+
$class = (string) $this->root;
104+
}
105+
99106
$propertyPath = (string) $this->propertyPath;
100107
$code = $this->code;
101108

‎src/Symfony/Component/Validator/Tests/ConstraintViolationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/ConstraintViolationTest.php
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,23 @@ public function testToStringHandlesArrays()
3333

3434
$this->assertSame($expected, (string) $violation);
3535
}
36+
37+
public function testToStringHandlesArrayRoots()
38+
{
39+
$violation = new ConstraintViolation(
40+
'42 cannot be used here',
41+
'this is the message template',
42+
array(),
43+
array('some_value' => 42),
44+
'some_value',
45+
null
46+
);
47+
48+
$expected = <<<EOF
49+
Array.some_value:
50+
42 cannot be used here
51+
EOF;
52+
53+
$this->assertSame($expected, (string) $violation);
54+
}
3655
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.