diff --git a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsRedirected.php b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsRedirected.php index d4e650e6fbc98..ba40e1b89c944 100644 --- a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsRedirected.php +++ b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsRedirected.php @@ -17,7 +17,7 @@ final class ResponseIsRedirected extends Constraint { /** - * @param booll $verbose If true, the entire response is printed on failure. If false, the response body is omitted. + * @param bool $verbose If true, the entire response is printed on failure. If false, the response body is omitted. */ public function __construct(private readonly bool $verbose = true) { @@ -44,11 +44,12 @@ protected function failureDescription($response): string return 'the Response '.$this->toString(); } - /** - * @param Response $response - */ - protected function additionalFailureDescription($response): string + protected function additionalFailureDescription($other): string { - return $this->verbose ? (string) $response : $response->getCommandString()."\r\n".$response->headers; + if ($this->verbose || !($other instanceof Response)) { + return (string) $other; + } else { + return $other->getCommandString()."\r\n".$other->headers; + } } } diff --git a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsSuccessful.php b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsSuccessful.php index 3ea8c69d2a523..fa675e6a1950a 100644 --- a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsSuccessful.php +++ b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsSuccessful.php @@ -17,7 +17,7 @@ final class ResponseIsSuccessful extends Constraint { /** - * @param booll $verbose If true, the entire response is printed on failure. If false, the response body is omitted. + * @param bool $verbose If true, the entire response is printed on failure. If false, the response body is omitted. */ public function __construct(private readonly bool $verbose = true) { @@ -44,11 +44,12 @@ protected function failureDescription($response): string return 'the Response '.$this->toString(); } - /** - * @param Response $response - */ - protected function additionalFailureDescription($response): string + protected function additionalFailureDescription($other): string { - return $this->verbose ? (string) $response : $response->getCommandString()."\r\n".$response->headers; + if ($this->verbose || !($other instanceof Response)) { + return (string) $other; + } else { + return $other->getCommandString()."\r\n".$other->headers; + } } } diff --git a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsUnprocessable.php b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsUnprocessable.php index 59004158f0017..36c201104d0ac 100644 --- a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsUnprocessable.php +++ b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseIsUnprocessable.php @@ -16,6 +16,9 @@ final class ResponseIsUnprocessable extends Constraint { + /** + * @param bool $verbose If true, the entire response is printed on failure. If false, the response body is omitted. + */ public function __construct(private readonly bool $verbose = true) { } @@ -26,26 +29,30 @@ public function toString(): string } /** - * @param Response $response + * @param Response $other */ - protected function matches($response): bool + protected function matches($other): bool { - return Response::HTTP_UNPROCESSABLE_ENTITY === $response->getStatusCode(); + return Response::HTTP_UNPROCESSABLE_ENTITY === $other->getStatusCode(); } /** - * @param Response $response + * @param Response $other */ - protected function failureDescription($response): string + protected function failureDescription($other): string { return 'the Response '.$this->toString(); } /** - * @param Response $response + * @param Response $other */ - protected function additionalFailureDescription($response): string + protected function additionalFailureDescription($other): string { - return $this->verbose ? (string) $response : $response->getCommandString()."\r\n".$response->headers; + if ($this->verbose || !($other instanceof Response)) { + return (string) $other; + } else { + return $other->getCommandString()."\r\n".$other->headers; + } } } diff --git a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseStatusCodeSame.php b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseStatusCodeSame.php index 9358fe3319b64..7e6b29b3438f9 100644 --- a/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseStatusCodeSame.php +++ b/src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseStatusCodeSame.php @@ -45,10 +45,14 @@ protected function failureDescription($response): string } /** - * @param Response $response + * @param Response $other */ - protected function additionalFailureDescription($response): string + protected function additionalFailureDescription($other): string { - return $this->verbose ? (string) $response : $response->getCommandString()."\r\n".$response->headers; + if ($this->verbose || !($other instanceof Response)) { + return (string) $other; + } else { + return $other->getCommandString()."\r\n".$other->headers; + } } }