12
12
use Psr \Http \Message \RequestInterface ;
13
13
use Psr \Http \Message \ResponseInterface ;
14
14
use Psr \Http \Message \StreamInterface ;
15
+ use Psr \Http \Message \UriInterface ;
15
16
16
17
class CachePluginSpec extends ObjectBehavior
17
18
{
@@ -33,15 +34,16 @@ function it_is_a_plugin()
33
34
$ this ->shouldImplement ('Http\Client\Common\Plugin ' );
34
35
}
35
36
36
- function it_caches_responses (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , ResponseInterface $ response , StreamInterface $ stream )
37
+ function it_caches_responses (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , UriInterface $ uri , ResponseInterface $ response , StreamInterface $ stream )
37
38
{
38
39
$ httpBody = 'body ' ;
39
40
$ stream ->__toString ()->willReturn ($ httpBody );
40
41
$ stream ->isSeekable ()->willReturn (true );
41
42
$ stream ->rewind ()->shouldBeCalled ();
42
43
43
44
$ request ->getMethod ()->willReturn ('GET ' );
44
- $ request ->getUri ()->willReturn ('/ ' );
45
+ $ request ->getUri ()->willReturn ($ uri );
46
+ $ uri ->__toString ()->willReturn ('https://example.com/ ' );
45
47
$ request ->getBody ()->shouldBeCalled ();
46
48
47
49
$ response ->getStatusCode ()->willReturn (200 );
@@ -50,7 +52,7 @@ function it_caches_responses(CacheItemPoolInterface $pool, CacheItemInterface $i
50
52
$ response ->getHeader ('Expires ' )->willReturn ([])->shouldBeCalled ();
51
53
$ response ->getHeader ('ETag ' )->willReturn ([])->shouldBeCalled ();
52
54
53
- $ pool ->getItem (' d20f64acc6e70b6079845f2fe357732929550ae1 ' )->shouldBeCalled ()->willReturn ($ item );
55
+ $ pool ->getItem (Argument:: any () )->shouldBeCalled ()->willReturn ($ item );
54
56
$ item ->isHit ()->willReturn (false );
55
57
$ item ->expiresAfter (1060 )->willReturn ($ item )->shouldBeCalled ();
56
58
@@ -70,17 +72,18 @@ function it_caches_responses(CacheItemPoolInterface $pool, CacheItemInterface $i
70
72
$ this ->handleRequest ($ request , $ next , function () {});
71
73
}
72
74
73
- function it_doesnt_store_failed_responses (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , ResponseInterface $ response )
75
+ function it_doesnt_store_failed_responses (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , UriInterface $ uri , ResponseInterface $ response )
74
76
{
75
77
$ request ->getMethod ()->willReturn ('GET ' );
76
- $ request ->getUri ()->willReturn ('/ ' );
78
+ $ request ->getUri ()->willReturn ($ uri );
79
+ $ uri ->__toString ()->willReturn ('https://example.com/ ' );
77
80
$ request ->getBody ()->shouldBeCalled ();
78
81
79
82
$ response ->getStatusCode ()->willReturn (400 );
80
83
$ response ->getHeader ('Cache-Control ' )->willReturn ([]);
81
84
$ response ->getHeader ('Expires ' )->willReturn ([]);
82
85
83
- $ pool ->getItem (' d20f64acc6e70b6079845f2fe357732929550ae1 ' )->shouldBeCalled ()->willReturn ($ item );
86
+ $ pool ->getItem (Argument:: any () )->shouldBeCalled ()->willReturn ($ item );
84
87
$ item ->isHit ()->willReturn (false );
85
88
86
89
$ next = function (RequestInterface $ request ) use ($ response ) {
@@ -90,10 +93,11 @@ function it_doesnt_store_failed_responses(CacheItemPoolInterface $pool, CacheIte
90
93
$ this ->handleRequest ($ request , $ next , function () {});
91
94
}
92
95
93
- function it_doesnt_store_post_requests_by_default (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , ResponseInterface $ response )
96
+ function it_doesnt_store_post_requests_by_default (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , UriInterface $ uri , ResponseInterface $ response )
94
97
{
95
98
$ request ->getMethod ()->willReturn ('POST ' );
96
- $ request ->getUri ()->willReturn ('/ ' );
99
+ $ request ->getUri ()->willReturn ($ uri );
100
+ $ uri ->__toString ()->willReturn ('https://example.com/ ' );
97
101
98
102
$ next = function (RequestInterface $ request ) use ($ response ) {
99
103
return new FulfilledPromise ($ response ->getWrappedObject ());
@@ -106,6 +110,7 @@ function it_stores_post_requests_when_allowed(
106
110
CacheItemPoolInterface $ pool ,
107
111
CacheItemInterface $ item ,
108
112
RequestInterface $ request ,
113
+ UriInterface $ uri ,
109
114
ResponseInterface $ response ,
110
115
StreamFactory $ streamFactory ,
111
116
StreamInterface $ stream
@@ -122,7 +127,8 @@ function it_stores_post_requests_when_allowed(
122
127
$ stream ->rewind ()->shouldBeCalled ();
123
128
124
129
$ request ->getMethod ()->willReturn ('POST ' );
125
- $ request ->getUri ()->willReturn ('/post ' );
130
+ $ request ->getUri ()->willReturn ($ uri );
131
+ $ uri ->__toString ()->willReturn ('https://example.com/ ' );
126
132
$ request ->getBody ()->willReturn ($ stream );
127
133
128
134
$ response ->getStatusCode ()->willReturn (200 );
@@ -131,7 +137,7 @@ function it_stores_post_requests_when_allowed(
131
137
$ response ->getHeader ('Expires ' )->willReturn ([])->shouldBeCalled ();
132
138
$ response ->getHeader ('ETag ' )->willReturn ([])->shouldBeCalled ();
133
139
134
- $ pool ->getItem (' e4311a9af932c603b400a54efab21b6d7dea7a90 ' )->shouldBeCalled ()->willReturn ($ item );
140
+ $ pool ->getItem (Argument:: any () )->shouldBeCalled ()->willReturn ($ item );
135
141
$ item ->isHit ()->willReturn (false );
136
142
$ item ->expiresAfter (1060 )->willReturn ($ item )->shouldBeCalled ();
137
143
@@ -171,15 +177,16 @@ function it_does_not_allow_invalid_request_methods(
171
177
->during ('__construct ' , [$ pool , $ streamFactory , ['methods ' => ['GET ' , 'head ' , 'POST ' ]]]);
172
178
}
173
179
174
- function it_calculate_age_from_response (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , ResponseInterface $ response , StreamInterface $ stream )
180
+ function it_calculate_age_from_response (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , UriInterface $ uri , ResponseInterface $ response , StreamInterface $ stream )
175
181
{
176
182
$ httpBody = 'body ' ;
177
183
$ stream ->__toString ()->willReturn ($ httpBody );
178
184
$ stream ->isSeekable ()->willReturn (true );
179
185
$ stream ->rewind ()->shouldBeCalled ();
180
186
181
187
$ request ->getMethod ()->willReturn ('GET ' );
182
- $ request ->getUri ()->willReturn ('/ ' );
188
+ $ request ->getUri ()->willReturn ($ uri );
189
+ $ uri ->__toString ()->willReturn ('https://example.com/ ' );
183
190
$ request ->getBody ()->shouldBeCalled ();
184
191
185
192
$ response ->getStatusCode ()->willReturn (200 );
@@ -189,7 +196,7 @@ function it_calculate_age_from_response(CacheItemPoolInterface $pool, CacheItemI
189
196
$ response ->getHeader ('Expires ' )->willReturn ([]);
190
197
$ response ->getHeader ('ETag ' )->willReturn ([]);
191
198
192
- $ pool ->getItem (' d20f64acc6e70b6079845f2fe357732929550ae1 ' )->shouldBeCalled ()->willReturn ($ item );
199
+ $ pool ->getItem (Argument:: any () )->shouldBeCalled ()->willReturn ($ item );
193
200
$ item ->isHit ()->willReturn (false );
194
201
195
202
$ item ->set ($ this ->getCacheItemMatcher ([
@@ -210,7 +217,7 @@ function it_calculate_age_from_response(CacheItemPoolInterface $pool, CacheItemI
210
217
$ this ->handleRequest ($ request , $ next , function () {});
211
218
}
212
219
213
- function it_saves_etag (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , ResponseInterface $ response , StreamInterface $ stream )
220
+ function it_saves_etag (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , UriInterface $ uri , ResponseInterface $ response , StreamInterface $ stream )
214
221
{
215
222
$ httpBody = 'body ' ;
216
223
$ stream ->__toString ()->willReturn ($ httpBody );
@@ -219,14 +226,15 @@ function it_saves_etag(CacheItemPoolInterface $pool, CacheItemInterface $item, R
219
226
$ request ->getBody ()->shouldBeCalled ();
220
227
221
228
$ request ->getMethod ()->willReturn ('GET ' );
222
- $ request ->getUri ()->willReturn ('/ ' );
229
+ $ request ->getUri ()->willReturn ($ uri );
230
+ $ uri ->__toString ()->willReturn ('https://example.com/ ' );
223
231
$ response ->getStatusCode ()->willReturn (200 );
224
232
$ response ->getBody ()->willReturn ($ stream );
225
233
$ response ->getHeader ('Cache-Control ' )->willReturn ([]);
226
234
$ response ->getHeader ('Expires ' )->willReturn ([]);
227
235
$ response ->getHeader ('ETag ' )->willReturn (['foo_etag ' ]);
228
236
229
- $ pool ->getItem (' d20f64acc6e70b6079845f2fe357732929550ae1 ' )->shouldBeCalled ()->willReturn ($ item );
237
+ $ pool ->getItem (Argument:: any () )->shouldBeCalled ()->willReturn ($ item );
230
238
$ item ->isHit ()->willReturn (false );
231
239
$ item ->expiresAfter (1060 )->willReturn ($ item );
232
240
@@ -246,20 +254,21 @@ function it_saves_etag(CacheItemPoolInterface $pool, CacheItemInterface $item, R
246
254
$ this ->handleRequest ($ request , $ next , function () {});
247
255
}
248
256
249
- function it_adds_etag_and_modfied_since_to_request (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , ResponseInterface $ response , StreamInterface $ stream )
257
+ function it_adds_etag_and_modfied_since_to_request (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , UriInterface $ uri , ResponseInterface $ response , StreamInterface $ stream )
250
258
{
251
259
$ httpBody = 'body ' ;
252
260
253
261
$ request ->getMethod ()->willReturn ('GET ' );
254
- $ request ->getUri ()->willReturn ('/ ' );
262
+ $ request ->getUri ()->willReturn ($ uri );
263
+ $ uri ->__toString ()->willReturn ('https://example.com/ ' );
255
264
$ request ->getBody ()->shouldBeCalled ();
256
265
257
266
$ request ->withHeader ('If-Modified-Since ' , 'Thursday, 01-Jan-70 01:18:31 GMT ' )->shouldBeCalled ()->willReturn ($ request );
258
267
$ request ->withHeader ('If-None-Match ' , 'foo_etag ' )->shouldBeCalled ()->willReturn ($ request );
259
268
260
269
$ response ->getStatusCode ()->willReturn (304 );
261
270
262
- $ pool ->getItem (' d20f64acc6e70b6079845f2fe357732929550ae1 ' )->shouldBeCalled ()->willReturn ($ item );
271
+ $ pool ->getItem (Argument:: any () )->shouldBeCalled ()->willReturn ($ item );
263
272
$ item ->isHit ()->willReturn (true , false );
264
273
$ item ->get ()->willReturn ([
265
274
'response ' => $ response ,
@@ -276,15 +285,16 @@ function it_adds_etag_and_modfied_since_to_request(CacheItemPoolInterface $pool,
276
285
$ this ->handleRequest ($ request , $ next , function () {});
277
286
}
278
287
279
- function it_servces_a_cached_response (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , ResponseInterface $ response , StreamInterface $ stream , StreamFactory $ streamFactory )
288
+ function it_servces_a_cached_response (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , UriInterface $ uri , ResponseInterface $ response , StreamInterface $ stream , StreamFactory $ streamFactory )
280
289
{
281
290
$ httpBody = 'body ' ;
282
291
283
292
$ request ->getMethod ()->willReturn ('GET ' );
284
- $ request ->getUri ()->willReturn ('/ ' );
293
+ $ request ->getUri ()->willReturn ($ uri );
294
+ $ uri ->__toString ()->willReturn ('https://example.com/ ' );
285
295
$ request ->getBody ()->shouldBeCalled ();
286
296
287
- $ pool ->getItem (' d20f64acc6e70b6079845f2fe357732929550ae1 ' )->shouldBeCalled ()->willReturn ($ item );
297
+ $ pool ->getItem (Argument:: any () )->shouldBeCalled ()->willReturn ($ item );
288
298
$ item ->isHit ()->willReturn (true );
289
299
$ item ->get ()->willReturn ([
290
300
'response ' => $ response ,
@@ -305,12 +315,13 @@ function it_servces_a_cached_response(CacheItemPoolInterface $pool, CacheItemInt
305
315
$ this ->handleRequest ($ request , $ next , function () {});
306
316
}
307
317
308
- function it_serves_and_resaved_expired_response (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , ResponseInterface $ response , StreamInterface $ stream , StreamFactory $ streamFactory )
318
+ function it_serves_and_resaved_expired_response (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , UriInterface $ uri , ResponseInterface $ response , StreamInterface $ stream , StreamFactory $ streamFactory )
309
319
{
310
320
$ httpBody = 'body ' ;
311
321
312
322
$ request ->getMethod ()->willReturn ('GET ' );
313
- $ request ->getUri ()->willReturn ('/ ' );
323
+ $ request ->getUri ()->willReturn ($ uri );
324
+ $ uri ->__toString ()->willReturn ('https://example.com/ ' );
314
325
$ request ->getBody ()->shouldBeCalled ();
315
326
316
327
$ request ->withHeader (Argument::any (), Argument::any ())->willReturn ($ request );
@@ -323,7 +334,7 @@ function it_serves_and_resaved_expired_response(CacheItemPoolInterface $pool, Ca
323
334
// Make sure we add back the body
324
335
$ response ->withBody ($ stream )->willReturn ($ response )->shouldBeCalled ();
325
336
326
- $ pool ->getItem (' d20f64acc6e70b6079845f2fe357732929550ae1 ' )->shouldBeCalled ()->willReturn ($ item );
337
+ $ pool ->getItem (Argument:: any () )->shouldBeCalled ()->willReturn ($ item );
327
338
$ item ->isHit ()->willReturn (true , true );
328
339
$ item ->expiresAfter (1060 )->willReturn ($ item )->shouldBeCalled ();
329
340
$ item ->get ()->willReturn ([
@@ -356,6 +367,7 @@ function it_caches_private_responses_when_allowed(
356
367
CacheItemPoolInterface $ pool ,
357
368
CacheItemInterface $ item ,
358
369
RequestInterface $ request ,
370
+ UriInterface $ uri ,
359
371
ResponseInterface $ response ,
360
372
StreamFactory $ streamFactory ,
361
373
StreamInterface $ stream
@@ -371,7 +383,8 @@ function it_caches_private_responses_when_allowed(
371
383
$ stream ->rewind ()->shouldBeCalled ();
372
384
373
385
$ request ->getMethod ()->willReturn ('GET ' );
374
- $ request ->getUri ()->willReturn ('/ ' );
386
+ $ request ->getUri ()->willReturn ($ uri );
387
+ $ uri ->__toString ()->willReturn ('https://example.com/ ' );
375
388
$ request ->getBody ()->shouldBeCalled ();
376
389
377
390
$ response ->getStatusCode ()->willReturn (200 );
@@ -380,7 +393,7 @@ function it_caches_private_responses_when_allowed(
380
393
$ response ->getHeader ('Expires ' )->willReturn ([])->shouldBeCalled ();
381
394
$ response ->getHeader ('ETag ' )->willReturn ([])->shouldBeCalled ();
382
395
383
- $ pool ->getItem (' d20f64acc6e70b6079845f2fe357732929550ae1 ' )->shouldBeCalled ()->willReturn ($ item );
396
+ $ pool ->getItem (Argument:: any () )->shouldBeCalled ()->willReturn ($ item );
384
397
$ item ->isHit ()->willReturn (false );
385
398
$ item ->expiresAfter (1060 )->willReturn ($ item )->shouldBeCalled ();
386
399
@@ -404,29 +417,31 @@ function it_does_not_store_responses_of_requests_to_blacklisted_paths(
404
417
CacheItemPoolInterface $ pool ,
405
418
CacheItemInterface $ item ,
406
419
RequestInterface $ request ,
420
+ UriInterface $ uri ,
407
421
ResponseInterface $ response ,
408
422
StreamFactory $ streamFactory ,
409
423
StreamInterface $ stream
410
424
) {
411
425
$ this ->beConstructedThrough ('clientCache ' , [$ pool , $ streamFactory , [
412
426
'default_ttl ' => 60 ,
413
427
'cache_lifetime ' => 1000 ,
414
- 'blacklisted_paths ' => ['\ /foo ' ]
428
+ 'blacklisted_paths ' => ['@ /foo@ ' ]
415
429
]]);
416
430
417
431
$ httpBody = 'body ' ;
418
432
$ stream ->__toString ()->willReturn ($ httpBody );
419
433
$ stream ->isSeekable ()->willReturn (true );
420
434
421
435
$ request ->getMethod ()->willReturn ('GET ' );
422
- $ request ->getUri ()->willReturn ('/foo ' );
436
+ $ request ->getUri ()->willReturn ($ uri );
437
+ $ uri ->__toString ()->willReturn ('https://example.com/foo ' );
423
438
$ request ->getBody ()->shouldBeCalled ();
424
439
425
440
$ response ->getStatusCode ()->willReturn (200 );
426
441
$ response ->getBody ()->willReturn ($ stream );
427
442
$ response ->getHeader ('Cache-Control ' )->willReturn ([])->shouldBeCalled ();
428
443
429
- $ pool ->getItem (' 231392a16d98e1cf631845c79b7d45f40bab08f3 ' )->shouldBeCalled ()->willReturn ($ item );
444
+ $ pool ->getItem (Argument:: any () )->shouldBeCalled ()->willReturn ($ item );
430
445
$ item ->isHit ()->willReturn (false );
431
446
432
447
$ item ->set ($ this ->getCacheItemMatcher ([
@@ -448,14 +463,15 @@ function it_stores_responses_of_requests_not_in_blacklisted_paths(
448
463
CacheItemPoolInterface $ pool ,
449
464
CacheItemInterface $ item ,
450
465
RequestInterface $ request ,
466
+ UriInterface $ uri ,
451
467
ResponseInterface $ response ,
452
468
StreamFactory $ streamFactory ,
453
469
StreamInterface $ stream
454
470
) {
455
471
$ this ->beConstructedThrough ('clientCache ' , [$ pool , $ streamFactory , [
456
472
'default_ttl ' => 60 ,
457
473
'cache_lifetime ' => 1000 ,
458
- 'blacklisted_paths ' => ['\ /foo ' ]
474
+ 'blacklisted_paths ' => ['@ /foo@ ' ]
459
475
]]);
460
476
461
477
$ httpBody = 'body ' ;
@@ -464,7 +480,8 @@ function it_stores_responses_of_requests_not_in_blacklisted_paths(
464
480
$ stream ->rewind ()->shouldBeCalled ();
465
481
466
482
$ request ->getMethod ()->willReturn ('GET ' );
467
- $ request ->getUri ()->willReturn ('/ ' );
483
+ $ request ->getUri ()->willReturn ($ uri );
484
+ $ uri ->__toString ()->willReturn ('https://example.com/ ' );
468
485
$ request ->getBody ()->shouldBeCalled ();
469
486
470
487
$ response ->getStatusCode ()->willReturn (200 );
@@ -473,7 +490,7 @@ function it_stores_responses_of_requests_not_in_blacklisted_paths(
473
490
$ response ->getHeader ('Expires ' )->willReturn ([])->shouldBeCalled ();
474
491
$ response ->getHeader ('ETag ' )->willReturn ([])->shouldBeCalled ();
475
492
476
- $ pool ->getItem (' d20f64acc6e70b6079845f2fe357732929550ae1 ' )->shouldBeCalled ()->willReturn ($ item );
493
+ $ pool ->getItem (Argument:: any () )->shouldBeCalled ()->willReturn ($ item );
477
494
$ item ->isHit ()->willReturn (false );
478
495
$ item ->expiresAfter (1060 )->willReturn ($ item )->shouldBeCalled ();
479
496
@@ -498,6 +515,7 @@ function it_can_be_initialized_with_custom_cache_key_generator(
498
515
CacheItemInterface $ item ,
499
516
StreamFactory $ streamFactory ,
500
517
RequestInterface $ request ,
518
+ UriInterface $ uri ,
501
519
ResponseInterface $ response ,
502
520
StreamInterface $ stream ,
503
521
SimpleGenerator $ generator
@@ -513,7 +531,8 @@ function it_can_be_initialized_with_custom_cache_key_generator(
513
531
$ streamFactory ->createStream (Argument::any ())->willReturn ($ stream );
514
532
515
533
$ request ->getMethod ()->willReturn ('GET ' );
516
- $ request ->getUri ()->willReturn ('/ ' );
534
+ $ request ->getUri ()->willReturn ($ uri );
535
+ $ uri ->__toString ()->willReturn ('https://example.com/ ' );
517
536
$ response ->withBody (Argument::any ())->willReturn ($ response );
518
537
519
538
$ pool ->getItem (Argument::any ())->shouldBeCalled ()->willReturn ($ item );
0 commit comments