1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Liip\ImagineBundle\Tests\DependencyInjection\Factory\Loader; |
4
|
|
|
|
5
|
|
|
use Liip\ImagineBundle\DependencyInjection\Factory\Loader\FlysystemLoaderFactory; |
6
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
7
|
|
|
use Symfony\Component\Config\Definition\Processor; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @requires PHP 5.4 |
12
|
|
|
* @covers Liip\ImagineBundle\DependencyInjection\Factory\Loader\FlysystemLoaderFactory<extended> |
13
|
|
|
*/ |
14
|
|
|
class FlysystemLoaderFactoryTest extends \Phpunit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
public function setUp() |
17
|
|
|
{ |
18
|
|
|
parent::setUp(); |
19
|
|
|
|
20
|
|
|
if (!class_exists('\League\Flysystem\Filesystem')) { |
21
|
|
|
$this->markTestSkipped( |
22
|
|
|
'The league/flysystem PHP library is not available.' |
23
|
|
|
); |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testImplementsLoaderFactoryInterface() |
28
|
|
|
{ |
29
|
|
|
$rc = new \ReflectionClass('Liip\ImagineBundle\DependencyInjection\Factory\Loader\FlysystemLoaderFactory'); |
30
|
|
|
|
31
|
|
|
$this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\DependencyInjection\Factory\Loader\LoaderFactoryInterface')); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testCouldBeConstructedWithoutAnyArguments() |
35
|
|
|
{ |
36
|
|
|
new FlysystemLoaderFactory(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testReturnExpectedName() |
40
|
|
|
{ |
41
|
|
|
$loader = new FlysystemLoaderFactory(); |
42
|
|
|
|
43
|
|
|
$this->assertEquals('flysystem', $loader->getName()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
View Code Duplication |
public function testCreateLoaderDefinitionOnCreate() |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$container = new ContainerBuilder(); |
49
|
|
|
|
50
|
|
|
$loader = new FlysystemLoaderFactory(); |
51
|
|
|
|
52
|
|
|
$loader->create($container, 'theLoaderName', array( |
53
|
|
|
'filesystem_service' => 'flyfilesystemservice', |
54
|
|
|
)); |
55
|
|
|
|
56
|
|
|
$this->assertTrue($container->hasDefinition('liip_imagine.binary.loader.theloadername')); |
57
|
|
|
|
58
|
|
|
$loaderDefinition = $container->getDefinition('liip_imagine.binary.loader.theloadername'); |
59
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $loaderDefinition); |
60
|
|
|
$this->assertEquals('liip_imagine.binary.loader.prototype.flysystem', $loaderDefinition->getParent()); |
61
|
|
|
|
62
|
|
|
$reference = $loaderDefinition->getArgument(1); |
63
|
|
|
$this->assertEquals('flyfilesystemservice', "$reference"); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
68
|
|
|
* @expectedExceptionMessage The child node "filesystem_service" at path "flysystem" must be configured. |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
public function testThrowIfFileSystemServiceNotSetOnAddConfiguration() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$treeBuilder = new TreeBuilder(); |
73
|
|
|
$rootNode = $treeBuilder->root('flysystem', 'array'); |
74
|
|
|
|
75
|
|
|
$resolver = new FlysystemLoaderFactory(); |
76
|
|
|
$resolver->addConfiguration($rootNode); |
77
|
|
|
|
78
|
|
|
$this->processConfigTree($treeBuilder, array()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
View Code Duplication |
public function testProcessCorrectlyOptionsOnAddConfiguration() |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
$expectedService = 'theService'; |
84
|
|
|
|
85
|
|
|
$treeBuilder = new TreeBuilder(); |
86
|
|
|
$rootNode = $treeBuilder->root('flysystem', 'array'); |
87
|
|
|
|
88
|
|
|
$loader = new FlysystemLoaderFactory(); |
89
|
|
|
$loader->addConfiguration($rootNode); |
90
|
|
|
|
91
|
|
|
$config = $this->processConfigTree($treeBuilder, array( |
92
|
|
|
'flysystem' => array( |
93
|
|
|
'filesystem_service' => $expectedService, |
94
|
|
|
), |
95
|
|
|
)); |
96
|
|
|
|
97
|
|
|
$this->assertArrayHasKey('filesystem_service', $config); |
98
|
|
|
$this->assertEquals($expectedService, $config['filesystem_service']); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param TreeBuilder $treeBuilder |
103
|
|
|
* @param array $configs |
104
|
|
|
* |
105
|
|
|
* @return array |
106
|
|
|
*/ |
107
|
|
|
protected function processConfigTree(TreeBuilder $treeBuilder, array $configs) |
108
|
|
|
{ |
109
|
|
|
$processor = new Processor(); |
110
|
|
|
|
111
|
|
|
return $processor->process($treeBuilder->buildTree(), $configs); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
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.