Completed
Push — master ( 2bb76e...2f6bf5 )
by Maksim
03:40
created

testSupportAwsV3ClientConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 66
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 66
rs 9.3191
cc 1
eloc 47
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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());
0 ignored issues
show
Bug introduced by
The method getFactoryClass() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean getFactory()?

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.

Loading history...
162
        $this->assertEquals('factory', $clientDefinition->getFactoryMethod());
0 ignored issues
show
Bug introduced by
The method getFactoryMethod() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean getFactory()?

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.

Loading history...
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 testWrapResolverWithProxyMatchReplaceStrategyOnCreate()
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' => 'theCacheServiceId',
294
            'proxies' => array('foo' => 'bar'),
295
        ));
296
297
        $this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername.proxied'));
298
        $proxiedResolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername.proxied');
299
        $this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $proxiedResolverDefinition);
300
        $this->assertEquals('liip_imagine.cache.resolver.prototype.aws_s3', $proxiedResolverDefinition->getParent());
301
302
        $this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername.cached'));
303
        $cachedResolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername.cached');
304
        $this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $cachedResolverDefinition);
305
        $this->assertEquals('liip_imagine.cache.resolver.prototype.proxy', $cachedResolverDefinition->getParent());
306
307
        $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $cachedResolverDefinition->getArgument(0));
308
        $this->assertEquals('liip_imagine.cache.resolver.theresolvername.proxied', $cachedResolverDefinition->getArgument(0));
309
310
        $this->assertEquals(array('foo' => 'bar'), $cachedResolverDefinition->getArgument(1));
311
    }
312
313
    public function testSetCachePrefixIfDefined()
314
    {
315
        $container = new ContainerBuilder();
316
317
        $resolver = new AwsS3ResolverFactory();
318
319
        $resolver->create($container, 'theResolverName', array(
320
            'client_config' => array(),
321
            'bucket' => 'aBucket',
322
            'acl' => 'aAcl',
323
            'url_options' => array(),
324
            'get_options' => array(),
325
            'put_options' => array(),
326
            'cache_prefix' => 'theCachePrefix',
327
            'cache' => null,
328
            'proxies' => array(),
329
        ));
330
331
        $this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername'));
332
        $resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername');
333
334
        $methodCalls = $resolverDefinition->getMethodCalls();
335
336
        $this->assertCount(1, $methodCalls);
337
        $this->assertEquals('setCachePrefix', $methodCalls[0][0]);
338
        $this->assertEquals(array('theCachePrefix'), $methodCalls[0][1]);
339
    }
340
341
    /**
342
     * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
343
     * @expectedExceptionMessage The child node "bucket" at path "aws_s3" must be configured.
344
     */
345 View Code Duplication
    public function testThrowBucketNotSetOnAddConfiguration()
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...
346
    {
347
        $treeBuilder = new TreeBuilder();
348
        $rootNode = $treeBuilder->root('aws_s3', 'array');
349
350
        $resolver = new AwsS3ResolverFactory();
351
        $resolver->addConfiguration($rootNode);
352
353
        $this->processConfigTree($treeBuilder, array());
354
    }
355
356
    /**
357
     * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
358
     * @expectedExceptionMessage The child node "client_config" at path "aws_s3" must be configured.
359
     */
360 View Code Duplication
    public function testThrowClientConfigNotSetOnAddConfiguration()
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...
361
    {
362
        $treeBuilder = new TreeBuilder();
363
        $rootNode = $treeBuilder->root('aws_s3', 'array');
364
365
        $resolver = new AwsS3ResolverFactory();
366
        $resolver->addConfiguration($rootNode);
367
368
        $this->processConfigTree($treeBuilder, array(
369
            'aws_s3' => array(
370
                'bucket' => 'aBucket',
371
            ),
372
        ));
373
    }
374
375
    /**
376
     * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
377
     * @expectedExceptionMessage Invalid type for path "aws_s3.client_config". Expected array, but got string
378
     */
379 View Code Duplication
    public function testThrowClientConfigNotArrayOnAddConfiguration()
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...
380
    {
381
        $treeBuilder = new TreeBuilder();
382
        $rootNode = $treeBuilder->root('aws_s3', 'array');
383
384
        $resolver = new AwsS3ResolverFactory();
385
        $resolver->addConfiguration($rootNode);
386
387
        $this->processConfigTree($treeBuilder, array(
388
            'aws_s3' => array(
389
                'bucket' => 'aBucket',
390
                'client_config' => 'not_array',
391
            ),
392
        ));
393
    }
394
395
    public function testProcessCorrectlyOptionsOnAddConfiguration()
396
    {
397
        $expectedClientConfig = array(
398
            'theKey' => 'theClientConfigVal',
399
            'theOtherKey' => 'theOtherClientConfigValue',
400
        );
401
        $expectedUrlOptions = array(
402
            'theKey' => 'theUrlOptionsVal',
403
            'theOtherKey' => 'theOtherUrlOptionsValue',
404
        );
405
        $expectedGetOptions = array(
406
            'theKey' => 'theGetOptionsVal',
407
            'theOtherKey' => 'theOtherGetOptionsValue',
408
        );
409
        $expectedObjectOptions = array(
410
            'theKey' => 'theObjectOptionsVal',
411
            'theOtherKey' => 'theOtherObjectOptionsValue',
412
        );
413
        $expectedBucket = 'theBucket';
414
        $expectedAcl = 'theAcl';
415
        $expectedCachePrefix = 'theCachePrefix';
416
417
        $treeBuilder = new TreeBuilder();
418
        $rootNode = $treeBuilder->root('aws_s3', 'array');
419
420
        $resolver = new AwsS3ResolverFactory();
421
        $resolver->addConfiguration($rootNode);
422
423
        $config = $this->processConfigTree($treeBuilder, array(
424
            'aws_s3' => array(
425
                'bucket' => $expectedBucket,
426
                'acl' => $expectedAcl,
427
                'client_config' => $expectedClientConfig,
428
                'url_options' => $expectedUrlOptions,
429
                'get_options' => $expectedGetOptions,
430
                'put_options' => $expectedObjectOptions,
431
                'cache_prefix' => $expectedCachePrefix,
432
            ),
433
        ));
434
435
        $this->assertArrayHasKey('bucket', $config);
436
        $this->assertEquals($expectedBucket, $config['bucket']);
437
438
        $this->assertArrayHasKey('acl', $config);
439
        $this->assertEquals($expectedAcl, $config['acl']);
440
441
        $this->assertArrayHasKey('client_config', $config);
442
        $this->assertEquals($expectedClientConfig, $config['client_config']);
443
444
        $this->assertArrayHasKey('url_options', $config);
445
        $this->assertEquals($expectedUrlOptions, $config['url_options']);
446
447
        $this->assertArrayHasKey('get_options', $config);
448
        $this->assertEquals($expectedGetOptions, $config['get_options']);
449
450
        $this->assertArrayHasKey('put_options', $config);
451
        $this->assertEquals($expectedObjectOptions, $config['put_options']);
452
453
        $this->assertArrayHasKey('cache_prefix', $config);
454
        $this->assertEquals($expectedCachePrefix, $config['cache_prefix']);
455
    }
456
457
    public function testAddDefaultOptionsIfNotSetOnAddConfiguration()
458
    {
459
        $expectedAcl = 'public-read';
460
461
        $treeBuilder = new TreeBuilder();
462
        $rootNode = $treeBuilder->root('aws_s3', 'array');
463
464
        $resolver = new AwsS3ResolverFactory();
465
        $resolver->addConfiguration($rootNode);
466
467
        $config = $this->processConfigTree($treeBuilder, array(
468
            'aws_s3' => array(
469
                'bucket' => 'aBucket',
470
                'client_config' => array(),
471
            ),
472
        ));
473
474
        $this->assertArrayHasKey('acl', $config);
475
        $this->assertEquals($expectedAcl, $config['acl']);
476
477
        $this->assertArrayHasKey('url_options', $config);
478
        $this->assertEquals(array(), $config['url_options']);
479
480
        $this->assertArrayHasKey('get_options', $config);
481
        $this->assertEquals(array(), $config['get_options']);
482
483
        $this->assertArrayHasKey('cache_prefix', $config);
484
        $this->assertNull($config['cache_prefix']);
485
    }
486
487
    public function testSupportAwsV3ClientConfig()
488
    {
489
        $expectedClientConfig = array(
490
            'credentials' => array(
491
                'key' => 'theKey',
492
                'secret' => 'theSecret',
493
                'token' => 'theToken',
494
            ),
495
            'region' => 'theRegion',
496
            'version' => 'theVersion',
497
        );
498
        $expectedUrlOptions = array(
499
            'theKey' => 'theUrlOptionsVal',
500
            'theOtherKey' => 'theOtherUrlOptionsValue',
501
        );
502
        $expectedGetOptions = array(
503
            'theKey' => 'theGetOptionsVal',
504
            'theOtherKey' => 'theOtherGetOptionsValue',
505
        );
506
        $expectedObjectOptions = array(
507
            'theKey' => 'theObjectOptionsVal',
508
            'theOtherKey' => 'theOtherObjectOptionsValue',
509
        );
510
        $expectedBucket = 'theBucket';
511
        $expectedAcl = 'theAcl';
512
        $expectedCachePrefix = 'theCachePrefix';
513
514
        $treeBuilder = new TreeBuilder();
515
        $rootNode = $treeBuilder->root('aws_s3', 'array');
516
517
        $resolver = new AwsS3ResolverFactory();
518
        $resolver->addConfiguration($rootNode);
519
520
        $config = $this->processConfigTree($treeBuilder, array(
521
            'aws_s3' => array(
522
                'bucket' => $expectedBucket,
523
                'acl' => $expectedAcl,
524
                'client_config' => $expectedClientConfig,
525
                'url_options' => $expectedUrlOptions,
526
                'get_options' => $expectedGetOptions,
527
                'put_options' => $expectedObjectOptions,
528
                'cache_prefix' => $expectedCachePrefix,
529
            ),
530
        ));
531
532
        $this->assertArrayHasKey('bucket', $config);
533
        $this->assertEquals($expectedBucket, $config['bucket']);
534
535
        $this->assertArrayHasKey('acl', $config);
536
        $this->assertEquals($expectedAcl, $config['acl']);
537
538
        $this->assertArrayHasKey('client_config', $config);
539
        $this->assertEquals($expectedClientConfig, $config['client_config']);
540
541
        $this->assertArrayHasKey('url_options', $config);
542
        $this->assertEquals($expectedUrlOptions, $config['url_options']);
543
544
        $this->assertArrayHasKey('get_options', $config);
545
        $this->assertEquals($expectedGetOptions, $config['get_options']);
546
547
        $this->assertArrayHasKey('put_options', $config);
548
        $this->assertEquals($expectedObjectOptions, $config['put_options']);
549
550
        $this->assertArrayHasKey('cache_prefix', $config);
551
        $this->assertEquals($expectedCachePrefix, $config['cache_prefix']);
552
    }
553
554
    /**
555
     * @param TreeBuilder $treeBuilder
556
     * @param array       $configs
557
     *
558
     * @return array
559
     */
560
    protected function processConfigTree(TreeBuilder $treeBuilder, array $configs)
561
    {
562
        $processor = new Processor();
563
564
        return $processor->process($treeBuilder->buildTree(), $configs);
565
    }
566
}
567