Skip to content

Commit 456a3d9

Browse files
committed
Fix ConstraintViolation#getPropertyPath() to always return string
`ConstraintViolation#getPropertyPath()`'s inherited signature states that `string` is to be returned by it at all times, yet the implementation returns `null` when no property path had been provided at instantiation. This patch obviates it, returning an empty string when the property path is `null`.
1 parent adc4d38 commit 456a3d9

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

ConstraintViolation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function getRoot()
140140
*/
141141
public function getPropertyPath()
142142
{
143-
return $this->propertyPath;
143+
return (string) $this->propertyPath;
144144
}
145145

146146
/**

Tests/ConstraintViolationTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,19 @@ public function testMessageObjectMustBeStringable()
156156
null
157157
);
158158
}
159+
160+
public function testRetrievedPropertyPathIsAStringEvenIfNotSet()
161+
{
162+
self::assertSame(
163+
'',
164+
(new ConstraintViolation(
165+
'irrelevant',
166+
'',
167+
[],
168+
'irrelevant',
169+
null,
170+
null
171+
))->getPropertyPath()
172+
);
173+
}
159174
}

0 commit comments

Comments
 (0)