Completed
Push — master ( bf3f93...22d625 )
by Maksim
03:11
created

LiipImagineBundleTest   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 213
Duplicated Lines 85.92 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 5
Bugs 0 Features 4
Metric Value
wmc 12
c 5
b 0
f 4
lcom 1
cbo 3
dl 183
loc 213
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A testSubClassOfBundle() 0 4 1
A testAddFiltersCompilerPassOnBuild() 19 19 1
A testAddWebPathResolverFactoryOnBuild() 21 21 1
A testAddAwsS3ResolverFactoryOnBuild() 21 21 1
A createContainerBuilderMock() 0 4 1
A testAddStreamLoaderFactoryOnBuild() 21 21 1
A testAddFilesystemLoaderFactoryOnBuild() 21 21 1
A testAddLoadersCompilerPassOnBuild() 21 21 1
A createExtensionMock() 0 8 1
A testAddPostProcessorsCompilerPassOnBuild() 19 19 1
A testAddResolversCompilerPassOnBuild() 19 19 1
A testAddFlysystemLoaderFactoryOnBuild() 21 21 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Liip\ImagineBundle\Tests;
4
5
use Liip\ImagineBundle\LiipImagineBundle;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
8
/**
9
 * @covers Liip\ImagineBundle\LiipImagineBundle
10
 */
11
class LiipImagineBundleTest extends \Phpunit_Framework_TestCase
12
{
13
    public function testSubClassOfBundle()
14
    {
15
        $this->assertInstanceOf('Symfony\Component\HttpKernel\Bundle\Bundle', new LiipImagineBundle());
16
    }
17
18 View Code Duplication
    public function testAddLoadersCompilerPassOnBuild()
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...
19
    {
20
        $containerMock = $this->createContainerBuilderMock();
21
        $containerMock
22
            ->expects($this->atLeastOnce())
23
            ->method('getExtension')
24
            ->with('liip_imagine')
25
            ->will($this->returnValue($this->createExtensionMock()))
26
        ;
27
        $containerMock
28
            ->expects($this->at(0))
29
            ->method('addCompilerPass')
30
            ->with($this->isInstanceOf('Liip\ImagineBundle\DependencyInjection\Compiler\LoadersCompilerPass'))
31
        ;
32
33
        $container = new ContainerBuilder();
0 ignored issues
show
Unused Code introduced by
$container is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
34
35
        $bundle = new LiipImagineBundle();
36
37
        $bundle->build($containerMock);
38
    }
39
40 View Code Duplication
    public function testAddFiltersCompilerPassOnBuild()
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...
41
    {
42
        $containerMock = $this->createContainerBuilderMock();
43
        $containerMock
44
            ->expects($this->atLeastOnce())
45
            ->method('getExtension')
46
            ->with('liip_imagine')
47
            ->will($this->returnValue($this->createExtensionMock()))
48
        ;
49
        $containerMock
50
            ->expects($this->at(1))
51
            ->method('addCompilerPass')
52
            ->with($this->isInstanceOf('Liip\ImagineBundle\DependencyInjection\Compiler\FiltersCompilerPass'))
53
        ;
54
55
        $bundle = new LiipImagineBundle();
56
57
        $bundle->build($containerMock);
58
    }
59
60 View Code Duplication
    public function testAddPostProcessorsCompilerPassOnBuild()
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...
61
    {
62
        $containerMock = $this->createContainerBuilderMock();
63
        $containerMock
64
            ->expects($this->atLeastOnce())
65
            ->method('getExtension')
66
            ->with('liip_imagine')
67
            ->will($this->returnValue($this->createExtensionMock()))
68
        ;
69
        $containerMock
70
            ->expects($this->at(2))
71
            ->method('addCompilerPass')
72
            ->with($this->isInstanceOf('Liip\ImagineBundle\DependencyInjection\Compiler\PostProcessorsCompilerPass'))
73
        ;
74
75
        $bundle = new LiipImagineBundle();
76
77
        $bundle->build($containerMock);
78
    }
79
80 View Code Duplication
    public function testAddResolversCompilerPassOnBuild()
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...
81
    {
82
        $containerMock = $this->createContainerBuilderMock();
83
        $containerMock
84
            ->expects($this->atLeastOnce())
85
            ->method('getExtension')
86
            ->with('liip_imagine')
87
            ->will($this->returnValue($this->createExtensionMock()))
88
        ;
89
        $containerMock
90
            ->expects($this->at(3))
91
            ->method('addCompilerPass')
92
            ->with($this->isInstanceOf('Liip\ImagineBundle\DependencyInjection\Compiler\ResolversCompilerPass'))
93
        ;
94
95
        $bundle = new LiipImagineBundle();
96
97
        $bundle->build($containerMock);
98
    }
99
100 View Code Duplication
    public function testAddWebPathResolverFactoryOnBuild()
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...
101
    {
102
        $extensionMock = $this->createExtensionMock();
103
        $extensionMock
104
            ->expects($this->at(0))
105
            ->method('addResolverFactory')
106
            ->with($this->isInstanceOf('Liip\ImagineBundle\DependencyInjection\Factory\Resolver\WebPathResolverFactory'))
107
        ;
108
109
        $containerMock = $this->createContainerBuilderMock();
110
        $containerMock
111
            ->expects($this->atLeastOnce())
112
            ->method('getExtension')
113
            ->with('liip_imagine')
114
            ->will($this->returnValue($extensionMock))
115
        ;
116
117
        $bundle = new LiipImagineBundle();
118
119
        $bundle->build($containerMock);
120
    }
121
122 View Code Duplication
    public function testAddAwsS3ResolverFactoryOnBuild()
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...
123
    {
124
        $extensionMock = $this->createExtensionMock();
125
        $extensionMock
126
            ->expects($this->at(1))
127
            ->method('addResolverFactory')
128
            ->with($this->isInstanceOf('Liip\ImagineBundle\DependencyInjection\Factory\Resolver\AwsS3ResolverFactory'))
129
        ;
130
131
        $containerMock = $this->createContainerBuilderMock();
132
        $containerMock
133
            ->expects($this->atLeastOnce())
134
            ->method('getExtension')
135
            ->with('liip_imagine')
136
            ->will($this->returnValue($extensionMock))
137
        ;
138
139
        $bundle = new LiipImagineBundle();
140
141
        $bundle->build($containerMock);
142
    }
143
144 View Code Duplication
    public function testAddStreamLoaderFactoryOnBuild()
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...
145
    {
146
        $extensionMock = $this->createExtensionMock();
147
        $extensionMock
148
            ->expects($this->at(2))
149
            ->method('addLoaderFactory')
150
            ->with($this->isInstanceOf('Liip\ImagineBundle\DependencyInjection\Factory\Loader\StreamLoaderFactory'))
151
        ;
152
153
        $containerMock = $this->createContainerBuilderMock();
154
        $containerMock
155
            ->expects($this->atLeastOnce())
156
            ->method('getExtension')
157
            ->with('liip_imagine')
158
            ->will($this->returnValue($extensionMock))
159
        ;
160
161
        $bundle = new LiipImagineBundle();
162
163
        $bundle->build($containerMock);
164
    }
165
166 View Code Duplication
    public function testAddFilesystemLoaderFactoryOnBuild()
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...
167
    {
168
        $extensionMock = $this->createExtensionMock();
169
        $extensionMock
170
            ->expects($this->at(3))
171
            ->method('addLoaderFactory')
172
            ->with($this->isInstanceOf('Liip\ImagineBundle\DependencyInjection\Factory\Loader\FilesystemLoaderFactory'))
173
        ;
174
175
        $containerMock = $this->createContainerBuilderMock();
176
        $containerMock
177
            ->expects($this->atLeastOnce())
178
            ->method('getExtension')
179
            ->with('liip_imagine')
180
            ->will($this->returnValue($extensionMock))
181
        ;
182
183
        $bundle = new LiipImagineBundle();
184
185
        $bundle->build($containerMock);
186
    }
187
188 View Code Duplication
    public function testAddFlysystemLoaderFactoryOnBuild()
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...
189
    {
190
        $extensionMock = $this->createExtensionMock();
191
        $extensionMock
192
            ->expects($this->at(4))
193
            ->method('addLoaderFactory')
194
            ->with($this->isInstanceOf('Liip\ImagineBundle\DependencyInjection\Factory\Loader\FlysystemLoaderFactory'))
195
        ;
196
197
        $containerMock = $this->createContainerBuilderMock();
198
        $containerMock
199
            ->expects($this->atLeastOnce())
200
            ->method('getExtension')
201
            ->with('liip_imagine')
202
            ->will($this->returnValue($extensionMock))
203
        ;
204
205
        $bundle = new LiipImagineBundle();
206
207
        $bundle->build($containerMock);
208
    }
209
210
    protected function createContainerBuilderMock()
211
    {
212
        return $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder', array(), array(), '', false);
213
    }
214
215
    protected function createExtensionMock()
216
    {
217
        $methods = array(
218
            'getNamespace', 'addResolverFactory', 'addLoaderFactory',
219
        );
220
221
        return $this->getMock('Liip\ImagineBundle\DependencyInjection\LiipImagineExtension', $methods, array(), '', false);
222
    }
223
}
224