1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Liip\ImagineBundle\Tests\DependencyInjection\Factory\Resolver; |
4
|
|
|
|
5
|
|
|
use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\AwsS3ResolverFactory; |
6
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
7
|
|
|
use Symfony\Component\Config\Definition\Processor; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
9
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @covers Liip\ImagineBundle\DependencyInjection\Factory\Resolver\AwsS3ResolverFactory<extended> |
13
|
|
|
*/ |
14
|
|
|
class AwsS3ResolverFactoryTest extends \Phpunit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
public function testImplementsResolverFactoryInterface() |
17
|
|
|
{ |
18
|
|
|
$rc = new \ReflectionClass('Liip\ImagineBundle\DependencyInjection\Factory\Resolver\AwsS3ResolverFactory'); |
19
|
|
|
|
20
|
|
|
$this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\DependencyInjection\Factory\Resolver\ResolverFactoryInterface')); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testCouldBeConstructedWithoutAnyArguments() |
24
|
|
|
{ |
25
|
|
|
new AwsS3ResolverFactory(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testReturnExpectedName() |
29
|
|
|
{ |
30
|
|
|
$resolver = new AwsS3ResolverFactory(); |
31
|
|
|
|
32
|
|
|
$this->assertEquals('aws_s3', $resolver->getName()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testCreateResolverDefinitionOnCreate() |
36
|
|
|
{ |
37
|
|
|
$container = new ContainerBuilder(); |
38
|
|
|
|
39
|
|
|
$resolver = new AwsS3ResolverFactory(); |
40
|
|
|
|
41
|
|
|
$resolver->create($container, 'theResolverName', array( |
42
|
|
|
'client_config' => array(), |
43
|
|
|
'bucket' => 'theBucket', |
44
|
|
|
'acl' => 'theAcl', |
45
|
|
|
'url_options' => array('fooKey' => 'fooVal'), |
46
|
|
|
'get_options' => array(), |
47
|
|
|
'put_options' => array('barKey' => 'barVal'), |
48
|
|
|
'cache' => false, |
49
|
|
|
'proxies' => array(), |
50
|
|
|
)); |
51
|
|
|
|
52
|
|
|
$this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername')); |
53
|
|
|
|
54
|
|
|
$resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername'); |
55
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $resolverDefinition); |
56
|
|
|
$this->assertEquals('liip_imagine.cache.resolver.prototype.aws_s3', $resolverDefinition->getParent()); |
57
|
|
|
|
58
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(0)); |
59
|
|
|
$this->assertEquals('liip_imagine.cache.resolver.theresolvername.client', $resolverDefinition->getArgument(0)); |
60
|
|
|
|
61
|
|
|
$this->assertEquals('theBucket', $resolverDefinition->getArgument(1)); |
62
|
|
|
$this->assertEquals('theAcl', $resolverDefinition->getArgument(2)); |
63
|
|
|
$this->assertEquals(array('fooKey' => 'fooVal'), $resolverDefinition->getArgument(3)); |
64
|
|
|
$this->assertEquals(array('barKey' => 'barVal'), $resolverDefinition->getArgument(4)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testOverrideDeprecatedUrlOptionsWithNewGetOptions() |
68
|
|
|
{ |
69
|
|
|
$container = new ContainerBuilder(); |
70
|
|
|
|
71
|
|
|
$resolver = new AwsS3ResolverFactory(); |
72
|
|
|
|
73
|
|
|
$resolver->create($container, 'theResolverName', array( |
74
|
|
|
'client_config' => array(), |
75
|
|
|
'bucket' => 'theBucket', |
76
|
|
|
'acl' => 'theAcl', |
77
|
|
|
'url_options' => array('fooKey' => 'fooVal', 'barKey' => 'barVal'), |
78
|
|
|
'get_options' => array('fooKey' => 'fooVal_overridden'), |
79
|
|
|
'put_options' => array(), |
80
|
|
|
'cache' => false, |
81
|
|
|
'proxies' => array(), |
82
|
|
|
)); |
83
|
|
|
|
84
|
|
|
$this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername')); |
85
|
|
|
|
86
|
|
|
$resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername'); |
87
|
|
|
$this->assertEquals(array('fooKey' => 'fooVal_overridden', 'barKey' => 'barVal'), $resolverDefinition->getArgument(3)); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testCreateS3ClientDefinitionOnCreate() |
91
|
|
|
{ |
92
|
|
|
$container = new ContainerBuilder(); |
93
|
|
|
|
94
|
|
|
$resolver = new AwsS3ResolverFactory(); |
95
|
|
|
|
96
|
|
|
$resolver->create($container, 'theResolverName', array( |
97
|
|
|
'client_config' => array('theClientConfigKey' => 'theClientConfigVal'), |
98
|
|
|
'bucket' => 'aBucket', |
99
|
|
|
'acl' => 'aAcl', |
100
|
|
|
'url_options' => array(), |
101
|
|
|
'get_options' => array(), |
102
|
|
|
'put_options' => array(), |
103
|
|
|
'cache' => false, |
104
|
|
|
'proxies' => array(), |
105
|
|
|
)); |
106
|
|
|
|
107
|
|
|
$this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername.client')); |
108
|
|
|
|
109
|
|
|
$clientDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername.client'); |
110
|
|
|
$this->assertEquals('Aws\S3\S3Client', $clientDefinition->getClass()); |
111
|
|
|
$this->assertEquals(array('theClientConfigKey' => 'theClientConfigVal'), $clientDefinition->getArgument(0)); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testCreateS3ClientDefinitionWithFactoryOnCreate() |
115
|
|
|
{ |
116
|
|
|
if (version_compare(Kernel::VERSION_ID, '20600') < 0) { |
117
|
|
|
$this->markTestSkipped('No need to test on symfony < 2.6'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
$container = new ContainerBuilder(); |
121
|
|
|
|
122
|
|
|
$resolver = new AwsS3ResolverFactory(); |
123
|
|
|
|
124
|
|
|
$resolver->create($container, 'theResolverName', array( |
125
|
|
|
'client_config' => array('theClientConfigKey' => 'theClientConfigVal'), |
126
|
|
|
'bucket' => 'aBucket', |
127
|
|
|
'acl' => 'aAcl', |
128
|
|
|
'url_options' => array(), |
129
|
|
|
'get_options' => array(), |
130
|
|
|
'put_options' => array(), |
131
|
|
|
'cache' => false, |
132
|
|
|
'proxies' => array(), |
133
|
|
|
)); |
134
|
|
|
|
135
|
|
|
$clientDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername.client'); |
136
|
|
|
$this->assertEquals(array('Aws\S3\S3Client', 'factory'), $clientDefinition->getFactory()); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function testLegacyCreateS3ClientDefinitionWithFactoryOnCreate() |
140
|
|
|
{ |
141
|
|
|
if (version_compare(Kernel::VERSION_ID, '20600') >= 0) { |
142
|
|
|
$this->markTestSkipped('No need to test on symfony >= 2.6'); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
$container = new ContainerBuilder(); |
146
|
|
|
|
147
|
|
|
$resolver = new AwsS3ResolverFactory(); |
148
|
|
|
|
149
|
|
|
$resolver->create($container, 'theResolverName', array( |
150
|
|
|
'client_config' => array('theClientConfigKey' => 'theClientConfigVal'), |
151
|
|
|
'bucket' => 'aBucket', |
152
|
|
|
'acl' => 'aAcl', |
153
|
|
|
'url_options' => array(), |
154
|
|
|
'get_options' => array(), |
155
|
|
|
'put_options' => array(), |
156
|
|
|
'cache' => false, |
157
|
|
|
'proxies' => array(), |
158
|
|
|
)); |
159
|
|
|
|
160
|
|
|
$clientDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername.client'); |
161
|
|
|
$this->assertEquals('Aws\S3\S3Client', $clientDefinition->getFactoryClass()); |
|
|
|
|
162
|
|
|
$this->assertEquals('factory', $clientDefinition->getFactoryMethod()); |
|
|
|
|
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function testWrapResolverWithProxyOnCreateWithoutCache() |
166
|
|
|
{ |
167
|
|
|
$container = new ContainerBuilder(); |
168
|
|
|
|
169
|
|
|
$resolver = new AwsS3ResolverFactory(); |
170
|
|
|
|
171
|
|
|
$resolver->create($container, 'theResolverName', array( |
172
|
|
|
'client_config' => array(), |
173
|
|
|
'bucket' => 'aBucket', |
174
|
|
|
'acl' => 'aAcl', |
175
|
|
|
'url_options' => array(), |
176
|
|
|
'get_options' => array(), |
177
|
|
|
'put_options' => array(), |
178
|
|
|
'cache' => false, |
179
|
|
|
'proxies' => array('foo'), |
180
|
|
|
)); |
181
|
|
|
|
182
|
|
|
$this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername.proxied')); |
183
|
|
|
$proxiedResolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername.proxied'); |
184
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $proxiedResolverDefinition); |
185
|
|
|
$this->assertEquals('liip_imagine.cache.resolver.prototype.aws_s3', $proxiedResolverDefinition->getParent()); |
186
|
|
|
|
187
|
|
|
$this->assertFalse($container->hasDefinition('liip_imagine.cache.resolver.theresolvername.cached')); |
188
|
|
|
|
189
|
|
|
$this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername')); |
190
|
|
|
$resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername'); |
191
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $resolverDefinition); |
192
|
|
|
$this->assertEquals('liip_imagine.cache.resolver.prototype.proxy', $resolverDefinition->getParent()); |
193
|
|
|
|
194
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(0)); |
195
|
|
|
$this->assertEquals('liip_imagine.cache.resolver.theresolvername.proxied', $resolverDefinition->getArgument(0)); |
196
|
|
|
|
197
|
|
|
$this->assertEquals(array('foo'), $resolverDefinition->getArgument(1)); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function testWrapResolverWithCacheOnCreateWithoutProxy() |
201
|
|
|
{ |
202
|
|
|
$container = new ContainerBuilder(); |
203
|
|
|
|
204
|
|
|
$resolver = new AwsS3ResolverFactory(); |
205
|
|
|
|
206
|
|
|
$resolver->create($container, 'theResolverName', array( |
207
|
|
|
'client_config' => array(), |
208
|
|
|
'bucket' => 'aBucket', |
209
|
|
|
'acl' => 'aAcl', |
210
|
|
|
'url_options' => array(), |
211
|
|
|
'get_options' => array(), |
212
|
|
|
'put_options' => array(), |
213
|
|
|
'cache' => 'theCacheServiceId', |
214
|
|
|
'proxies' => array(), |
215
|
|
|
)); |
216
|
|
|
|
217
|
|
|
$this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername.cached')); |
218
|
|
|
$cachedResolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername.cached'); |
219
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $cachedResolverDefinition); |
220
|
|
|
$this->assertEquals('liip_imagine.cache.resolver.prototype.aws_s3', $cachedResolverDefinition->getParent()); |
221
|
|
|
|
222
|
|
|
$this->assertFalse($container->hasDefinition('liip_imagine.cache.resolver.theresolvername.proxied')); |
223
|
|
|
|
224
|
|
|
$this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername')); |
225
|
|
|
$resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername'); |
226
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $resolverDefinition); |
227
|
|
|
$this->assertEquals('liip_imagine.cache.resolver.prototype.cache', $resolverDefinition->getParent()); |
228
|
|
|
|
229
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(0)); |
230
|
|
|
$this->assertEquals('thecacheserviceid', $resolverDefinition->getArgument(0)); |
231
|
|
|
|
232
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(1)); |
233
|
|
|
$this->assertEquals('liip_imagine.cache.resolver.theresolvername.cached', $resolverDefinition->getArgument(1)); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
public function testWrapResolverWithProxyAndCacheOnCreate() |
237
|
|
|
{ |
238
|
|
|
$container = new ContainerBuilder(); |
239
|
|
|
|
240
|
|
|
$resolver = new AwsS3ResolverFactory(); |
241
|
|
|
|
242
|
|
|
$resolver->create($container, 'theResolverName', array( |
243
|
|
|
'client_config' => array(), |
244
|
|
|
'bucket' => 'aBucket', |
245
|
|
|
'acl' => 'aAcl', |
246
|
|
|
'url_options' => array(), |
247
|
|
|
'get_options' => array(), |
248
|
|
|
'put_options' => array(), |
249
|
|
|
'cache' => 'theCacheServiceId', |
250
|
|
|
'proxies' => array('foo'), |
251
|
|
|
)); |
252
|
|
|
|
253
|
|
|
$this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername.proxied')); |
254
|
|
|
$proxiedResolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername.proxied'); |
255
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $proxiedResolverDefinition); |
256
|
|
|
$this->assertEquals('liip_imagine.cache.resolver.prototype.aws_s3', $proxiedResolverDefinition->getParent()); |
257
|
|
|
|
258
|
|
|
$this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername.cached')); |
259
|
|
|
$cachedResolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername.cached'); |
260
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $cachedResolverDefinition); |
261
|
|
|
$this->assertEquals('liip_imagine.cache.resolver.prototype.proxy', $cachedResolverDefinition->getParent()); |
262
|
|
|
|
263
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $cachedResolverDefinition->getArgument(0)); |
264
|
|
|
$this->assertEquals('liip_imagine.cache.resolver.theresolvername.proxied', $cachedResolverDefinition->getArgument(0)); |
265
|
|
|
|
266
|
|
|
$this->assertEquals(array('foo'), $cachedResolverDefinition->getArgument(1)); |
267
|
|
|
|
268
|
|
|
$this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername')); |
269
|
|
|
$resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername'); |
270
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $resolverDefinition); |
271
|
|
|
$this->assertEquals('liip_imagine.cache.resolver.prototype.cache', $resolverDefinition->getParent()); |
272
|
|
|
|
273
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(0)); |
274
|
|
|
$this->assertEquals('thecacheserviceid', $resolverDefinition->getArgument(0)); |
275
|
|
|
|
276
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $resolverDefinition->getArgument(1)); |
277
|
|
|
$this->assertEquals('liip_imagine.cache.resolver.theresolvername.cached', $resolverDefinition->getArgument(1)); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
public function testSetCachePrefixIfDefined() |
281
|
|
|
{ |
282
|
|
|
$container = new ContainerBuilder(); |
283
|
|
|
|
284
|
|
|
$resolver = new AwsS3ResolverFactory(); |
285
|
|
|
|
286
|
|
|
$resolver->create($container, 'theResolverName', array( |
287
|
|
|
'client_config' => array(), |
288
|
|
|
'bucket' => 'aBucket', |
289
|
|
|
'acl' => 'aAcl', |
290
|
|
|
'url_options' => array(), |
291
|
|
|
'get_options' => array(), |
292
|
|
|
'put_options' => array(), |
293
|
|
|
'cache_prefix' => 'theCachePrefix', |
294
|
|
|
'cache' => null, |
295
|
|
|
'proxies' => array(), |
296
|
|
|
)); |
297
|
|
|
|
298
|
|
|
$this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername')); |
299
|
|
|
$resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername'); |
300
|
|
|
|
301
|
|
|
$methodCalls = $resolverDefinition->getMethodCalls(); |
302
|
|
|
|
303
|
|
|
$this->assertCount(1, $methodCalls); |
304
|
|
|
$this->assertEquals('setCachePrefix', $methodCalls[0][0]); |
305
|
|
|
$this->assertEquals(array('theCachePrefix'), $methodCalls[0][1]); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
310
|
|
|
* @expectedExceptionMessage The child node "bucket" at path "aws_s3" must be configured. |
311
|
|
|
*/ |
312
|
|
View Code Duplication |
public function testThrowBucketNotSetOnAddConfiguration() |
|
|
|
|
313
|
|
|
{ |
314
|
|
|
$treeBuilder = new TreeBuilder(); |
315
|
|
|
$rootNode = $treeBuilder->root('aws_s3', 'array'); |
316
|
|
|
|
317
|
|
|
$resolver = new AwsS3ResolverFactory(); |
318
|
|
|
$resolver->addConfiguration($rootNode); |
319
|
|
|
|
320
|
|
|
$this->processConfigTree($treeBuilder, array()); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
325
|
|
|
* @expectedExceptionMessage The child node "client_config" at path "aws_s3" must be configured. |
326
|
|
|
*/ |
327
|
|
View Code Duplication |
public function testThrowClientConfigNotSetOnAddConfiguration() |
|
|
|
|
328
|
|
|
{ |
329
|
|
|
$treeBuilder = new TreeBuilder(); |
330
|
|
|
$rootNode = $treeBuilder->root('aws_s3', 'array'); |
331
|
|
|
|
332
|
|
|
$resolver = new AwsS3ResolverFactory(); |
333
|
|
|
$resolver->addConfiguration($rootNode); |
334
|
|
|
|
335
|
|
|
$this->processConfigTree($treeBuilder, array( |
336
|
|
|
'aws_s3' => array( |
337
|
|
|
'bucket' => 'aBucket', |
338
|
|
|
), |
339
|
|
|
)); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
344
|
|
|
* @expectedExceptionMessage Invalid type for path "aws_s3.client_config". Expected array, but got string |
345
|
|
|
*/ |
346
|
|
View Code Duplication |
public function testThrowClientConfigNotArrayOnAddConfiguration() |
|
|
|
|
347
|
|
|
{ |
348
|
|
|
$treeBuilder = new TreeBuilder(); |
349
|
|
|
$rootNode = $treeBuilder->root('aws_s3', 'array'); |
350
|
|
|
|
351
|
|
|
$resolver = new AwsS3ResolverFactory(); |
352
|
|
|
$resolver->addConfiguration($rootNode); |
353
|
|
|
|
354
|
|
|
$this->processConfigTree($treeBuilder, array( |
355
|
|
|
'aws_s3' => array( |
356
|
|
|
'bucket' => 'aBucket', |
357
|
|
|
'client_config' => 'not_array', |
358
|
|
|
), |
359
|
|
|
)); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
public function testProcessCorrectlyOptionsOnAddConfiguration() |
363
|
|
|
{ |
364
|
|
|
$expectedClientConfig = array( |
365
|
|
|
'theKey' => 'theClientConfigVal', |
366
|
|
|
'theOtherKey' => 'theOtherClientConfigValue', |
367
|
|
|
); |
368
|
|
|
$expectedUrlOptions = array( |
369
|
|
|
'theKey' => 'theUrlOptionsVal', |
370
|
|
|
'theOtherKey' => 'theOtherUrlOptionsValue', |
371
|
|
|
); |
372
|
|
|
$expectedGetOptions = array( |
373
|
|
|
'theKey' => 'theGetOptionsVal', |
374
|
|
|
'theOtherKey' => 'theOtherGetOptionsValue', |
375
|
|
|
); |
376
|
|
|
$expectedObjectOptions = array( |
377
|
|
|
'theKey' => 'theObjectOptionsVal', |
378
|
|
|
'theOtherKey' => 'theOtherObjectOptionsValue', |
379
|
|
|
); |
380
|
|
|
$expectedBucket = 'theBucket'; |
381
|
|
|
$expectedAcl = 'theAcl'; |
382
|
|
|
$expectedCachePrefix = 'theCachePrefix'; |
383
|
|
|
|
384
|
|
|
$treeBuilder = new TreeBuilder(); |
385
|
|
|
$rootNode = $treeBuilder->root('aws_s3', 'array'); |
386
|
|
|
|
387
|
|
|
$resolver = new AwsS3ResolverFactory(); |
388
|
|
|
$resolver->addConfiguration($rootNode); |
389
|
|
|
|
390
|
|
|
$config = $this->processConfigTree($treeBuilder, array( |
391
|
|
|
'aws_s3' => array( |
392
|
|
|
'bucket' => $expectedBucket, |
393
|
|
|
'acl' => $expectedAcl, |
394
|
|
|
'client_config' => $expectedClientConfig, |
395
|
|
|
'url_options' => $expectedUrlOptions, |
396
|
|
|
'get_options' => $expectedGetOptions, |
397
|
|
|
'put_options' => $expectedObjectOptions, |
398
|
|
|
'cache_prefix' => $expectedCachePrefix, |
399
|
|
|
), |
400
|
|
|
)); |
401
|
|
|
|
402
|
|
|
$this->assertArrayHasKey('bucket', $config); |
403
|
|
|
$this->assertEquals($expectedBucket, $config['bucket']); |
404
|
|
|
|
405
|
|
|
$this->assertArrayHasKey('acl', $config); |
406
|
|
|
$this->assertEquals($expectedAcl, $config['acl']); |
407
|
|
|
|
408
|
|
|
$this->assertArrayHasKey('client_config', $config); |
409
|
|
|
$this->assertEquals($expectedClientConfig, $config['client_config']); |
410
|
|
|
|
411
|
|
|
$this->assertArrayHasKey('url_options', $config); |
412
|
|
|
$this->assertEquals($expectedUrlOptions, $config['url_options']); |
413
|
|
|
|
414
|
|
|
$this->assertArrayHasKey('get_options', $config); |
415
|
|
|
$this->assertEquals($expectedGetOptions, $config['get_options']); |
416
|
|
|
|
417
|
|
|
$this->assertArrayHasKey('put_options', $config); |
418
|
|
|
$this->assertEquals($expectedObjectOptions, $config['put_options']); |
419
|
|
|
|
420
|
|
|
$this->assertArrayHasKey('cache_prefix', $config); |
421
|
|
|
$this->assertEquals($expectedCachePrefix, $config['cache_prefix']); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
public function testAddDefaultOptionsIfNotSetOnAddConfiguration() |
425
|
|
|
{ |
426
|
|
|
$expectedAcl = 'public-read'; |
427
|
|
|
|
428
|
|
|
$treeBuilder = new TreeBuilder(); |
429
|
|
|
$rootNode = $treeBuilder->root('aws_s3', 'array'); |
430
|
|
|
|
431
|
|
|
$resolver = new AwsS3ResolverFactory(); |
432
|
|
|
$resolver->addConfiguration($rootNode); |
433
|
|
|
|
434
|
|
|
$config = $this->processConfigTree($treeBuilder, array( |
435
|
|
|
'aws_s3' => array( |
436
|
|
|
'bucket' => 'aBucket', |
437
|
|
|
'client_config' => array(), |
438
|
|
|
), |
439
|
|
|
)); |
440
|
|
|
|
441
|
|
|
$this->assertArrayHasKey('acl', $config); |
442
|
|
|
$this->assertEquals($expectedAcl, $config['acl']); |
443
|
|
|
|
444
|
|
|
$this->assertArrayHasKey('url_options', $config); |
445
|
|
|
$this->assertEquals(array(), $config['url_options']); |
446
|
|
|
|
447
|
|
|
$this->assertArrayHasKey('get_options', $config); |
448
|
|
|
$this->assertEquals(array(), $config['get_options']); |
449
|
|
|
|
450
|
|
|
$this->assertArrayHasKey('cache_prefix', $config); |
451
|
|
|
$this->assertNull($config['cache_prefix']); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
public function testSupportAwsV3ClientConfig() |
455
|
|
|
{ |
456
|
|
|
$expectedClientConfig = array( |
457
|
|
|
'credentials' => array( |
458
|
|
|
'key' => 'theKey', |
459
|
|
|
'secret' => 'theSecret', |
460
|
|
|
'token' => 'theToken', |
461
|
|
|
), |
462
|
|
|
'region' => 'theRegion', |
463
|
|
|
'version' => 'theVersion', |
464
|
|
|
); |
465
|
|
|
$expectedUrlOptions = array( |
466
|
|
|
'theKey' => 'theUrlOptionsVal', |
467
|
|
|
'theOtherKey' => 'theOtherUrlOptionsValue', |
468
|
|
|
); |
469
|
|
|
$expectedGetOptions = array( |
470
|
|
|
'theKey' => 'theGetOptionsVal', |
471
|
|
|
'theOtherKey' => 'theOtherGetOptionsValue', |
472
|
|
|
); |
473
|
|
|
$expectedObjectOptions = array( |
474
|
|
|
'theKey' => 'theObjectOptionsVal', |
475
|
|
|
'theOtherKey' => 'theOtherObjectOptionsValue', |
476
|
|
|
); |
477
|
|
|
$expectedBucket = 'theBucket'; |
478
|
|
|
$expectedAcl = 'theAcl'; |
479
|
|
|
$expectedCachePrefix = 'theCachePrefix'; |
480
|
|
|
|
481
|
|
|
$treeBuilder = new TreeBuilder(); |
482
|
|
|
$rootNode = $treeBuilder->root('aws_s3', 'array'); |
483
|
|
|
|
484
|
|
|
$resolver = new AwsS3ResolverFactory(); |
485
|
|
|
$resolver->addConfiguration($rootNode); |
486
|
|
|
|
487
|
|
|
$config = $this->processConfigTree($treeBuilder, array( |
488
|
|
|
'aws_s3' => array( |
489
|
|
|
'bucket' => $expectedBucket, |
490
|
|
|
'acl' => $expectedAcl, |
491
|
|
|
'client_config' => $expectedClientConfig, |
492
|
|
|
'url_options' => $expectedUrlOptions, |
493
|
|
|
'get_options' => $expectedGetOptions, |
494
|
|
|
'put_options' => $expectedObjectOptions, |
495
|
|
|
'cache_prefix' => $expectedCachePrefix, |
496
|
|
|
), |
497
|
|
|
)); |
498
|
|
|
|
499
|
|
|
$this->assertArrayHasKey('bucket', $config); |
500
|
|
|
$this->assertEquals($expectedBucket, $config['bucket']); |
501
|
|
|
|
502
|
|
|
$this->assertArrayHasKey('acl', $config); |
503
|
|
|
$this->assertEquals($expectedAcl, $config['acl']); |
504
|
|
|
|
505
|
|
|
$this->assertArrayHasKey('client_config', $config); |
506
|
|
|
$this->assertEquals($expectedClientConfig, $config['client_config']); |
507
|
|
|
|
508
|
|
|
$this->assertArrayHasKey('url_options', $config); |
509
|
|
|
$this->assertEquals($expectedUrlOptions, $config['url_options']); |
510
|
|
|
|
511
|
|
|
$this->assertArrayHasKey('get_options', $config); |
512
|
|
|
$this->assertEquals($expectedGetOptions, $config['get_options']); |
513
|
|
|
|
514
|
|
|
$this->assertArrayHasKey('put_options', $config); |
515
|
|
|
$this->assertEquals($expectedObjectOptions, $config['put_options']); |
516
|
|
|
|
517
|
|
|
$this->assertArrayHasKey('cache_prefix', $config); |
518
|
|
|
$this->assertEquals($expectedCachePrefix, $config['cache_prefix']); |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
/** |
522
|
|
|
* @param TreeBuilder $treeBuilder |
523
|
|
|
* @param array $configs |
524
|
|
|
* |
525
|
|
|
* @return array |
526
|
|
|
*/ |
527
|
|
|
protected function processConfigTree(TreeBuilder $treeBuilder, array $configs) |
528
|
|
|
{ |
529
|
|
|
$processor = new Processor(); |
530
|
|
|
|
531
|
|
|
return $processor->process($treeBuilder->buildTree(), $configs); |
532
|
|
|
} |
533
|
|
|
} |
534
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.