1414use FOS \HttpCache \SymfonyCache \CacheEvent ;
1515use FOS \HttpCache \SymfonyCache \CacheInvalidationInterface ;
1616use FOS \HttpCache \SymfonyCache \CustomTtlListener ;
17+ use Mockery \MockInterface ;
1718use Symfony \Component \HttpFoundation \Request ;
1819use Symfony \Component \HttpFoundation \Response ;
1920
2021class CustomTtlListenerTest extends \PHPUnit_Framework_TestCase
2122{
2223 /**
23- * @var CacheInvalidationInterface|\PHPUnit_Framework_MockObject_MockObject
24+ * @var CacheInvalidationInterface|MockInterface
2425 */
2526 private $ kernel ;
2627
@@ -65,6 +66,23 @@ public function testCustomTtlNoSmaxage()
6566 $ this ->assertSame ('false ' , $ response ->headers ->get (CustomTtlListener::SMAXAGE_BACKUP ));
6667 }
6768
69+ public function testNoCustomTtl ()
70+ {
71+ $ ttlListener = new CustomTtlListener ();
72+ $ request = Request::create ('http://example.com/foo ' , 'GET ' );
73+ $ response = new Response ('' , 200 , array (
74+ 'Cache-Control ' => 'max-age=30, s-maxage=33 ' ,
75+ ));
76+ $ event = new CacheEvent ($ this ->kernel , $ request , $ response );
77+
78+ $ ttlListener ->useCustomTtl ($ event );
79+ $ response = $ event ->getResponse ();
80+
81+ $ this ->assertInstanceOf (Response::class, $ response );
82+ $ this ->assertSame ('33 ' , $ response ->headers ->getCacheControlDirective ('s-maxage ' ));
83+ $ this ->assertFalse ($ response ->headers ->has (CustomTtlListener::SMAXAGE_BACKUP ));
84+ }
85+
6886 public function testCleanup ()
6987 {
7088 $ ttlListener = new CustomTtlListener ();
@@ -92,7 +110,7 @@ public function testCleanupNoSmaxage()
92110 $ request = Request::create ('http://example.com/foo ' , 'GET ' );
93111 $ response = new Response ('' , 200 , array (
94112 'X-Reverse-Proxy-TTL ' => '120 ' ,
95- 'Cache-Control ' => 's-maxage: 120, max-age: 30 ' ,
113+ 'Cache-Control ' => 's-maxage= 120, max-age= 30 ' ,
96114 CustomTtlListener::SMAXAGE_BACKUP => 'false ' ,
97115 ));
98116 $ event = new CacheEvent ($ this ->kernel , $ request , $ response );
@@ -105,4 +123,22 @@ public function testCleanupNoSmaxage()
105123 $ this ->assertFalse ($ response ->headers ->has ('X-Reverse-Proxy-TTL ' ));
106124 $ this ->assertFalse ($ response ->headers ->has (CustomTtlListener::SMAXAGE_BACKUP ));
107125 }
126+
127+ public function testCleanupNoCustomTtl ()
128+ {
129+ $ ttlListener = new CustomTtlListener ();
130+ $ request = Request::create ('http://example.com/foo ' , 'GET ' );
131+ $ response = new Response ('' , 200 , array (
132+ 'Cache-Control ' => 's-maxage=60, max-age=30 ' ,
133+ ));
134+ $ event = new CacheEvent ($ this ->kernel , $ request , $ response );
135+
136+ $ ttlListener ->cleanResponse ($ event );
137+ $ response = $ event ->getResponse ();
138+
139+ $ this ->assertInstanceOf (Response::class, $ response );
140+ $ this ->assertSame ('60 ' , $ response ->headers ->getCacheControlDirective ('s-maxage ' ));
141+ $ this ->assertFalse ($ response ->headers ->has ('X-Reverse-Proxy-TTL ' ));
142+ $ this ->assertFalse ($ response ->headers ->has (CustomTtlListener::SMAXAGE_BACKUP ));
143+ }
108144}
0 commit comments