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 72a464e

Browse filesBrowse files
committed
Fix ConstraintViolation#getMessageTemplate() to always return string
`ConstraintViolation#getMessageTemplate()`'s inherited signature states that `string` is to be returned by it at all times, yet the implementation returns `null` when no message template had been provided at instantiation. This patch obviates it, returning an empty string when the message template is `null`. Ref: symfony#40415 (comment)
1 parent e5f9a89 commit 72a464e
Copy full SHA for 72a464e

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+16
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/ConstraintViolation.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function __toString()
100100
*/
101101
public function getMessageTemplate()
102102
{
103-
return $this->messageTemplate;
103+
return (string) $this->messageTemplate;
104104
}
105105

106106
/**

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/ConstraintViolationTest.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,19 @@ public function testRetrievedPropertyPathIsAStringEvenIfNotSet()
171171
))->getPropertyPath()
172172
);
173173
}
174+
175+
public function testRetrievedMessageTemplateIsAStringEvenIfNotSet()
176+
{
177+
self::assertSame(
178+
'',
179+
(new ConstraintViolation(
180+
'irrelevant',
181+
null,
182+
[],
183+
'irrelevant',
184+
'irrelevant',
185+
null
186+
))->getMessageTemplate()
187+
);
188+
}
174189
}

0 commit comments

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