@@ -203,7 +203,7 @@ public function testOnKernelResponse()
203203
204204 public function testOnKernelResponseSetsNoAutoCacheHeader ()
205205 {
206- if (4 > Kernel::MAJOR_VERSION || 1 > Kernel:: MINOR_VERSION ) {
206+ if (\version_compare ( ' 4.1 ' , Kernel::VERSION , ' > ' ) ) {
207207 $ this ->markTestSkipped ('Test only relevant for Symfony 4.1 and up ' );
208208 }
209209
@@ -225,9 +225,37 @@ public function testOnKernelResponseSetsNoAutoCacheHeader()
225225 $ this ->assertEquals (1 , $ event ->getResponse ()->headers ->get (AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER ));
226226 }
227227
228+ public function testOnKernelResponseDoesNotSetNoAutoCacheHeaderWhenNoSessionListener ()
229+ {
230+ if (\version_compare ('4.1 ' , Kernel::VERSION , '> ' )) {
231+ $ this ->markTestSkipped ('Test only relevant for Symfony 4.1 and up ' );
232+ }
233+
234+ $ request = new Request ();
235+ $ request ->setMethod ('HEAD ' );
236+ $ request ->headers ->set ('X-User-Context-Hash ' , 'hash ' );
237+
238+ $ hashGenerator = \Mockery::mock (HashGenerator::class);
239+
240+ $ userContextListener = new UserContextListener (
241+ $ this ->getRequestMatcher ($ request , false ),
242+ $ hashGenerator ,
243+ null ,
244+ null ,
245+ [],
246+ false
247+ );
248+ $ event = $ this ->getKernelResponseEvent ($ request );
249+
250+ $ userContextListener ->onKernelResponse ($ event );
251+
252+ $ this ->assertContains ('X-User-Context-Hash ' , $ event ->getResponse ()->headers ->get ('Vary ' ));
253+ $ this ->assertFalse ($ event ->getResponse ()->headers ->has (AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER ));
254+ }
255+
228256 public function testOnKernelResponseSetsNoAutoCacheHeaderWhenCustomHeader ()
229257 {
230- if (4 > Kernel::MAJOR_VERSION || 1 > Kernel:: MINOR_VERSION ) {
258+ if (\version_compare ( ' 4.1 ' , Kernel::VERSION , ' > ' ) ) {
231259 $ this ->markTestSkipped ('Test only relevant for Symfony 4.1 and up ' );
232260 }
233261
@@ -250,7 +278,7 @@ public function testOnKernelResponseSetsNoAutoCacheHeaderWhenCustomHeader()
250278
251279 public function testOnKernelResponseSetsNoAutoCacheHeaderWhenCustomHeaderAndNoAddVaryOnHash ()
252280 {
253- if (4 > Kernel::MAJOR_VERSION || 1 > Kernel:: MINOR_VERSION ) {
281+ if (\version_compare ( ' 4.1 ' , Kernel::VERSION , ' > ' ) ) {
254282 $ this ->markTestSkipped ('Test only relevant for Symfony 4.1 and up ' );
255283 }
256284
@@ -278,7 +306,7 @@ public function testOnKernelResponseSetsNoAutoCacheHeaderWhenCustomHeaderAndNoAd
278306
279307 public function testOnKernelResponseDoesNotSetNoAutoCacheHeaderWhenNoCustomHeaderAndNoAddVaryOnHash ()
280308 {
281- if (4 > Kernel::MAJOR_VERSION || 1 > Kernel:: MINOR_VERSION ) {
309+ if (\version_compare ( ' 4.1 ' , Kernel::VERSION , ' > ' ) ) {
282310 $ this ->markTestSkipped ('Test only relevant for Symfony 4.1 and up ' );
283311 }
284312
0 commit comments