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() |
|
|
|
|
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(); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$bundle = new LiipImagineBundle(); |
36
|
|
|
|
37
|
|
|
$bundle->build($containerMock); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
View Code Duplication |
public function testAddFiltersCompilerPassOnBuild() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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
|
|
|
|
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.