55use Akeneo \Pim \ApiClient \Exception \BadRequestHttpException ;
66use Akeneo \Pim \ApiClient \Exception \ClientErrorHttpException ;
77use Akeneo \Pim \ApiClient \Exception \ForbiddenHttpException ;
8+ use Akeneo \Pim \ApiClient \Exception \MethodNotAllowedHttpException ;
89use Akeneo \Pim \ApiClient \Exception \NotFoundHttpException ;
910use Akeneo \Pim \ApiClient \Exception \RedirectionHttpException ;
1011use Akeneo \Pim \ApiClient \Exception \ServerErrorHttpException ;
@@ -123,6 +124,31 @@ function it_throws_not_found_exception_when_status_code_404(
123124 ->during ('transformResponseToException ' , [$ request , $ response ]);
124125 }
125126
127+ function it_throws_method_not_allowed_exception_when_status_code_405 (
128+ RequestInterface $ request ,
129+ ResponseInterface $ response ,
130+ StreamInterface $ responseBody
131+ ) {
132+ $ response ->getStatusCode ()->willReturn (405 );
133+ $ response ->getBody ()->willReturn ($ responseBody );
134+ $ responseBody ->getContents ()->willReturn (<<<JSON
135+ {
136+ "code": 405,
137+ "message": "No route found for 'POST /api/rest/v1/products/myproduct': Method Not Allowed (Allow: GET, PATCH, DELETE)"
138+ }
139+ JSON );
140+ $ responseBody ->rewind ()->shouldBeCalled ();
141+ $ this
142+ ->shouldThrow (
143+ new MethodNotAllowedHttpException (
144+ 'No route found for \'POST /api/rest/v1/products/myproduct \': Method Not Allowed (Allow: GET, PATCH, DELETE) ' ,
145+ $ request ->getWrappedObject (),
146+ $ response ->getWrappedObject ()
147+ )
148+ )
149+ ->during ('transformResponseToException ' , [$ request , $ response ]);
150+ }
151+
126152 function it_throws_bad_request_exception_when_status_code_422 (
127153 RequestInterface $ request ,
128154 ResponseInterface $ response ,
@@ -148,9 +174,9 @@ function it_throws_bad_request_exception_when_status_code_4xx(
148174 ResponseInterface $ response ,
149175 StreamInterface $ responseBody
150176 ) {
151- $ response ->getStatusCode ()->willReturn (405 );
177+ $ response ->getStatusCode ()->willReturn (418 );
152178 $ response ->getBody ()->willReturn ($ responseBody );
153- $ responseBody ->getContents ()->willReturn ('{"code": 405 , "message": "Not allowed."} ' );
179+ $ responseBody ->getContents ()->willReturn ('{"code": 418 , "message": "Not allowed."} ' );
154180 $ responseBody ->rewind ()->shouldBeCalled ();
155181 $ this
156182 ->shouldThrow (
0 commit comments