@@ -244,4 +244,104 @@ public function testRetryOnErrorAssertContent()
244
244
self ::assertSame ('Test out content ' , $ response ->getContent ());
245
245
self ::assertSame ('Test out content ' , $ response ->getContent (), 'Content should be buffered ' );
246
246
}
247
+
248
+ public function testRetryWithMultipleBaseUris ()
249
+ {
250
+ $ client = new RetryableHttpClient (
251
+ new MockHttpClient ([
252
+ new MockResponse ('' , ['http_code ' => 500 ]),
253
+ new MockResponse ('Hit on second uri ' , ['http_code ' => 200 ]),
254
+ ]),
255
+ new GenericRetryStrategy ([500 ], 0 ),
256
+ 1
257
+ );
258
+
259
+ $ response = $ client ->request ('GET ' , 'foo-bar ' , [
260
+ 'base_uri ' => [
261
+ 'http://example.com/a/ ' ,
262
+ 'http://example.com/b/ ' ,
263
+ ],
264
+ ]);
265
+
266
+ self ::assertSame (200 , $ response ->getStatusCode ());
267
+ self ::assertSame ('http://example.com/b/foo-bar ' , $ response ->getInfo ('url ' ));
268
+ }
269
+
270
+ public function testMultipleBaseUrisAsOptions ()
271
+ {
272
+ $ client = new RetryableHttpClient (
273
+ new MockHttpClient ([
274
+ new MockResponse ('' , ['http_code ' => 500 ]),
275
+ new MockResponse ('Hit on second uri ' , ['http_code ' => 200 ]),
276
+ ]),
277
+ new GenericRetryStrategy ([500 ], 0 ),
278
+ 1
279
+ );
280
+
281
+ $ client = $ client ->withOptions ([
282
+ 'base_uri ' => [
283
+ 'http://example.com/a/ ' ,
284
+ 'http://example.com/b/ ' ,
285
+ ],
286
+ ]);
287
+
288
+ $ response = $ client ->request ('GET ' , 'foo-bar ' );
289
+
290
+ self ::assertSame (200 , $ response ->getStatusCode ());
291
+ self ::assertSame ('http://example.com/b/foo-bar ' , $ response ->getInfo ('url ' ));
292
+ }
293
+
294
+ public function testRetryWithMultipleBaseUrisShufflesNestedArray ()
295
+ {
296
+ $ client = new RetryableHttpClient (
297
+ new MockHttpClient ([
298
+ new MockResponse ('' , ['http_code ' => 500 ]),
299
+ new MockResponse ('Hit on second uri ' , ['http_code ' => 200 ]),
300
+ ]),
301
+ new GenericRetryStrategy ([500 ], 0 ),
302
+ 1
303
+ );
304
+
305
+ $ response = $ client ->request ('GET ' , 'foo-bar ' , [
306
+ 'base_uri ' => [
307
+ 'http://example.com/a/ ' ,
308
+ [
309
+ 'http://example.com/b/ ' ,
310
+ 'http://example.com/c/ ' ,
311
+ ],
312
+ 'http://example.com/d/ ' ,
313
+ ],
314
+ ]);
315
+
316
+ self ::assertSame (200 , $ response ->getStatusCode ());
317
+ self ::assertMatchesRegularExpression ('#^http://example.com/(b|c)/foo-bar$# ' , $ response ->getInfo ('url ' ));
318
+ }
319
+
320
+ public function testRetryWithMultipleBaseUrisPreservesNonNestedOrder ()
321
+ {
322
+ $ client = new RetryableHttpClient (
323
+ new MockHttpClient ([
324
+ new MockResponse ('' , ['http_code ' => 500 ]),
325
+ new MockResponse ('' , ['http_code ' => 500 ]),
326
+ new MockResponse ('' , ['http_code ' => 500 ]),
327
+ new MockResponse ('Hit on second uri ' , ['http_code ' => 200 ]),
328
+ ]),
329
+ new GenericRetryStrategy ([500 ], 0 ),
330
+ 3
331
+ );
332
+
333
+ $ response = $ client ->request ('GET ' , 'foo-bar ' , [
334
+ 'base_uri ' => [
335
+ 'http://example.com/a/ ' ,
336
+ [
337
+ 'http://example.com/b/ ' ,
338
+ 'http://example.com/c/ ' ,
339
+ ],
340
+ 'http://example.com/d/ ' ,
341
+ ],
342
+ ]);
343
+
344
+ self ::assertSame (200 , $ response ->getStatusCode ());
345
+ self ::assertSame ('http://example.com/d/foo-bar ' , $ response ->getInfo ('url ' ));
346
+ }
247
347
}
0 commit comments