Completed
Pull Request — master (#1)
by Rafał
10:37
created

TenantAwareRouterCompilerPassTest::testNoBundle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 16
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 16
loc 16
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of the Superdesk Web Publisher MultiTenancy Bundle.
4
 *
5
 * Copyright 2016 Sourcefabric z.u. and contributors.
6
 *
7
 * For the full copyright and license information, please see the
8
 * AUTHORS and LICENSE files distributed with this source code.
9
 *
10
 * @copyright 2016 Sourcefabric z.ú.
11
 * @license http://www.superdesk.org/license
12
 */
13
namespace SWP\MultiTenancyBundle\Tests\DependencyInjection\Compiler;
14
15
use SWP\MultiTenancyBundle\DependencyInjection\Compiler\TenantAwareRouterCompilerPass;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
class TenantAwareRouterCompilerPassTest extends \PHPUnit_Framework_TestCase
19
{
20
    private $container;
21
    private $definition;
22
    private $pass;
23
24
    public function setUp()
25
    {
26
        $this->container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
27
        $this->definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')
28
            ->setMethods(['setArguments', 'addMethodCall', 'setMethodCalls'])
29
            ->getMock();
30
31
        $this->pass = new TenantAwareRouterCompilerPass();
32
    }
33
34
    /**
35
     * @covers SWP\MultiTenancyBundle\DependencyInjection\Compiler\TenantAwareRouterCompilerPass::process
36
     */
37
    public function testProcess()
38
    {
39
        $this->container->expects($this->any())
40
            ->method('hasParameter')
41
            ->will($this->returnValueMap([
42
                ['swp_multi_tenancy.backend_type_phpcr', true],
43
                ['cmf_routing.backend_type_phpcr', true],
44
            ]));
45
46
        $this->container->expects($this->once())
47
            ->method('getParameter')
48
            ->with('kernel.bundles')
49
            ->will($this->returnValue(array(
50
                'CmfRoutingBundle' => true,
51
            )));
52
53
        $definition2 = clone $this->definition;
54
55
        $this->container->expects($this->any())
56
            ->method('getDefinition')
57
            ->will($this->returnValueMap([
58
                ['swp_multi_tenancy.tenant_aware_router', $this->definition],
59
                ['cmf_routing.dynamic_router', $definition2],
60
            ]));
61
62
        $this->definition->expects($this->once())
63
            ->method('setMethodCalls')
64
            ->will($this->returnValue($this->definition));
65
66
        $this->definition->expects($this->once())
67
            ->method('setArguments')
68
            ->will($this->returnValue($this->definition));
69
70
        $this->definition->expects($this->once())
71
            ->method('addMethodCall')
72
            ->with(
73
                'setPathBuilder',
74
                [new Reference('swp_multi_tenancy.path_builder')]
75
            );
76
77
        $this->pass->process($this->container);
78
    }
79
80
    /**
81
     * @covers SWP\MultiTenancyBundle\DependencyInjection\Compiler\TenantAwareRouterCompilerPass::process
82
     */
83 View Code Duplication
    public function testProcessCMFBackendDisabled()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
    {
85
        $this->container->expects($this->any())
86
            ->method('hasParameter')
87
            ->will($this->returnValueMap([
88
                ['swp_multi_tenancy.backend_type_phpcr', true],
89
                ['cmf_routing.backend_type_phpcr', false],
90
            ]));
91
92
        $this->assertNull($this->pass->process($this->container));
93
    }
94
95
    /**
96
     * @covers SWP\MultiTenancyBundle\DependencyInjection\Compiler\TenantAwareRouterCompilerPass::process
97
     */
98 View Code Duplication
    public function testProcessWithoutConfig()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
    {
100
        $this->container->expects($this->any())
101
            ->method('hasParameter')
102
            ->will($this->returnValueMap([
103
                ['swp_multi_tenancy.backend_type_phpcr', false],
104
                ['cmf_routing.backend_type_phpcr', false],
105
            ]));
106
107
        $this->assertNull($this->pass->process($this->container));
108
    }
109
110
    /**
111
     * @expectedException Symfony\Component\DependencyInjection\Exception\RuntimeException
112
     */
113 View Code Duplication
    public function testNoBundle()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114
    {
115
        $this->container->expects($this->any())
116
            ->method('hasParameter')
117
            ->will($this->returnValueMap([
118
                ['swp_multi_tenancy.backend_type_phpcr', true],
119
                ['cmf_routing.backend_type_phpcr', true],
120
            ]));
121
122
        $this->container->expects($this->once())
123
            ->method('getParameter')
124
            ->with('kernel.bundles')
125
            ->will($this->returnValue(array()));
126
127
        $this->pass->process($this->container);
128
    }
129
}
130