@@ -154,6 +154,78 @@ public function testErrorOverCapacity()
154154 $ listener ->error ($ this ->getEventMock ($ response ));
155155 }
156156
157+ /**
158+ * @expectedException \Imgur\Exception\ErrorException
159+ * @expectedExceptionMessage Request to: /3/image.json failed with: "You are uploading too fast. Please wait 59 more minutes."
160+ */
161+ public function testErrorUploadingTooFast ()
162+ {
163+ $ response = $ this ->getMockBuilder ('GuzzleHttp\Message\ResponseInterface ' )
164+ ->disableOriginalConstructor ()
165+ ->getMock ();
166+ $ response ->expects ($ this ->exactly (2 ))
167+ ->method ('getStatusCode ' )
168+ ->will ($ this ->returnValue (429 ));
169+ $ response ->expects ($ this ->once ())
170+ ->method ('getBody ' )
171+ ->will ($ this ->returnValue (json_encode (['status ' => 400 , 'success ' => false , 'data ' => ['error ' => ['code ' => 429 , 'message ' => 'You are uploading too fast. Please wait 59 more minutes. ' , 'type ' => 'ImgurException ' , 'exception ' => []], 'request ' => '/3/image.json ' , 'method ' => 'POST ' ]])));
172+ $ response ->expects ($ this ->at (1 ))
173+ ->method ('getHeader ' )
174+ ->with ('X-RateLimit-UserRemaining ' )
175+ ->will ($ this ->returnValue (9 ));
176+ $ response ->expects ($ this ->at (2 ))
177+ ->method ('getHeader ' )
178+ ->with ('X-RateLimit-UserLimit ' )
179+ ->will ($ this ->returnValue (10 ));
180+ $ response ->expects ($ this ->at (3 ))
181+ ->method ('getHeader ' )
182+ ->with ('X-RateLimit-ClientRemaining ' )
183+ ->will ($ this ->returnValue (9 ));
184+ $ response ->expects ($ this ->at (4 ))
185+ ->method ('getHeader ' )
186+ ->with ('X-RateLimit-ClientLimit ' )
187+ ->will ($ this ->returnValue (10 ));
188+
189+ $ listener = new ErrorListener ();
190+ $ listener ->error ($ this ->getEventMock ($ response ));
191+ }
192+
193+ /**
194+ * @expectedException \Imgur\Exception\ErrorException
195+ * @expectedExceptionMessage Request to: /3/image.json failed with: "Error code: 666"
196+ */
197+ public function testErrorNoMessageInError ()
198+ {
199+ $ response = $ this ->getMockBuilder ('GuzzleHttp\Message\ResponseInterface ' )
200+ ->disableOriginalConstructor ()
201+ ->getMock ();
202+ $ response ->expects ($ this ->exactly (2 ))
203+ ->method ('getStatusCode ' )
204+ ->will ($ this ->returnValue (429 ));
205+ $ response ->expects ($ this ->once ())
206+ ->method ('getBody ' )
207+ ->will ($ this ->returnValue (json_encode (['status ' => 400 , 'success ' => false , 'data ' => ['error ' => ['code ' => 666 , 'type ' => 'ImgurException ' , 'exception ' => []], 'request ' => '/3/image.json ' , 'method ' => 'POST ' ]])));
208+ $ response ->expects ($ this ->at (1 ))
209+ ->method ('getHeader ' )
210+ ->with ('X-RateLimit-UserRemaining ' )
211+ ->will ($ this ->returnValue (9 ));
212+ $ response ->expects ($ this ->at (2 ))
213+ ->method ('getHeader ' )
214+ ->with ('X-RateLimit-UserLimit ' )
215+ ->will ($ this ->returnValue (10 ));
216+ $ response ->expects ($ this ->at (3 ))
217+ ->method ('getHeader ' )
218+ ->with ('X-RateLimit-ClientRemaining ' )
219+ ->will ($ this ->returnValue (9 ));
220+ $ response ->expects ($ this ->at (4 ))
221+ ->method ('getHeader ' )
222+ ->with ('X-RateLimit-ClientLimit ' )
223+ ->will ($ this ->returnValue (10 ));
224+
225+ $ listener = new ErrorListener ();
226+ $ listener ->error ($ this ->getEventMock ($ response ));
227+ }
228+
157229 /**
158230 * @expectedException \Imgur\Exception\RuntimeException
159231 * @expectedExceptionMessage hihi
0 commit comments