-
Notifications
You must be signed in to change notification settings - Fork 380
/
WebPathResolverFactoryTest.php
125 lines (97 loc) · 4.27 KB
/
WebPathResolverFactoryTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/*
* This file is part of the `liip/LiipImagineBundle` project.
*
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Liip\ImagineBundle\Tests\DependencyInjection\Factory\Resolver;
use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\ResolverFactoryInterface;
use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\WebPathResolverFactory;
use Liip\ImagineBundle\Utility\Framework\SymfonyFramework;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ChildDefinition;
/**
* @covers \Liip\ImagineBundle\DependencyInjection\Factory\Resolver\WebPathResolverFactory<extended>
*/
class WebPathResolverFactoryTest extends \PHPUnit\Framework\TestCase
{
public function testImplementsResolverFactoryInterface()
{
$rc = new \ReflectionClass(WebPathResolverFactory::class);
$this->assertTrue($rc->implementsInterface(ResolverFactoryInterface::class));
}
public function testCouldBeConstructedWithoutAnyArguments()
{
$loader = new WebPathResolverFactory();
$this->assertInstanceOf(WebPathResolverFactory::class, $loader);
}
public function testReturnExpectedName()
{
$resolver = new WebPathResolverFactory();
$this->assertEquals('web_path', $resolver->getName());
}
public function testCreateResolverDefinitionOnCreate()
{
$container = new ContainerBuilder();
$resolver = new WebPathResolverFactory();
$resolver->create($container, 'the_resolver_name', array(
'web_root' => 'theWebRoot',
'cache_prefix' => 'theCachePrefix',
));
$this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.the_resolver_name'));
$resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.the_resolver_name');
$this->assertInstanceOf(ChildDefinition::class, $resolverDefinition);
$this->assertEquals('liip_imagine.cache.resolver.prototype.web_path', $resolverDefinition->getParent());
$this->assertEquals('theWebRoot', $resolverDefinition->getArgument(2));
$this->assertEquals('theCachePrefix', $resolverDefinition->getArgument(3));
}
public function testProcessCorrectlyOptionsOnAddConfiguration()
{
$expectedWebPath = 'theWebPath';
$expectedCachePrefix = 'theCachePrefix';
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('web_path', 'array');
$resolver = new WebPathResolverFactory();
$resolver->addConfiguration($rootNode);
$config = $this->processConfigTree($treeBuilder, array(
'web_path' => array(
'web_root' => $expectedWebPath,
'cache_prefix' => $expectedCachePrefix,
),
));
$this->assertArrayHasKey('web_root', $config);
$this->assertEquals($expectedWebPath, $config['web_root']);
$this->assertArrayHasKey('cache_prefix', $config);
$this->assertEquals($expectedCachePrefix, $config['cache_prefix']);
}
public function testAddDefaultOptionsIfNotSetOnAddConfiguration()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('web_path', 'array');
$resolver = new WebPathResolverFactory();
$resolver->addConfiguration($rootNode);
$config = $this->processConfigTree($treeBuilder, array(
'web_path' => array(),
));
$this->assertArrayHasKey('web_root', $config);
$this->assertEquals(SymfonyFramework::getContainerResolvableRootWebPath(), $config['web_root']);
$this->assertArrayHasKey('cache_prefix', $config);
$this->assertEquals('media/cache', $config['cache_prefix']);
}
/**
* @param TreeBuilder $treeBuilder
* @param array $configs
*
* @return array
*/
protected function processConfigTree(TreeBuilder $treeBuilder, array $configs)
{
$processor = new Processor();
return $processor->process($treeBuilder->buildTree(), $configs);
}
}