Skip to content

Commit d5f9486

Browse files
committed
test: Add 403 forbidden spec test
1 parent ebb0c1c commit d5f9486

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

spec/Client/HttpExceptionHandlerSpec.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Akeneo\Pim\ApiClient\Exception\BadRequestHttpException;
66
use Akeneo\Pim\ApiClient\Exception\ClientErrorHttpException;
7+
use Akeneo\Pim\ApiClient\Exception\ForbiddenHttpException;
78
use Akeneo\Pim\ApiClient\Exception\NotFoundHttpException;
89
use Akeneo\Pim\ApiClient\Exception\RedirectionHttpException;
910
use Akeneo\Pim\ApiClient\Exception\ServerErrorHttpException;
@@ -82,6 +83,26 @@ function it_throws_unauthorized_request_exception_when_status_code_401(
8283
->during('transformResponseToException', [$request, $response]);
8384
}
8485

86+
function it_throws_forbidden_exception_when_status_code_403(
87+
RequestInterface $request,
88+
ResponseInterface $response,
89+
StreamInterface $responseBody
90+
) {
91+
$response->getStatusCode()->willReturn(403);
92+
$response->getBody()->willReturn($responseBody);
93+
$responseBody->getContents()->willReturn('{"code": 403, "message": "Access forbidden."}');
94+
$responseBody->rewind()->shouldBeCalled();
95+
$this
96+
->shouldThrow(
97+
new ForbiddenHttpException(
98+
'Access forbidden.',
99+
$request->getWrappedObject(),
100+
$response->getWrappedObject()
101+
)
102+
)
103+
->during('transformResponseToException', [$request, $response]);
104+
}
105+
85106
function it_throws_not_found_exception_when_status_code_404(
86107
RequestInterface $request,
87108
ResponseInterface $response,

0 commit comments

Comments
 (0)