testProcessWithoutConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 11
loc 11
rs 9.9
cc 1
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
14
namespace SWP\Bundle\MultiTenancyBundle\Tests\DependencyInjection\Compiler;
15
16
use PHPUnit\Framework\TestCase;
17
use SWP\Bundle\MultiTenancyBundle\DependencyInjection\Compiler\TenantAwareRouterCompilerPass;
18
use Symfony\Component\DependencyInjection\Reference;
19
20
class TenantAwareRouterCompilerPassTest extends TestCase
21
{
22
    private $container;
23
24
    private $definition;
25
26
    private $pass;
27
28
    public function setUp()
29
    {
30
        $this->container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
31
            ->getMock();
32
        $this->definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')
33
            ->setMethods(['setArguments', 'addMethodCall', 'setMethodCalls'])
34
            ->getMock();
35
36
        $this->pass = new TenantAwareRouterCompilerPass();
37
    }
38
39
    /**
40
     * @covers \SWP\Bundle\MultiTenancyBundle\DependencyInjection\Compiler\TenantAwareRouterCompilerPass::process
41
     */
42
    public function testProcess()
43
    {
44
        $this->container->expects($this->any())
45
            ->method('hasParameter')
46
            ->will($this->returnValueMap([
47
                ['swp_multi_tenancy.backend_type_phpcr', true],
48
                ['cmf_routing.backend_type_phpcr', true],
49
            ]));
50
51
        $this->container->expects($this->once())
52
            ->method('getParameter')
53
            ->with('kernel.bundles')
54
            ->will($this->returnValue([
55
                'CmfRoutingBundle' => true,
56
            ]));
57
58
        $definition2 = clone $this->definition;
59
60
        $this->container->expects($this->any())
61
            ->method('getDefinition')
62
            ->will($this->returnValueMap([
63
                ['swp_multi_tenancy.tenant_aware_router', $this->definition],
64
                ['cmf_routing.dynamic_router', $definition2],
65
            ]));
66
67
        $this->definition->expects($this->once())
68
            ->method('setMethodCalls')
69
            ->will($this->returnValue($this->definition));
70
71
        $this->definition->expects($this->once())
72
            ->method('setArguments')
73
            ->will($this->returnValue($this->definition));
74
75
        $this->definition->expects($this->once())
76
            ->method('addMethodCall')
77
            ->with(
78
                'setPathBuilder',
79
                [new Reference('swp_multi_tenancy.path_builder')]
80
            );
81
82
        $this->pass->process($this->container);
83
    }
84
85
    /**
86
     * @covers \SWP\Bundle\MultiTenancyBundle\DependencyInjection\Compiler\TenantAwareRouterCompilerPass::process
87
     */
88 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...
89
    {
90
        $this->container->expects($this->any())
91
            ->method('hasParameter')
92
            ->will($this->returnValueMap([
93
                ['swp_multi_tenancy.backend_type_phpcr', true],
94
                ['cmf_routing.backend_type_phpcr', false],
95
            ]));
96
97
        $this->assertNull($this->pass->process($this->container));
98
    }
99
100
    /**
101
     * @covers \SWP\Bundle\MultiTenancyBundle\DependencyInjection\Compiler\TenantAwareRouterCompilerPass::process
102
     */
103 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...
104
    {
105
        $this->container->expects($this->any())
106
            ->method('hasParameter')
107
            ->will($this->returnValueMap([
108
                ['swp_multi_tenancy.backend_type_phpcr', false],
109
                ['cmf_routing.backend_type_phpcr', false],
110
            ]));
111
112
        $this->assertNull($this->pass->process($this->container));
113
    }
114
115
    /**
116
     * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
117
     */
118
    public function testNoBundle()
119
    {
120
        $this->container->expects($this->any())
121
            ->method('hasParameter')
122
            ->will($this->returnValueMap([
123
                ['swp_multi_tenancy.backend_type_phpcr', true],
124
                ['cmf_routing.backend_type_phpcr', true],
125
            ]));
126
127
        $this->container->expects($this->once())
128
            ->method('getParameter')
129
            ->with('kernel.bundles')
130
            ->will($this->returnValue([]));
131
132
        $this->pass->process($this->container);
133
    }
134
}
135