8000 Fix `ConstraintViolation#getMessageTemplate()` to always return `string` · symfony/symfony@72a464e · GitHub
[go: up one dir, main page]

Skip to content

Commit 72a464e

Browse 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: #40415 (comment)
1 parent e5f9a89 commit 72a464e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Symfony/Component/Validator/ConstraintViolation.php

Lines 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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,19 @@ public function testRetrievedPropertyPathIsAStringEvenIfNotSet()
< 8000 code>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