diff --git a/src/PushGateway/PSR18UnexpectedPushGatewayResponse.php b/src/PushGateway/PSR18UnexpectedPushGatewayResponse.php index b7440d42..d17bab8d 100644 --- a/src/PushGateway/PSR18UnexpectedPushGatewayResponse.php +++ b/src/PushGateway/PSR18UnexpectedPushGatewayResponse.php @@ -14,13 +14,13 @@ private function __construct(private RequestInterface $request, private Response { $exceptionCode = 0; - $message = 'Cannot connect PushGateway server to ' . $request->getUri()->__toString() . ':'; + $message = 'Cannot connect PushGateway server to ' . $request->getUri()->__toString(); if ($response !== null) { - $message = ' ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase(); + $message .= ': ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase(); } if ($clientException !== null) { - $message = ' ' . $clientException->getMessage(); + $message .= ': ' . $clientException->getMessage(); $exceptionCode = $clientException->getCode(); } diff --git a/tests/unit/PushGateway/PSR18UnexpectedPushGatewayResponseTest.php b/tests/unit/PushGateway/PSR18UnexpectedPushGatewayResponseTest.php index 40daf678..654cb89a 100644 --- a/tests/unit/PushGateway/PSR18UnexpectedPushGatewayResponseTest.php +++ b/tests/unit/PushGateway/PSR18UnexpectedPushGatewayResponseTest.php @@ -20,6 +20,7 @@ public function testInvalidResponse(): void $exception = PSR18UnexpectedPushGatewayResponse::invalidResponse($request, $response); + self::assertStringContainsString('Cannot connect PushGateway server to /: 500 Internal', $exception->getMessage()); self::assertSame($request, $exception->getRequest()); self::assertSame($response, $exception->getResponse()); self::assertNull($exception->getPrevious()); @@ -29,11 +30,12 @@ public function testInvalidResponse(): void public function testRequestFailure(): void { $request = Psr17FactoryDiscovery::findRequestFactory()->createRequest('PUT', '/'); - $clientException = new class extends Exception implements ClientExceptionInterface { + $clientException = new class ('some reason') extends Exception implements ClientExceptionInterface { }; $exception = PSR18UnexpectedPushGatewayResponse::requestFailure($request, $clientException); + self::assertStringContainsString('Cannot connect PushGateway server to /: some reason', $exception->getMessage()); self::assertSame($request, $exception->getRequest()); self::assertNull($exception->getResponse()); self::assertSame($clientException, $exception->getPrevious());