|
12 | 12 |
|
13 | 13 | namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\DependencyInjection;
|
14 | 14 |
|
| 15 | +use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
15 | 16 | use Symfony\Cmf\Bundle\RoutingBundle\DependencyInjection\CmfRoutingExtension;
|
16 |
| -use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 17 | +use Symfony\Component\DependencyInjection\Reference; |
17 | 18 |
|
18 |
| -class CmfRoutingExtensionTest extends \PHPUnit_Framework_TestCase |
| 19 | +class CmfRoutingExtensionTest extends AbstractExtensionTestCase |
19 | 20 | {
|
20 |
| - |
21 |
| - /** |
22 |
| - * @param array $config |
23 |
| - * @return \Symfony\Component\DependencyInjection\ContainerBuilder |
24 |
| - */ |
25 |
| - protected function getBuilder(array $config = array()) |
| 21 | + protected function getContainerExtensions() |
26 | 22 | {
|
27 |
| - $builder = new ContainerBuilder(); |
28 |
| - |
29 |
| - $loader = new CmfRoutingExtension(); |
30 |
| - $loader->load($config, $builder); |
31 |
| - |
32 |
| - return $builder; |
| 23 | + return array( |
| 24 | + new CmfRoutingExtension(), |
| 25 | + ); |
33 | 26 | }
|
34 | 27 |
|
35 | 28 | public function testLoadDefault()
|
36 | 29 | {
|
37 |
| - |
38 |
| - $builder = $this->getBuilder( |
39 |
| - array( |
40 |
| - array( |
41 |
| - 'dynamic' => array( |
| 30 | + $this->load(array( |
| 31 | + 'dynamic' => array( |
| 32 | + 'enabled' => true, |
| 33 | + 'persistence' => array( |
| 34 | + 'phpcr' => array( |
42 | 35 | 'enabled' => true,
|
43 |
| - 'persistence' => array( |
44 |
| - 'phpcr' => array( |
45 |
| - 'enabled' => true, |
46 |
| - 'use_sonata_admin' => false, |
47 |
| - ), |
48 |
| - ), |
| 36 | + 'use_sonata_admin' => false, |
49 | 37 | ),
|
50 |
| - ) |
51 |
| - ) |
52 |
| - ); |
53 |
| - |
54 |
| - $this->assertTrue($builder->hasAlias('cmf_routing.route_provider')); |
55 |
| - $alias = $builder->getAlias('cmf_routing.route_provider'); |
56 |
| - $this->assertEquals('cmf_routing.phpcr_route_provider', $alias->__toString()); |
57 |
| - |
58 |
| - $this->assertTrue($builder->hasAlias('cmf_routing.content_repository')); |
59 |
| - $alias = $builder->getAlias('cmf_routing.content_repository'); |
60 |
| - $this->assertEquals('cmf_routing.phpcr_content_repository', $alias->__toString()); |
61 |
| - |
62 |
| - $this->assertTrue($builder->getParameter('cmf_routing.replace_symfony_router')); |
63 |
| - |
64 |
| - $this->assertTrue($builder->hasDefinition('cmf_routing.router')); |
65 |
| - $methodCalls = $builder->getDefinition('cmf_routing.router')->getMethodCalls(); |
66 |
| - $addMethodCalls = array_filter( |
67 |
| - $methodCalls, |
68 |
| - function ($call) { |
69 |
| - return 'add' == $call[0]; |
70 |
| - } |
71 |
| - ); |
72 |
| - |
73 |
| - $this->assertCount(1, $addMethodCalls); |
74 |
| - $addMethodCall = reset($addMethodCalls); |
75 |
| - |
76 |
| - $params = $addMethodCall[1]; |
77 |
| - $this->assertCount(2, $params); |
78 |
| - |
79 |
| - /** @var $reference \Symfony\Component\DependencyInjection\Reference */ |
80 |
| - list($reference, $priority) = $params; |
| 38 | + ), |
| 39 | + ), |
| 40 | + )); |
81 | 41 |
|
82 |
| - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $reference); |
83 |
| - $this->assertEquals(100, $priority); |
| 42 | + $this->assertContainerBuilderHasAlias('cmf_routing.route_provider', 'cmf_routing.phpcr_route_provider'); |
| 43 | + $this->assertContainerBuilderHasAlias('cmf_routing.content_repository', 'cmf_routing.phpcr_content_repository'); |
84 | 44 |
|
85 |
| - $this->assertEquals('router.default', $reference->__toString()); |
| 45 | + $this->assertContainerBuilderHasParameter('cmf_routing.replace_symfony_router', true); |
86 | 46 |
|
| 47 | + $this->assertContainerBuilderHasService('cmf_routing.router', '%cmf_routing.chain_router.class%'); |
| 48 | + $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('cmf_routing.router', 'add', array( |
| 49 | + new Reference('router.default'), |
| 50 | + 100, |
| 51 | + )); |
87 | 52 | }
|
88 | 53 |
|
89 | 54 | public function testLoadConfigured()
|
90 | 55 | {
|
91 |
| - $config = array( |
92 |
| - array( |
93 |
| - 'dynamic' => array( |
94 |
| - 'enabled' => true, |
95 |
| - 'route_provider_service_id' => 'test_route_provider_service', |
96 |
| - 'content_repository_service_id' => 'test_content_repository_service', |
97 |
| - 'persistence' => array( |
98 |
| - 'phpcr' => array( |
99 |
| - 'use_sonata_admin' => false, |
100 |
| - ), |
| 56 | + $this->load(array( |
| 57 | + 'dynamic' => array( |
| 58 | + 'enabled' => true, |
| 59 | + 'route_provider_service_id' => 'test_route_provider_service', |
| 60 | + 'content_repository_service_id' => 'test_content_repository_service', |
| 61 | + 'persistence' => array( |
| 62 | + 'phpcr' => array( |
| 63 | + 'use_sonata_admin' => false, |
101 | 64 | ),
|
102 | 65 | ),
|
103 |
| - 'chain' => array( |
104 |
| - 'routers_by_id' => $providedRouters = array( |
105 |
| - 'router.custom' => 200, |
106 |
| - 'router.default' => 300 |
107 |
| - ) |
| 66 | + ), |
| 67 | + 'chain' => array( |
| 68 | + 'routers_by_id' => array( |
| 69 | + 'router.custom' => 200, |
| 70 | + 'router.default' => 300 |
108 | 71 | )
|
109 | 72 | )
|
110 |
| - ); |
111 |
| - |
112 |
| - $builder = $this->getBuilder($config); |
113 |
| - |
114 |
| - $this->assertTrue($builder->hasAlias('cmf_routing.route_provider')); |
115 |
| - $alias = $builder->getAlias('cmf_routing.route_provider'); |
116 |
| - $this->assertEquals('test_route_provider_service', $alias->__toString()); |
117 |
| - |
118 |
| - $this->assertTrue($builder->hasAlias('cmf_routing.content_repository')); |
119 |
| - $alias = $builder->getAlias('cmf_routing.content_repository'); |
120 |
| - $this->assertEquals('test_content_repository_service', $alias->__toString()); |
121 |
| - |
122 |
| - $this->assertTrue($builder->hasDefinition('cmf_routing.router')); |
123 |
| - $methodCalls = $builder->getDefinition('cmf_routing.router')->getMethodCalls(); |
124 |
| - $addMethodCalls = array_filter( |
125 |
| - $methodCalls, |
126 |
| - function ($call) { |
127 |
| - return 'add' == $call[0]; |
128 |
| - } |
129 |
| - ); |
130 |
| - |
131 |
| - $this->assertCount(2, $addMethodCalls); |
132 |
| - |
133 |
| - $routersAdded = array(); |
134 |
| - |
135 |
| - foreach ($addMethodCalls as $addMethodCall) { |
136 |
| - $params = $addMethodCall[1]; |
137 |
| - $this->assertCount(2, $params); |
138 |
| - /** @var $reference \Symfony\Component\DependencyInjection\Reference */ |
139 |
| - list($reference, $priority) = $params; |
140 |
| - |
141 |
| - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $reference); |
142 |
| - |
143 |
| - $routersAdded[$reference->__toString()] = $priority; |
144 |
| - } |
145 |
| - |
146 |
| - $this->assertEquals($providedRouters, $routersAdded); |
| 73 | + )); |
| 74 | + |
| 75 | + $this->assertContainerBuilderHasAlias('cmf_routing.route_provider', 'test_route_provider_service'); |
| 76 | + $this->assertContainerBuilderHasAlias('cmf_routing.content_repository', 'test_content_repository_service'); |
| 77 | + |
| 78 | + $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('cmf_routing.router', 'add', array( |
| 79 | + new Reference('router.custom'), |
| 80 | + 200, |
| 81 | + )); |
| 82 | + $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('cmf_routing.router', 'add', array( |
| 83 | + new Reference('router.default'), |
| 84 | + 300, |
| 85 | + )); |
147 | 86 | }
|
148 | 87 |
|
149 | 88 | public function testWhitespaceInPriorities()
|
150 | 89 | {
|
151 |
| - $config = array( |
152 |
| - array( |
153 |
| - 'dynamic' => array( |
154 |
| - 'route_provider_service_id' => 'test_route_provider_service', |
155 |
| - 'enabled' => true, |
156 |
| - 'controllers_by_type' => array( |
157 |
| - 'Acme\Foo' => ' |
158 |
| - acme_main.controller:indexAction |
159 |
| - ' |
160 |
| - ), |
| 90 | + $this->load(array( |
| 91 | + 'dynamic' => array( |
| 92 | + 'route_provider_service_id' => 'test_route_provider_service', |
| 93 | + 'enabled' => true, |
| 94 | + 'controllers_by_type' => array( |
| 95 | + 'Acme\Foo' => ' |
| 96 | + acme_main.controller:indexAction |
| 97 | + ' |
161 | 98 | ),
|
162 |
| - 'chain' => array( |
163 |
| - 'routers_by_id' => array( |
164 |
| - 'acme_test.router' => ' |
165 |
| - 100 |
166 |
| - ', |
167 |
| - ), |
| 99 | + ), |
| 100 | + 'chain' => array( |
| 101 | + 'routers_by_id' => array( |
| 102 | + 'acme_test.router' => ' |
| 103 | + 100 |
| 104 | + ', |
168 | 105 | ),
|
169 |
| - ) |
170 |
| - ); |
171 |
| - |
172 |
| - $builder = $this->getBuilder($config); |
173 |
| - |
174 |
| - $methodCalls = $builder->getDefinition('cmf_routing.router')->getMethodCalls(); |
175 |
| - $addMethodCalls = array_filter( |
176 |
| - $methodCalls, |
177 |
| - function ($call) { |
178 |
| - return 'add' == $call[0]; |
179 |
| - } |
180 |
| - ); |
181 |
| - |
182 |
| - $this->assertCount(1, $addMethodCalls); |
183 |
| - |
184 |
| - $methodCall = current($addMethodCalls); |
| 106 | + ), |
| 107 | + )); |
185 | 108 |
|
186 |
| - $this->assertSame('100', $methodCall[1][1]); |
| 109 | + $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('cmf_routing.router', 'add', array( |
| 110 | + new Reference('acme_test.router'), |
| 111 | + 100 |
| 112 | + )); |
187 | 113 |
|
188 |
| - $controllers = $builder->getParameter('cmf_routing.controllers_by_type'); |
189 |
| - $this->assertSame('acme_main.controller:indexAction', $controllers['Acme\Foo']); |
| 114 | + $this->assertContainerBuilderHasParameter('cmf_routing.controllers_by_type', array( |
| 115 | + 'Acme\Foo' => 'acme_main.controller:indexAction', |
| 116 | + )); |
190 | 117 | }
|
191 | 118 | }
|
0 commit comments