Skip to content
This repository was archived by the owner on Feb 24, 2023. It is now read-only.

Commit 0fd5fdf

Browse files
committed
Check _cache type for compatibility with Symfony 6.2
1 parent 6bd976c commit 0fd5fdf

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/EventListener/HttpCacheListener.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Sensio\Bundle\FrameworkExtraBundle\EventListener;
1313

14+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
1415
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1516
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
1617
use Symfony\Component\HttpFoundation\Response;
@@ -42,7 +43,8 @@ public function __construct()
4243
public function onKernelController(KernelEvent $event)
4344
{
4445
$request = $event->getRequest();
45-
if (!$configuration = $request->attributes->get('_cache')) {
46+
$configuration = $request->attributes->get('_cache');
47+
if (!$configuration instanceof Cache) {
4648
return;
4749
}
4850

@@ -81,8 +83,9 @@ public function onKernelController(KernelEvent $event)
8183
public function onKernelResponse(KernelEvent $event)
8284
{
8385
$request = $event->getRequest();
86+
$configuration = $request->attributes->get('_cache');
8487

85-
if (!$configuration = $request->attributes->get('_cache')) {
88+
if (!$configuration instanceof Cache) {
8689
return;
8790
}
8891

tests/EventListener/HttpCacheListenerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ public function testWontReassignResponseWhenNoConfigurationIsPresent()
5050
$this->assertSame($response, $this->event->getResponse());
5151
}
5252

53+
public function testIgnoreUnknownCacheAttribute()
54+
{
55+
$response = $this->event->getResponse();
56+
57+
$this->request->attributes->set('_cache', new \stdClass());
58+
59+
$this->assertNull($this->listener->onKernelResponse($this->event));
60+
$this->assertSame($response, $this->event->getResponse());
61+
}
62+
5363
public function testResponseIsPublicIfSharedMaxAgeSetAndPublicNotOverridden()
5464
{
5565
$request = $this->createRequest(new Cache([

0 commit comments

Comments
 (0)