Completed
Push — 3.x ( 4aa5ae...fcf788 )
by Oskar
04:38
created

SonataAdminBundleTest::testBuildWithMakerBundle()   B

Complexity

Conditions 6
Paths 1

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 8.4905
c 0
b 0
f 0
cc 6
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\AdminBundle\Tests;
13
14
use PHPUnit\Framework\TestCase;
15
use Sonata\AdminBundle\DependencyInjection\Compiler\AddDependencyCallsCompilerPass;
16
use Sonata\AdminBundle\DependencyInjection\Compiler\AddFilterTypeCompilerPass;
17
use Sonata\AdminBundle\DependencyInjection\Compiler\AdminMakerCompilerPass;
18
use Sonata\AdminBundle\DependencyInjection\Compiler\ExtensionCompilerPass;
19
use Sonata\AdminBundle\DependencyInjection\Compiler\GlobalVariablesCompilerPass;
20
use Sonata\AdminBundle\SonataAdminBundle;
21
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
22
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
23
use Symfony\Component\DependencyInjection\ContainerBuilder;
24
25
/**
26
 * @author Andrej Hudec <[email protected]>
27
 */
28
class SonataAdminBundleTest extends TestCase
29
{
30
    public function testBuild()
31
    {
32
        $containerBuilder = $this->getMockBuilder(ContainerBuilder::class)
33
            ->setMethods(['addCompilerPass', 'getParameter'])
34
            ->getMock();
35
36
        $containerBuilder->expects($this->exactly(4))
37
            ->method('addCompilerPass')
38
            ->will($this->returnCallback(function (CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
                if ($pass instanceof AddDependencyCallsCompilerPass) {
40
                    return;
41
                }
42
43
                if ($pass instanceof AddFilterTypeCompilerPass) {
44
                    return;
45
                }
46
47
                if ($pass instanceof ExtensionCompilerPass) {
48
                    return;
49
                }
50
51
                if ($pass instanceof GlobalVariablesCompilerPass) {
52
                    return;
53
                }
54
55
                $this->fail(sprintf(
56
                    'CompilerPass is not one of the expected types. Expects "%s", "%s", "%s" or "%s", but got "%s".',
57
                    AddDependencyCallsCompilerPass::class,
58
                    AddFilterTypeCompilerPass::class,
59
                    ExtensionCompilerPass::class,
60
                    GlobalVariablesCompilerPass::class,
61
                    \get_class($pass)
62
                ));
63
            }));
64
65
        $containerBuilder
66
            ->expects($this->once())
67
            ->method('getParameter')
68
            ->with('kernel.bundles')
69
            ->willReturn([]);
70
71
        $bundle = new SonataAdminBundle();
72
        $bundle->build($containerBuilder);
73
    }
74
75
    public function testBuildWithMakerBundle()
76
    {
77
        $containerBuilder = $this->getMockBuilder(ContainerBuilder::class)
78
            ->setMethods(['addCompilerPass', 'getParameter'])
79
            ->getMock();
80
81
        $containerBuilder->expects($this->exactly(5))
82
            ->method('addCompilerPass')
83
            ->will($this->returnCallback(function (CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION) {
84
                if ($pass instanceof AddDependencyCallsCompilerPass) {
85
                    return;
86
                }
87
88
                if ($pass instanceof AddFilterTypeCompilerPass) {
89
                    return;
90
                }
91
92
                if ($pass instanceof ExtensionCompilerPass) {
93
                    return;
94
                }
95
96
                if ($pass instanceof GlobalVariablesCompilerPass) {
97
                    return;
98
                }
99
100
                if ($pass instanceof AdminMakerCompilerPass) {
101
                    return;
102
                }
103
104
                $this->fail(sprintf(
105
                    'CompilerPass is not one of the expected types. Expects "%s", "%s", "%s", "%s" or "%s", but got "%s".',
106
                    AddDependencyCallsCompilerPass::class,
107
                    AddFilterTypeCompilerPass::class,
108
                    ExtensionCompilerPass::class,
109
                    GlobalVariablesCompilerPass::class,
110
                    AdminMakerCompilerPass::class,
111
                    \get_class($pass)
112
                ));
113
            }));
114
115
        $containerBuilder
116
            ->expects($this->once())
117
            ->method('getParameter')
118
            ->with('kernel.bundles')
119
            ->willReturn(['MakerBundle' => 'foo']);
120
121
        $bundle = new SonataAdminBundle();
122
        $bundle->build($containerBuilder);
123
    }
124
}
125