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

Commit

Permalink
Check _cache type for compatibility with Symfony 6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Oct 29, 2022
1 parent 6bd976c commit 0fd5fdf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/EventListener/HttpCacheListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Sensio\Bundle\FrameworkExtraBundle\EventListener;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -42,7 +43,8 @@ public function __construct()
public function onKernelController(KernelEvent $event)
{
$request = $event->getRequest();
if (!$configuration = $request->attributes->get('_cache')) {
$configuration = $request->attributes->get('_cache');
if (!$configuration instanceof Cache) {
return;
}

Expand Down Expand Up @@ -81,8 +83,9 @@ public function onKernelController(KernelEvent $event)
public function onKernelResponse(KernelEvent $event)
{
$request = $event->getRequest();
$configuration = $request->attributes->get('_cache');

if (!$configuration = $request->attributes->get('_cache')) {
if (!$configuration instanceof Cache) {
return;
}

Expand Down
10 changes: 10 additions & 0 deletions tests/EventListener/HttpCacheListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ public function testWontReassignResponseWhenNoConfigurationIsPresent()
$this->assertSame($response, $this->event->getResponse());
}

public function testIgnoreUnknownCacheAttribute()
{
$response = $this->event->getResponse();

$this->request->attributes->set('_cache', new \stdClass());

$this->assertNull($this->listener->onKernelResponse($this->event));
$this->assertSame($response, $this->event->getResponse());
}

public function testResponseIsPublicIfSharedMaxAgeSetAndPublicNotOverridden()
{
$request = $this->createRequest(new Cache([
Expand Down

0 comments on commit 0fd5fdf

Please sign in to comment.