|
11 | 11 |
|
12 | 12 | namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection; |
13 | 13 |
|
14 | | -use Symfony\Bundle\MonologBundle\Tests\TestCase; |
15 | 14 | use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension; |
16 | 15 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
17 | 16 | use Symfony\Component\DependencyInjection\Reference; |
18 | 17 |
|
19 | | -abstract class MonologExtensionTest extends TestCase |
| 18 | +class MonologExtensionTest extends DependencyInjectionTest |
20 | 19 | { |
21 | 20 | public function testLoadWithDefault() |
22 | 21 | { |
@@ -52,115 +51,6 @@ public function testLoadWithCustomValues() |
52 | 51 | $this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, false)); |
53 | 52 | } |
54 | 53 |
|
55 | | - public function testLoadWithSeveralHandlers() |
56 | | - { |
57 | | - $container = $this->getContainer('multiple_handlers'); |
58 | | - |
59 | | - $this->assertTrue($container->hasDefinition('monolog.logger')); |
60 | | - $this->assertTrue($container->hasDefinition('monolog.handler.custom')); |
61 | | - $this->assertTrue($container->hasDefinition('monolog.handler.main')); |
62 | | - $this->assertTrue($container->hasDefinition('monolog.handler.nested')); |
63 | | - |
64 | | - $logger = $container->getDefinition('monolog.logger'); |
65 | | - $this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', array(new Reference('monolog.handler.custom'))); |
66 | | - $this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.main'))); |
67 | | - |
68 | | - $handler = $container->getDefinition('monolog.handler.custom'); |
69 | | - $this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%'); |
70 | | - $this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, false)); |
71 | | - |
72 | | - $handler = $container->getDefinition('monolog.handler.main'); |
73 | | - $this->assertDICDefinitionClass($handler, '%monolog.handler.fingers_crossed.class%'); |
74 | | - $this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.nested'), \Monolog\Logger::ERROR, 0, true, true)); |
75 | | - } |
76 | | - |
77 | | - public function testLoadWithOverwriting() |
78 | | - { |
79 | | - $container = $this->getContainer('overwriting'); |
80 | | - |
81 | | - $this->assertTrue($container->hasDefinition('monolog.logger')); |
82 | | - $this->assertTrue($container->hasDefinition('monolog.handler.custom')); |
83 | | - $this->assertTrue($container->hasDefinition('monolog.handler.main')); |
84 | | - $this->assertTrue($container->hasDefinition('monolog.handler.nested')); |
85 | | - |
86 | | - $logger = $container->getDefinition('monolog.logger'); |
87 | | - $this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', array(new Reference('monolog.handler.custom'))); |
88 | | - $this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.main'))); |
89 | | - |
90 | | - $handler = $container->getDefinition('monolog.handler.custom'); |
91 | | - $this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%'); |
92 | | - $this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::WARNING, true)); |
93 | | - |
94 | | - $handler = $container->getDefinition('monolog.handler.main'); |
95 | | - $this->assertDICDefinitionClass($handler, '%monolog.handler.fingers_crossed.class%'); |
96 | | - $this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.nested'), \Monolog\Logger::ERROR, 0, true, true)); |
97 | | - } |
98 | | - |
99 | | - public function testLoadWithNewAtEnd() |
100 | | - { |
101 | | - $container = $this->getContainer('new_at_end'); |
102 | | - |
103 | | - $this->assertTrue($container->hasDefinition('monolog.logger')); |
104 | | - $this->assertTrue($container->hasDefinition('monolog.handler.custom')); |
105 | | - $this->assertTrue($container->hasDefinition('monolog.handler.main')); |
106 | | - $this->assertTrue($container->hasDefinition('monolog.handler.nested')); |
107 | | - $this->assertTrue($container->hasDefinition('monolog.handler.new')); |
108 | | - |
109 | | - $logger = $container->getDefinition('monolog.logger'); |
110 | | - $this->assertDICDefinitionMethodCallAt(2, $logger, 'pushHandler', array(new Reference('monolog.handler.new'))); |
111 | | - $this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', array(new Reference('monolog.handler.custom'))); |
112 | | - $this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.main'))); |
113 | | - |
114 | | - $handler = $container->getDefinition('monolog.handler.new'); |
115 | | - $this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%'); |
116 | | - $this->assertDICConstructorArguments($handler, array('/tmp/monolog.log', \Monolog\Logger::ERROR, true)); |
117 | | - } |
118 | | - |
119 | | - public function testLoadWithNewAndPriority() |
120 | | - { |
121 | | - $container = $this->getContainer('new_and_priority'); |
122 | | - |
123 | | - $this->assertTrue($container->hasDefinition('monolog.logger')); |
124 | | - $this->assertTrue($container->hasDefinition('monolog.handler.custom')); |
125 | | - $this->assertTrue($container->hasDefinition('monolog.handler.main')); |
126 | | - $this->assertTrue($container->hasDefinition('monolog.handler.nested')); |
127 | | - $this->assertTrue($container->hasDefinition('monolog.handler.first')); |
128 | | - $this->assertTrue($container->hasDefinition('monolog.handler.last')); |
129 | | - |
130 | | - $logger = $container->getDefinition('monolog.logger'); |
131 | | - $this->assertDICDefinitionMethodCallAt(2, $logger, 'pushHandler', array(new Reference('monolog.handler.last'))); |
132 | | - $this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', array(new Reference('monolog.handler.custom'))); |
133 | | - $this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.main'))); |
134 | | - $this->assertDICDefinitionMethodCallAt(2, $logger, 'pushHandler', array(new Reference('monolog.handler.first'))); |
135 | | - |
136 | | - $handler = $container->getDefinition('monolog.handler.main'); |
137 | | - $this->assertDICDefinitionClass($handler, '%monolog.handler.buffer.class%'); |
138 | | - $this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.nested'), 0, \Monolog\Logger::INFO, true)); |
139 | | - |
140 | | - $handler = $container->getDefinition('monolog.handler.first'); |
141 | | - $this->assertDICDefinitionClass($handler, '%monolog.handler.rotating_file.class%'); |
142 | | - $this->assertDICConstructorArguments($handler, array('/tmp/monolog.log', 0, \Monolog\Logger::ERROR, true)); |
143 | | - |
144 | | - $handler = $container->getDefinition('monolog.handler.last'); |
145 | | - $this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%'); |
146 | | - $this->assertDICConstructorArguments($handler, array('/tmp/last.log', \Monolog\Logger::ERROR, true)); |
147 | | - } |
148 | | - |
149 | | - public function testHandlersWithChannels() |
150 | | - { |
151 | | - $container = $this->getContainer('handlers_with_channels'); |
152 | | - |
153 | | - $this->assertEquals( |
154 | | - array( |
155 | | - 'monolog.handler.custom' => array('type' => 'inclusive', 'elements' => array('foo')), |
156 | | - 'monolog.handler.main' => array('type' => 'exclusive', 'elements' => array('foo', 'bar')), |
157 | | - 'monolog.handler.extra' => null, |
158 | | - 'monolog.handler.more' => array('type' => 'inclusive', 'elements' => array('security', 'doctrine')), |
159 | | - ), |
160 | | - $container->getParameter('monolog.handlers_to_channels') |
161 | | - ); |
162 | | - } |
163 | | - |
164 | 54 | /** |
165 | 55 | * @expectedException InvalidArgumentException |
166 | 56 | */ |
@@ -238,48 +128,4 @@ public function testExceptionWhenUsingDebugName() |
238 | 128 |
|
239 | 129 | $loader->load(array(array('handlers' => array('debug' => array('type' => 'stream')))), $container); |
240 | 130 | } |
241 | | - |
242 | | - protected function getContainer($fixture) |
243 | | - { |
244 | | - $container = new ContainerBuilder(); |
245 | | - $container->registerExtension(new MonologExtension()); |
246 | | - |
247 | | - $this->loadFixture($container, $fixture); |
248 | | - |
249 | | - $container->getCompilerPassConfig()->setOptimizationPasses(array()); |
250 | | - $container->getCompilerPassConfig()->setRemovingPasses(array()); |
251 | | - $container->compile(); |
252 | | - |
253 | | - return $container; |
254 | | - } |
255 | | - |
256 | | - abstract protected function loadFixture(ContainerBuilder $container, $fixture); |
257 | | - |
258 | | - /** |
259 | | - * Assertion on the Class of a DIC Service Definition. |
260 | | - * |
261 | | - * @param \Symfony\Component\DependencyInjection\Definition $definition |
262 | | - * @param string $expectedClass |
263 | | - */ |
264 | | - protected function assertDICDefinitionClass($definition, $expectedClass) |
265 | | - { |
266 | | - $this->assertEquals($expectedClass, $definition->getClass(), "Expected Class of the DIC Container Service Definition is wrong."); |
267 | | - } |
268 | | - |
269 | | - protected function assertDICConstructorArguments($definition, $args) |
270 | | - { |
271 | | - $this->assertEquals($args, $definition->getArguments(), "Expected and actual DIC Service constructor arguments of definition '".$definition->getClass()."' don't match."); |
272 | | - } |
273 | | - |
274 | | - protected function assertDICDefinitionMethodCallAt($pos, $definition, $methodName, array $params = null) |
275 | | - { |
276 | | - $calls = $definition->getMethodCalls(); |
277 | | - if (isset($calls[$pos][0])) { |
278 | | - $this->assertEquals($methodName, $calls[$pos][0], "Method '".$methodName."' is expected to be called at position $pos."); |
279 | | - |
280 | | - if ($params !== null) { |
281 | | - $this->assertEquals($params, $calls[$pos][1], "Expected parameters to methods '".$methodName."' do not match the actual parameters."); |
282 | | - } |
283 | | - } |
284 | | - } |
285 | 131 | } |
0 commit comments