Completed
Pull Request — master (#1)
by Rafał
02:55
created

testProcessPHPCRBackendDisabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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