@@ -332,34 +332,36 @@ public function testLookupWithEmptyCache()
332332 public function testLookupWithVaryResponse ()
333333 {
334334 $ request = Request::create ('https://foobar.com/ ' );
335- $ response = new Response ('hello world ' , 200 , ['Vary ' => 'Foobar ' , 'Foobar ' => 'whatever ' ]);
335+ $ request ->headers ->set ('Foobar ' , 'whatever ' );
336+ $ response = new Response ('hello world ' , 200 , ['Vary ' => 'Foobar ' ]);
336337
337338 $ this ->store ->write ($ request , $ response );
338339
340+ $ request = Request::create ('https://foobar.com/ ' );
339341 $ result = $ this ->store ->lookup ($ request );
340-
341342 $ this ->assertNull ($ result );
342343
343344 $ request = Request::create ('https://foobar.com/ ' );
344345 $ request ->headers ->set ('Foobar ' , 'whatever ' );
345-
346346 $ result = $ this ->store ->lookup ($ request );
347-
348347 $ this ->assertSame (200 , $ result ->getStatusCode ());
349348 $ this ->assertSame ('hello world ' , $ result ->getContent ());
350349 $ this ->assertSame ('Foobar ' , $ result ->headers ->get ('Vary ' ));
351- $ this ->assertSame ('whatever ' , $ result ->headers ->get ('Foobar ' ));
352350 }
353351
354352 public function testLookupWithMultipleVaryResponse ()
355353 {
356- $ request = Request::create ('https://foobar.com/ ' );
357- $ response1 = new Response ('should be whatever 1 ' , 200 , ['Vary ' => 'Foobar ' , 'Foobar ' => 'whatever1 ' ]);
358- $ response2 = new Response ('should be whatever 2 ' , 200 , ['Vary ' => 'Foobar ' , 'Foobar ' => 'whatever2 ' ]);
354+ $ jsonRequest = Request::create ('https://foobar.com/ ' );
355+ $ jsonRequest ->headers ->set ('Accept ' , 'application/json ' );
356+ $ htmlRequest = Request::create ('https://foobar.com/ ' );
357+ $ htmlRequest ->headers ->set ('Accept ' , 'text/html ' );
358+
359+ $ jsonResponse = new Response ('{} ' , 200 , ['Vary ' => 'Accept ' , 'Content-Type ' => 'application/json ' ]);
360+ $ htmlResponse = new Response ('<html></html> ' , 200 , ['Vary ' => 'Accept ' , 'Content-Type ' => 'text/html ' ]);
359361
360362 // Fill cache
361- $ this ->store ->write ($ request , $ response1 );
362- $ this ->store ->write ($ request , $ response2 );
363+ $ this ->store ->write ($ jsonRequest , $ jsonResponse );
364+ $ this ->store ->write ($ htmlRequest , $ htmlResponse );
363365
364366 // Should return null because no header provided
365367 $ request = Request::create ('https://foobar.com/ ' );
@@ -368,27 +370,27 @@ public function testLookupWithMultipleVaryResponse()
368370
369371 // Should return null because header provided but non matching content
370372 $ request = Request::create ('https://foobar.com/ ' );
371- $ request ->headers ->set ('Foobar ' , 'whatever3 ' );
373+ $ request ->headers ->set ('Accept ' , 'application/xml ' );
372374 $ result = $ this ->store ->lookup ($ request );
373375 $ this ->assertNull ($ result );
374376
375- // Should return $response1
377+ // Should return a JSON response
376378 $ request = Request::create ('https://foobar.com/ ' );
377- $ request ->headers ->set ('Foobar ' , 'whatever1 ' );
379+ $ request ->headers ->set ('Accept ' , 'application/json ' );
378380 $ result = $ this ->store ->lookup ($ request );
379381 $ this ->assertSame (200 , $ result ->getStatusCode ());
380- $ this ->assertSame ('should be whatever 1 ' , $ result ->getContent ());
381- $ this ->assertSame ('Foobar ' , $ result ->headers ->get ('Vary ' ));
382- $ this ->assertSame ('whatever1 ' , $ result ->headers ->get ('Foobar ' ));
382+ $ this ->assertSame ('{} ' , $ result ->getContent ());
383+ $ this ->assertSame ('Accept ' , $ result ->headers ->get ('Vary ' ));
384+ $ this ->assertSame ('application/json ' , $ result ->headers ->get ('Content-Type ' ));
383385
384- // Should return $response2
386+ // Should return an HTML response
385387 $ request = Request::create ('https://foobar.com/ ' );
386- $ request ->headers ->set ('Foobar ' , 'whatever2 ' );
388+ $ request ->headers ->set ('Accept ' , 'text/html ' );
387389 $ result = $ this ->store ->lookup ($ request );
388390 $ this ->assertSame (200 , $ result ->getStatusCode ());
389- $ this ->assertSame ('should be whatever 2 ' , $ result ->getContent ());
390- $ this ->assertSame ('Foobar ' , $ result ->headers ->get ('Vary ' ));
391- $ this ->assertSame ('whatever2 ' , $ result ->headers ->get ('Foobar ' ));
391+ $ this ->assertSame ('<html></html> ' , $ result ->getContent ());
392+ $ this ->assertSame ('Accept ' , $ result ->headers ->get ('Vary ' ));
393+ $ this ->assertSame ('text/html ' , $ result ->headers ->get ('Content-Type ' ));
392394 }
393395
394396 public function testInvalidate ()
0 commit comments