|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Superdesk Web Publisher MultiTenancy Bundle. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright 2016 Sourcefabric z.u. and contributors. |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please see the |
|
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @copyright 2016 Sourcefabric z.ú. |
|
12
|
|
|
* @license http://www.superdesk.org/license |
|
13
|
|
|
*/ |
|
14
|
|
|
namespace SWP\MultiTenancyBundle\Tests\DependencyInjection\Compiler; |
|
15
|
|
|
|
|
16
|
|
|
use SWP\MultiTenancyBundle\DependencyInjection\Compiler\ConfigurePrefixCandidatesCompilerPass; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
18
|
|
|
|
|
19
|
|
|
class ConfigurePrefixCandidatesCompilerPassTest extends \PHPUnit_Framework_TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
private $container; |
|
22
|
|
|
private $definition; |
|
23
|
|
|
private $pass; |
|
24
|
|
|
|
|
25
|
|
|
public function setUp() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); |
|
28
|
|
|
$this->definition = $this->getMock('Symfony\Component\DependencyInjection\Definition'); |
|
29
|
|
|
$this->pass = new ConfigurePrefixCandidatesCompilerPass(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @covers SWP\MultiTenancyBundle\DependencyInjection\Compiler\ConfigurePrefixCandidatesCompilerPass::process |
|
34
|
|
|
*/ |
|
35
|
|
|
public function testProcess() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->container->expects($this->any()) |
|
38
|
|
|
->method('hasParameter') |
|
39
|
|
|
->will($this->returnValueMap([ |
|
40
|
|
|
['swp_multi_tenancy.backend_type_phpcr', true], |
|
41
|
|
|
['cmf_routing.backend_type_phpcr', true], |
|
42
|
|
|
])); |
|
43
|
|
|
|
|
44
|
|
|
$this->container->expects($this->once()) |
|
45
|
|
|
->method('getParameter') |
|
46
|
|
|
->with('kernel.bundles') |
|
47
|
|
|
->will($this->returnValue(array( |
|
48
|
|
|
'CmfRoutingBundle' => true, |
|
49
|
|
|
))); |
|
50
|
|
|
|
|
51
|
|
|
$this->container->expects($this->once()) |
|
52
|
|
|
->method('getDefinition') |
|
53
|
|
|
->with('cmf_routing.phpcr_candidates_prefix') |
|
54
|
|
|
->will($this->returnValue($this->definition)); |
|
55
|
|
|
|
|
56
|
|
|
$this->definition->expects($this->once()) |
|
57
|
|
|
->method('setConfigurator') |
|
58
|
|
|
->with([ |
|
59
|
|
|
new Reference('swp_multi_tenancy.candidates_configurator'), |
|
60
|
|
|
'configure', |
|
61
|
|
|
]); |
|
62
|
|
|
|
|
63
|
|
|
$this->pass->process($this->container); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @covers SWP\MultiTenancyBundle\DependencyInjection\Compiler\ConfigurePrefixCandidatesCompilerPass::process |
|
68
|
|
|
*/ |
|
69
|
|
View Code Duplication |
public function testProcessPHPCRBackendDisabled() |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
|
|
$this->container->expects($this->any()) |
|
72
|
|
|
->method('hasParameter') |
|
73
|
|
|
->will($this->returnValueMap([ |
|
74
|
|
|
['swp_multi_tenancy.backend_type_phpcr', false], |
|
75
|
|
|
['cmf_routing.backend_type_phpcr', true], |
|
76
|
|
|
])); |
|
77
|
|
|
|
|
78
|
|
|
$this->assertNull($this->pass->process($this->container)); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @covers SWP\MultiTenancyBundle\DependencyInjection\Compiler\ConfigurePrefixCandidatesCompilerPass::process |
|
83
|
|
|
*/ |
|
84
|
|
View Code Duplication |
public function testProcessCMFBackendDisabled() |
|
|
|
|
|
|
85
|
|
|
{ |
|
86
|
|
|
$this->container->expects($this->any()) |
|
87
|
|
|
->method('hasParameter') |
|
88
|
|
|
->will($this->returnValueMap([ |
|
89
|
|
|
['swp_multi_tenancy.backend_type_phpcr', true], |
|
90
|
|
|
['cmf_routing.backend_type_phpcr', false], |
|
91
|
|
|
])); |
|
92
|
|
|
|
|
93
|
|
|
$this->assertNull($this->pass->process($this->container)); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @covers SWP\MultiTenancyBundle\DependencyInjection\Compiler\ConfigurePrefixCandidatesCompilerPass::process |
|
98
|
|
|
*/ |
|
99
|
|
View Code Duplication |
public function testProcessWithoutConfig() |
|
|
|
|
|
|
100
|
|
|
{ |
|
101
|
|
|
$this->container->expects($this->any()) |
|
102
|
|
|
->method('hasParameter') |
|
103
|
|
|
->will($this->returnValueMap([ |
|
104
|
|
|
['swp_multi_tenancy.backend_type_phpcr', false], |
|
105
|
|
|
['cmf_routing.backend_type_phpcr', false], |
|
106
|
|
|
])); |
|
107
|
|
|
|
|
108
|
|
|
$this->assertNull($this->pass->process($this->container)); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @expectedException Symfony\Component\DependencyInjection\Exception\RuntimeException |
|
113
|
|
|
*/ |
|
114
|
|
View Code Duplication |
public function testNoBundle() |
|
|
|
|
|
|
115
|
|
|
{ |
|
116
|
|
|
$this->container->expects($this->any()) |
|
117
|
|
|
->method('hasParameter') |
|
118
|
|
|
->will($this->returnValueMap([ |
|
119
|
|
|
['swp_multi_tenancy.backend_type_phpcr', true], |
|
120
|
|
|
['cmf_routing.backend_type_phpcr', true], |
|
121
|
|
|
])); |
|
122
|
|
|
|
|
123
|
|
|
$this->container->expects($this->once()) |
|
124
|
|
|
->method('getParameter') |
|
125
|
|
|
->with('kernel.bundles') |
|
126
|
|
|
->will($this->returnValue(array())); |
|
127
|
|
|
|
|
128
|
|
|
$this->pass->process($this->container); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
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.