|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Liip\ImagineBundle\Tests\DependencyInjection\Factory\Resolver; |
|
4
|
|
|
|
|
5
|
|
|
use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\WebPathResolverFactory; |
|
6
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
7
|
|
|
use Symfony\Component\Config\Definition\Processor; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @covers Liip\ImagineBundle\DependencyInjection\Factory\Resolver\WebPathResolverFactory<extended> |
|
12
|
|
|
*/ |
|
13
|
|
|
class WebPathResolverFactoryTest extends \Phpunit_Framework_TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
public function testImplementsResolverFactoryInterface() |
|
16
|
|
|
{ |
|
17
|
|
|
$rc = new \ReflectionClass('Liip\ImagineBundle\DependencyInjection\Factory\Resolver\WebPathResolverFactory'); |
|
18
|
|
|
|
|
19
|
|
|
$this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\DependencyInjection\Factory\Resolver\ResolverFactoryInterface')); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testCouldBeConstructedWithoutAnyArguments() |
|
23
|
|
|
{ |
|
24
|
|
|
new WebPathResolverFactory(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testReturnExpectedName() |
|
28
|
|
|
{ |
|
29
|
|
|
$resolver = new WebPathResolverFactory(); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertEquals('web_path', $resolver->getName()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
View Code Duplication |
public function testCreateResolverDefinitionOnCreate() |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
$container = new ContainerBuilder(); |
|
37
|
|
|
|
|
38
|
|
|
$resolver = new WebPathResolverFactory(); |
|
39
|
|
|
|
|
40
|
|
|
$resolver->create($container, 'theResolverName', array( |
|
41
|
|
|
'web_root' => 'theWebRoot', |
|
42
|
|
|
'cache_prefix' => 'theCachePrefix', |
|
43
|
|
|
)); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername')); |
|
46
|
|
|
|
|
47
|
|
|
$resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername'); |
|
48
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\DefinitionDecorator', $resolverDefinition); |
|
49
|
|
|
$this->assertEquals('liip_imagine.cache.resolver.prototype.web_path', $resolverDefinition->getParent()); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertEquals('theWebRoot', $resolverDefinition->getArgument(2)); |
|
52
|
|
|
$this->assertEquals('theCachePrefix', $resolverDefinition->getArgument(3)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
View Code Duplication |
public function testProcessCorrectlyOptionsOnAddConfiguration() |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
$expectedWebPath = 'theWebPath'; |
|
58
|
|
|
$expectedCachePrefix = 'theCachePrefix'; |
|
59
|
|
|
|
|
60
|
|
|
$treeBuilder = new TreeBuilder(); |
|
61
|
|
|
$rootNode = $treeBuilder->root('web_path', 'array'); |
|
62
|
|
|
|
|
63
|
|
|
$resolver = new WebPathResolverFactory(); |
|
64
|
|
|
$resolver->addConfiguration($rootNode); |
|
65
|
|
|
|
|
66
|
|
|
$config = $this->processConfigTree($treeBuilder, array( |
|
67
|
|
|
'web_path' => array( |
|
68
|
|
|
'web_root' => $expectedWebPath, |
|
69
|
|
|
'cache_prefix' => $expectedCachePrefix, |
|
70
|
|
|
), |
|
71
|
|
|
)); |
|
72
|
|
|
|
|
73
|
|
|
$this->assertArrayHasKey('web_root', $config); |
|
74
|
|
|
$this->assertEquals($expectedWebPath, $config['web_root']); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertArrayHasKey('cache_prefix', $config); |
|
77
|
|
|
$this->assertEquals($expectedCachePrefix, $config['cache_prefix']); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testAddDefaultOptionsIfNotSetOnAddConfiguration() |
|
81
|
|
|
{ |
|
82
|
|
|
$treeBuilder = new TreeBuilder(); |
|
83
|
|
|
$rootNode = $treeBuilder->root('web_path', 'array'); |
|
84
|
|
|
|
|
85
|
|
|
$resolver = new WebPathResolverFactory(); |
|
86
|
|
|
$resolver->addConfiguration($rootNode); |
|
87
|
|
|
|
|
88
|
|
|
$config = $this->processConfigTree($treeBuilder, array( |
|
89
|
|
|
'web_path' => array(), |
|
90
|
|
|
)); |
|
91
|
|
|
|
|
92
|
|
|
$this->assertArrayHasKey('web_root', $config); |
|
93
|
|
|
$this->assertEquals('%kernel.root_dir%/../web', $config['web_root']); |
|
94
|
|
|
|
|
95
|
|
|
$this->assertArrayHasKey('cache_prefix', $config); |
|
96
|
|
|
$this->assertEquals('media/cache', $config['cache_prefix']); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param TreeBuilder $treeBuilder |
|
101
|
|
|
* @param array $configs |
|
102
|
|
|
* |
|
103
|
|
|
* @return array |
|
104
|
|
|
*/ |
|
105
|
|
|
protected function processConfigTree(TreeBuilder $treeBuilder, array $configs) |
|
106
|
|
|
{ |
|
107
|
|
|
$processor = new Processor(); |
|
108
|
|
|
|
|
109
|
|
|
return $processor->process($treeBuilder->buildTree(), $configs); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
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.