Completed
Push — 6.7 ( 470b16...7283a5 )
by André
13:35
created

HttpCachePassTest::testProcessPurgeClient()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 3
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the HttpCachePassTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection\Compiler;
10
11
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\HttpCachePass;
12
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Symfony\Component\DependencyInjection\Definition;
15
use Symfony\Component\DependencyInjection\Reference;
16
17
class HttpCachePassTest extends AbstractCompilerPassTestCase
18
{
19
    protected function registerCompilerPass(ContainerBuilder $container)
20
    {
21
        $container->addCompilerPass(new HttpCachePass());
22
    }
23
24
    /**
25
     * @expectedException \InvalidArgumentException
26
     */
27
    public function testProcessVarnishProxyNotRegistered()
28
    {
29
        $this->setDefinition('ezpublish.http_cache.cache_manager', new Definition());
30
        $this->compile();
31
    }
32
33
    public function testProcessCacheManager()
34
    {
35
        $this->setDefinition('ezpublish.http_cache.cache_manager', new Definition('foo', array(true)));
36
        $varnishProxyClient = new Definition();
37
        $this->setDefinition('fos_http_cache.proxy_client.varnish', $varnishProxyClient);
38
        $this->compile();
39
40
        $factoryArray = $varnishProxyClient->getFactory();
41
        $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $factoryArray[0]);
42
        $this->assertEquals('buildProxyClient', $factoryArray[1]);
43
        $this->assertEquals('ezpublish.http_cache.proxy_client.varnish.factory', $factoryArray[0]);
44
        $this->assertTrue($varnishProxyClient->isLazy());
45
46
        $this->assertContainerBuilderHasServiceDefinitionWithArgument(
47
            'ezpublish.http_cache.cache_manager',
48
            0,
49
            new Reference('fos_http_cache.proxy_client.varnish')
50
        );
51
    }
52
53
    public function processPurgeClientProvider()
54
    {
55
        return [
56
            ['local', 'ezpublish.http_cache.purge_client.local'],
57
            ['http', 'ezpublish.http_cache.purge_client.fos'],
58
        ];
59
    }
60
61
    /**
62
     * @dataProvider processPurgeClientProvider
63
     *
64
     * @param string $paramValue
65
     * @param string $expectedServiceAlias
0 ignored issues
show
Bug introduced by
There is no parameter named $expectedServiceAlias. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
66
     * @param \Symfony\Component\DependencyInjection\Definition|null $customService
67
     */
68
    public function testProcessPurgeClient($paramValue, $expectedServiceId, Definition $customService = null)
69
    {
70
        $this->setDefinition('ezpublish.http_cache.purge_client', new Definition());
71
        $this->setParameter('ezpublish.http_cache.purge_type', $paramValue);
72
        if ($customService) {
73
            $this->setDefinition($paramValue, $customService);
74
        }
75
76
        $this->compile();
77
78
        $this->assertContainerBuilderHasAlias('ezpublish.http_cache.purge_client', $expectedServiceId);
79
    }
80
81
    /**
82
     * @expectedException \InvalidArgumentException
83
     */
84
    public function testProcessPurgeClientOnInvalidService()
85
    {
86
        $this->setDefinition('ezpublish.http_cache.purge_client', new Definition());
87
        $this->setParameter('ezpublish.http_cache.purge_type', 'foo');
88
89
        $this->compile();
90
    }
91
}
92