From 4a2a4fe4a5331d71ecff0f19b0ee4fc93ba5a501 Mon Sep 17 00:00:00 2001 From: Littlesqx Date: Wed, 28 Aug 2019 16:28:55 +0800 Subject: [PATCH] Add forbidden response test cases --- tests/Exception/HttpClientExceptionTest.php | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/Exception/HttpClientExceptionTest.php b/tests/Exception/HttpClientExceptionTest.php index 0756855..c1504f9 100644 --- a/tests/Exception/HttpClientExceptionTest.php +++ b/tests/Exception/HttpClientExceptionTest.php @@ -34,4 +34,30 @@ class HttpClientExceptionTest extends MailgunTestCase $exception = HttpClientException::badRequest($response); $this->assertStringEndsWith('Server HTML', $exception->getMessage()); } + + public function testForbiddenRequestThrowException() + { + $response = new Response(403, ['Content-Type' => 'application/json'], '{"Error":"Business Verification"}'); + $exception = HttpClientException::forbidden($response); + $this->assertInstanceOf(HttpClientException::class, $exception); + $this->assertSame(403, $exception->getCode()); + } + + public function testForbiddenRequestGetMessageJson() + { + $response = new Response(403, ['Content-Type' => 'application/json'], '{"Error":"Business Verification"}'); + $exception = HttpClientException::forbidden($response); + $this->assertStringEndsWith('Business Verification', $exception->getMessage()); + + $response = new Response(403, ['Content-Type' => 'application/json'], '{"Message":"Business Verification"}'); + $exception = HttpClientException::forbidden($response); + $this->assertStringEndsWith('{"Message":"Business Verification"}', $exception->getMessage()); + } + + public function testForbiddenRequestGetMessage() + { + $response = new Response(400, ['Content-Type' => 'text/html'], 'Forbidden'); + $exception = HttpClientException::badRequest($response); + $this->assertStringEndsWith('Forbidden', $exception->getMessage()); + } }