From 7d1029b9079471686ecf688da044c2d3750a6af4 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 8 Mar 2021 14:18:40 +0100 Subject: [PATCH] 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`. --- .../Component/Validator/ConstraintViolation.php | 2 +- .../Validator/Tests/ConstraintViolationTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Validator/ConstraintViolation.php b/src/Symfony/Component/Validator/ConstraintViolation.php index 982ebe275950a..2004745fe238d 100644 --- a/src/Symfony/Component/Validator/ConstraintViolation.php +++ b/src/Symfony/Component/Validator/ConstraintViolation.php @@ -140,7 +140,7 @@ public function getRoot() */ public function getPropertyPath() { - return $this->propertyPath; + return (string) $this->propertyPath; } /** diff --git a/src/Symfony/Component/Validator/Tests/ConstraintViolationTest.php b/src/Symfony/Component/Validator/Tests/ConstraintViolationTest.php index eb5810dafbd89..a7734635aacff 100644 --- a/src/Symfony/Component/Validator/Tests/ConstraintViolationTest.php +++ b/src/Symfony/Component/Validator/Tests/ConstraintViolationTest.php @@ -156,4 +156,19 @@ public function testMessageObjectMustBeStringable() null ); } + + public function testRetrievedPropertyPathIsAStringEvenIfNotSet() + { + self::assertSame( + '', + (new ConstraintViolation( + 'irrelevant', + '', + [], + 'irrelevant', + null, + null + ))->getPropertyPath() + ); + } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy