Skip to content

Commit c1f8db4

Browse files
author
Bertrand Dunogier
committed
Fixed KernelPass listeners detection + added specs
1 parent e32fbd0 commit c1f8db4

File tree

2 files changed

+63
-5
lines changed

2 files changed

+63
-5
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace spec\EzSystems\PlatformHttpCacheBundle\DependencyInjection\Compiler;
4+
5+
use EzSystems\PlatformHttpCacheBundle\DependencyInjection\Compiler\KernelPass;
6+
use PhpSpec\ObjectBehavior;
7+
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
use Symfony\Component\DependencyInjection\Definition;
9+
10+
class KernelPassSpec extends ObjectBehavior
11+
{
12+
function let(ContainerBuilder $container)
13+
{
14+
$container->getDefinitions()->willReturn([]);
15+
$container->getAlias('ezpublish.http_cache.purge_client')->willReturn('some_random_id');
16+
}
17+
18+
function it_is_initializable()
19+
{
20+
$this->shouldHaveType(KernelPass::class);
21+
}
22+
23+
function it_disables_the_kernels_httpcache_slots(ContainerBuilder $container)
24+
{
25+
$container->getDefinitions()->willReturn([
26+
'ezpublish.http_cache.witness_service' => new Definition(),
27+
'ezpublish.http_cache.signalslot.some_slot' => new Definition(),
28+
'ezpublish.http_cache.signalslot.some_other_slot' => new Definition(),
29+
'witness_service' => new Definition(),
30+
]);
31+
$container->removeDefinition('ezpublish.http_cache.signalslot.some_slot')->shouldBeCalled();
32+
$container->removeDefinition('ezpublish.http_cache.signalslot.some_other_slot')->shouldBeCalled();
33+
34+
$this->process($container);
35+
}
36+
37+
function it_disables_the_kernels_smartcache_event_listeners(ContainerBuilder $container)
38+
{
39+
$container->getDefinitions()->willReturn([
40+
'ezpublish.cache_clear.content.some_listener' => new Definition(),
41+
'witness_service' => new Definition(),
42+
]);
43+
$container->removeDefinition('ezpublish.cache_clear.content.some_listener')->shouldBeCalled();
44+
45+
$this->process($container);
46+
}
47+
48+
function it_disables_the_kernels_view_cache_response_listener(ContainerBuilder $container)
49+
{
50+
$container->getDefinitions()->willReturn([
51+
'ezpublish.view.cache_response_listener' => new Definition(),
52+
'witness_service' => new Definition(),
53+
]);
54+
$container->removeDefinition('ezpublish.view.cache_response_listener')->shouldBeCalled();
55+
56+
$this->process($container);
57+
}
58+
}

src/DependencyInjection/Compiler/KernelPass.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
use Symfony\Component\DependencyInjection\ContainerBuilder;
1111

1212
/**
13-
*
13+
* Disables some of the http-cache services declared by the kernel so that
14+
* they can be replaced with this bundle's.
1415
*/
1516
class KernelPass implements CompilerPassInterface
1617
{
1718
public function process(ContainerBuilder $container)
1819
{
19-
// slots
2020
foreach ($container->getDefinitions() as $id => $definition) {
2121
if ($this->isSignalSlot($id) ||
2222
$this->isSmartCacheListener($id) ||
23-
$this->isCacheTagListener($id)
23+
$this->isResponseCacheListener($id)
2424
) {
2525
$container->removeDefinition($id);
2626
}
@@ -44,15 +44,15 @@ protected function isSignalSlot($id)
4444
*/
4545
protected function isSmartCacheListener($id)
4646
{
47-
return preg_match('/ezpublish.cache_clear.content.[a-z_]]_listener/', $id);
47+
return preg_match('/^ezpublish\.cache_clear\.content.[a-z_]+_listener/', $id);
4848
}
4949

5050
/**
5151
* @param string $id
5252
*
5353
* @return bool
5454
*/
55-
protected function isCacheTagListener($id)
55+
protected function isResponseCacheListener($id)
5656
{
5757
return $id === 'ezpublish.view.cache_response_listener';
5858
}

0 commit comments

Comments
 (0)