From 5481891e6d8f6a15c319f827c584b68744ac3b9b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 17 Mar 2024 16:35:01 +0000 Subject: [PATCH] [HttpFoundation] Tweak previous merged PR --- .../Test/Constraint/ResponseFormatSame.php | 9 ++++++--- .../Test/Constraint/ResponseIsRedirected.php | 11 +++++------ .../Test/Constraint/ResponseIsSuccessful.php | 11 +++++------ .../Test/Constraint/ResponseIsUnprocessable.php | 11 +++++------ .../Test/Constraint/ResponseStatusCodeSame.php | 11 +++++------ 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseFormatSame.php b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseFormatSame.php index b14dcee94787..c75321f24402 100644 --- a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseFormatSame.php +++ b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseFormatSame.php @@ -25,8 +25,11 @@ final class ResponseFormatSame extends Constraint private Request $request; private ?string $format; - public function __construct(Request $request, ?string $format) - { + public function __construct( + Request $request, + ?string $format, + private readonly bool $verbose = true, + ) { $this->request = $request; $this->format = $format; } @@ -57,6 +60,6 @@ protected function failureDescription($response): string */ protected function additionalFailureDescription($response): string { - return (string) $response; + return $this->verbose ? (string) $response : explode("\r\n\r\n", (string) $response)[0]; } } diff --git a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsRedirected.php b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsRedirected.php index b1abd905e424..b7ae15e78295 100644 --- a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsRedirected.php +++ b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsRedirected.php @@ -44,12 +44,11 @@ protected function failureDescription($response): string return 'the Response '.$this->toString(); } - protected function additionalFailureDescription($other): string + /** + * @param Response $response + */ + protected function additionalFailureDescription($response): string { - if ($this->verbose || !($other instanceof Response)) { - return (string) $other; - } else { - return explode("\r\n\r\n", (string) $other)[0]; - } + return $this->verbose ? (string) $response : explode("\r\n\r\n", (string) $response)[0]; } } diff --git a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsSuccessful.php b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsSuccessful.php index d7d6c502a17c..94a65eda4402 100644 --- a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsSuccessful.php +++ b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsSuccessful.php @@ -44,12 +44,11 @@ protected function failureDescription($response): string return 'the Response '.$this->toString(); } - protected function additionalFailureDescription($other): string + /** + * @param Response $response + */ + protected function additionalFailureDescription($response): string { - if ($this->verbose || !($other instanceof Response)) { - return (string) $other; - } else { - return explode("\r\n\r\n", (string) $other)[0]; - } + return $this->verbose ? (string) $response : explode("\r\n\r\n", (string) $response)[0]; } } diff --git a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsUnprocessable.php b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsUnprocessable.php index c791a31bd63c..799d5583aec8 100644 --- a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsUnprocessable.php +++ b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsUnprocessable.php @@ -44,12 +44,11 @@ protected function failureDescription($other): string return 'the Response '.$this->toString(); } - protected function additionalFailureDescription($other): string + /** + * @param Response $response + */ + protected function additionalFailureDescription($response): string { - if ($this->verbose || !($other instanceof Response)) { - return (string) $other; - } else { - return explode("\r\n\r\n", (string) $other)[0]; - } + return $this->verbose ? (string) $response : explode("\r\n\r\n", (string) $response)[0]; } } diff --git a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseStatusCodeSame.php b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseStatusCodeSame.php index 8259e09fdf2f..5ca6373ce28d 100644 --- a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseStatusCodeSame.php +++ b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseStatusCodeSame.php @@ -44,12 +44,11 @@ protected function failureDescription($response): string return 'the Response '.$this->toString(); } - protected function additionalFailureDescription($other): string + /** + * @param Response $response + */ + protected function additionalFailureDescription($response): string { - if ($this->verbose || !($other instanceof Response)) { - return (string) $other; - } else { - return explode("\r\n\r\n", (string) $other)[0]; - } + return $this->verbose ? (string) $response : explode("\r\n\r\n", (string) $response)[0]; } }