Skip to content

Commit 8a9103d

Browse files
committed
Store must implement the new ClearableInterface
1 parent 4fa32cc commit 8a9103d

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"symfony/http-kernel": "^3.4 || ^4.3 || ^5.0"
4040
},
4141
"conflict": {
42-
"toflar/psr6-symfony-http-cache-store": "<2.2.0"
42+
"toflar/psr6-symfony-http-cache-store": "<2.2.1"
4343
},
4444
"suggest": {
4545
"friendsofsymfony/http-cache-bundle": "For integration with the Symfony framework",

src/SymfonyCache/PurgeListener.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\HttpFoundation\Response;
1515
use Symfony\Component\OptionsResolver\OptionsResolver;
16+
use Toflar\Psr6HttpCacheStore\ClearableInterface;
1617
use Toflar\Psr6HttpCacheStore\Psr6StoreInterface;
1718

1819
/**
@@ -98,9 +99,9 @@ public function handlePurge(CacheEvent $event)
9899

99100
// Purge whole cache
100101
if ($request->headers->has($this->clearCacheHeader)) {
101-
if (!$store instanceof Psr6StoreInterface) {
102+
if (!$store instanceof ClearableInterface) {
102103
$response->setStatusCode(400);
103-
$response->setContent('Store must be an instance of '.Psr6StoreInterface::class.'. Please check your proxy configuration.');
104+
$response->setContent('Store must be an instance of '.ClearableInterface::class.'. Please check your proxy configuration.');
104105
$event->setResponse($response);
105106

106107
return;

tests/Unit/SymfonyCache/PurgeListenerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ public function testClearCache()
8888
$this->assertSame(200, $response->getStatusCode());
8989
}
9090

91+
public function testClearCacheWithoutPsr6Store()
92+
{
93+
/** @var StoreInterface $store */
94+
$store = \Mockery::mock(StoreInterface::class);
95+
$kernel = $this->getKernelMock($store);
96+
$purgeListener = new PurgeListener();
97+
$request = Request::create('http://example.com/', 'PURGE');
98+
$request->headers->set('Clear-Cache', 'true');
99+
$event = new CacheEvent($kernel, $request);
100+
$purgeListener->handlePurge($event);
101+
$response = $event->getResponse();
102+
$this->assertInstanceOf(Response::class, $response);
103+
$this->assertSame(400, $response->getStatusCode());
104+
$this->assertSame('Store must be an instance of Toflar\Psr6HttpCacheStore\ClearableInterface. Please check your proxy configuration.', $response->getContent());
105+
}
106+
91107
public function testPurgeAllowedMiss()
92108
{
93109
/** @var StoreInterface $store */

0 commit comments

Comments
 (0)