Add forbidden response test cases

This commit is contained in:
Littlesqx 2019-08-28 16:28:55 +08:00 committed by David Garcia
parent e0cb8023a7
commit 4a2a4fe4a5

View File

@ -34,4 +34,30 @@ class HttpClientExceptionTest extends MailgunTestCase
$exception = HttpClientException::badRequest($response);
$this->assertStringEndsWith('<html><body>Server HTML</body></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'], '<html><body>Forbidden</body></html>');
$exception = HttpClientException::badRequest($response);
$this->assertStringEndsWith('<html><body>Forbidden</body></html>', $exception->getMessage());
}
}