testProcess()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 9.248
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
15
namespace SWP\Bundle\MultiTenancyBundle\Tests\DependencyInjection\Compiler;
16
17
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
18
use SWP\Bundle\MultiTenancyBundle\DependencyInjection\Compiler\ConfigurePrefixCandidatesCompilerPass;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Definition;
21
use Symfony\Component\DependencyInjection\Reference;
22
23
class ConfigurePrefixCandidatesCompilerPassTest extends AbstractCompilerPassTestCase
24
{
25
    /**
26
     * @param ContainerBuilder $container
27
     */
28
    protected function registerCompilerPass(ContainerBuilder $container)
29
    {
30
        $container->addCompilerPass(new ConfigurePrefixCandidatesCompilerPass());
31
    }
32
33
    /**
34
     * @covers \SWP\Bundle\MultiTenancyBundle\DependencyInjection\Compiler\ConfigurePrefixCandidatesCompilerPass::process
35
     */
36
    public function testProcessPHPCRBackendDisabled()
37
    {
38
        $this->container->setParameter('cmf_routing.backend_type_phpcr', true);
39
40
        $this->compile();
41
42
        $this->assertContainerBuilderHasParameter('cmf_routing.backend_type_phpcr');
43
    }
44
45
    /**
46
     * @covers \SWP\Bundle\MultiTenancyBundle\DependencyInjection\Compiler\ConfigurePrefixCandidatesCompilerPass::process
47
     */
48
    public function testProcessCMFBackendDisabled()
49
    {
50
        $this->container->setParameter('swp_multi_tenancy.backend_type_phpcr', true);
51
52
        $this->compile();
53
54
        $this->assertContainerBuilderHasParameter('swp_multi_tenancy.backend_type_phpcr');
55
    }
56
57
    /**
58
     * @covers \SWP\Bundle\MultiTenancyBundle\DependencyInjection\Compiler\ConfigurePrefixCandidatesCompilerPass::process
59
     */
60
    public function testProcess()
61
    {
62
        $this->container->setParameter('swp_multi_tenancy.backend_type_phpcr', true);
63
        $this->container->setParameter('cmf_routing.backend_type_phpcr', true);
64
        $this->container->setParameter('kernel.bundles', [
65
            'CmfRoutingBundle' => true,
66
        ]);
67
        $this->container->setParameter('swp_multi_tenancy.persistence.phpcr.route_basepaths', ['routes']);
68
        $this->container->setParameter(
69
            'swp_multi_tenancy.prefix_candidates.class',
70
            'SWP\Bundle\MultiTenancyBundle\Doctrine\PHPCR\PrefixCandidates'
71
        );
72
73
        $collectingService = new Definition();
74
        $this->setDefinition('cmf_routing.phpcr_candidates_prefix', $collectingService);
75
76
        $pathBuilderService = new Definition();
77
        $this->setDefinition('swp_multi_tenancy.path_builder', $pathBuilderService);
78
79
        $this->compile();
80
81
        $this->assertContainerBuilderHasService(
82
            'cmf_routing.phpcr_candidates_prefix',
83
            'SWP\Bundle\MultiTenancyBundle\Doctrine\PHPCR\PrefixCandidates'
84
        );
85
86
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
87
            'cmf_routing.phpcr_candidates_prefix',
88
            'setPathBuilder',
89
            [
90
                new Reference('swp_multi_tenancy.path_builder'),
91
            ]
92
        );
93
94
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
95
            'cmf_routing.phpcr_candidates_prefix',
96
            'setRoutePathsNames',
97
            [
98
                $this->container->getParameter('swp_multi_tenancy.persistence.phpcr.route_basepaths'),
99
            ]
100
        );
101
    }
102
103
    /**
104
     * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
105
     */
106
    public function testProcessWhenNoBundle()
107
    {
108
        $this->container->setParameter('swp_multi_tenancy.backend_type_phpcr', true);
109
        $this->container->setParameter('cmf_routing.backend_type_phpcr', true);
110
111
        $this->container->setParameter('kernel.bundles', []);
112
113
        $this->compile();
114
115
        $this->assertContainerBuilderHasParameter('swp_multi_tenancy.backend_type_phpcr');
116
    }
117
}
118