@@ -300,6 +300,44 @@ public function selectMissingKeys()
300300 );
301301 }
302302
303+ /**
304+ * @test
305+ * @covers ::next
306+ */
307+ public function collectionThrowsApiExceptionWith400Response ()
308+ {
309+ $ response = new Response (400 , ['Content-Type ' => ['application/json ' ]], []);
310+ $ mockClient = $ this ->getMockBuilder (ClientInterface::class)->getMock ();
311+ $ mockClient ->method ('index ' )->willReturn ($ response );
312+ $ collection = new Collection ($ mockClient , 'basic ' , []);
313+ try {
314+ $ collection ->next ();
315+ $ this ->fail ('No Exception throw ' );
316+ } catch (Exception $ e ) {
317+ $ this ->assertSame ('Did not receive 200 from API. Instead received 400 ' , $ e ->getMessage ());
318+ $ this ->assertSame ($ response , $ e ->getResponse ());
319+ }
320+ }
321+
322+ /**
323+ * @test
324+ * @covers ::next
325+ */
326+ public function collectionThrowsApiExceptionWith500Response ()
327+ {
328+ $ response = new Response (500 , ['Content-Type ' => ['application/json ' ]], []);
329+ $ mockClient = $ this ->getMockBuilder (ClientInterface::class)->getMock ();
330+ $ mockClient ->method ('index ' )->willReturn ($ response );
331+ $ collection = new Collection ($ mockClient , 'basic ' , []);
332+ try {
333+ $ collection ->next ();
334+ $ this ->fail ('No Exception throw ' );
335+ } catch (Exception $ e ) {
336+ $ this ->assertSame ('Did not receive 200 from API. Instead received 500 ' , $ e ->getMessage ());
337+ $ this ->assertSame ($ response , $ e ->getResponse ());
338+ }
339+ }
340+
303341 private function getClient (array $ items = self ::DEFAULT_RESULT_SET ) : ClientInterface
304342 {
305343 $ callback = function (string $ resource , array $ filters ) use ($ items ) {
0 commit comments