@@ -1184,15 +1184,53 @@ public function testRequestIsMacroable()
1184
1184
1185
1185
public function testRequestExceptionIsThrownWhenRetriesExhausted ()
1186
1186
{
1187
- $ this ->expectException (RequestException::class);
1188
-
1189
1187
$ this ->factory ->fake ([
1190
1188
'* ' => $ this ->factory ->response (['error ' ], 403 ),
1191
1189
]);
1192
1190
1193
- $ this ->factory
1194
- ->retry (2 , 1000 , null , true )
1195
- ->get ('http://foo.com/get ' );
1191
+ $ exception = null ;
1192
+
1193
+ try {
1194
+ $ this ->factory
1195
+ ->retry (2 , 1000 , null , true )
1196
+ ->get ('http://foo.com/get ' );
1197
+ } catch (RequestException $ e ) {
1198
+ $ exception = $ e ;
1199
+ }
1200
+
1201
+ $ this ->assertNotNull ($ exception );
1202
+ $ this ->assertInstanceOf (RequestException::class, $ exception );
1203
+
1204
+ $ this ->factory ->assertSentCount (2 );
1205
+ }
1206
+
1207
+ public function testRequestExceptionIsThrownWithoutRetriesIfRetryNotNecessary ()
1208
+ {
1209
+ $ this ->factory ->fake ([
1210
+ '* ' => $ this ->factory ->response (['error ' ], 500 ),
1211
+ ]);
1212
+
1213
+ $ exception = null ;
1214
+ $ whenAttempts = 0 ;
1215
+
1216
+ try {
1217
+ $ this ->factory
1218
+ ->retry (2 , 1000 , function ($ exception ) use (&$ whenAttempts ) {
1219
+ $ whenAttempts ++;
1220
+
1221
+ return $ exception ->response ->status () === 403 ;
1222
+ }, true )
1223
+ ->get ('http://foo.com/get ' );
1224
+ } catch (RequestException $ e ) {
1225
+ $ exception = $ e ;
1226
+ }
1227
+
1228
+ $ this ->assertNotNull ($ exception );
1229
+ $ this ->assertInstanceOf (RequestException::class, $ exception );
1230
+
1231
+ $ this ->assertSame (1 , $ whenAttempts );
1232
+
1233
+ $ this ->factory ->assertSentCount (1 );
1196
1234
}
1197
1235
1198
1236
public function testRequestExceptionIsNotThrownWhenDisabledAndRetriesExhausted ()
@@ -1206,6 +1244,31 @@ public function testRequestExceptionIsNotThrownWhenDisabledAndRetriesExhausted()
1206
1244
->get ('http://foo.com/get ' );
1207
1245
1208
1246
$ this ->assertTrue ($ response ->failed ());
1247
+
1248
+ $ this ->factory ->assertSentCount (2 );
1249
+ }
1250
+
1251
+ public function testRequestExceptionIsNotThrownWithoutRetriesIfRetryNotNecessary ()
1252
+ {
1253
+ $ this ->factory ->fake ([
1254
+ '* ' => $ this ->factory ->response (['error ' ], 500 ),
1255
+ ]);
1256
+
1257
+ $ whenAttempts = 0 ;
1258
+
1259
+ $ response = $ this ->factory
1260
+ ->retry (2 , 1000 , function ($ exception ) use (&$ whenAttempts ) {
1261
+ $ whenAttempts ++;
1262
+
1263
+ return $ exception ->response ->status () === 403 ;
1264
+ }, false )
1265
+ ->get ('http://foo.com/get ' );
1266
+
1267
+ $ this ->assertTrue ($ response ->failed ());
1268
+
1269
+ $ this ->assertSame (1 , $ whenAttempts );
1270
+
1271
+ $ this ->factory ->assertSentCount (1 );
1209
1272
}
1210
1273
1211
1274
public function testMiddlewareRunsWhenFaked ()
0 commit comments