|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Psr\Log\LoggerInterface;
|
16 |
| -use Symfony\Component\DependencyInjection\Reference; |
17 |
| -use Symfony\Component\DependencyInjection\Definition; |
18 |
| -use Symfony\Component\DependencyInjection\ContainerBuilder; |
19 | 16 | use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass;
|
20 | 17 | use Symfony\Component\Config\FileLocator;
|
| 18 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 19 | +use Symfony\Component\DependencyInjection\Definition; |
21 | 20 | use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
| 21 | +use Symfony\Component\DependencyInjection\Reference; |
22 | 22 |
|
23 | 23 | class LoggerChannelPassTest extends TestCase
|
24 | 24 | {
|
@@ -51,7 +51,22 @@ public function testProcess()
|
51 | 51 | }
|
52 | 52 | }
|
53 | 53 |
|
54 |
| - $this->assertNotNull($container->getDefinition('monolog.logger.manualchan')); |
| 54 | + $this->assertNotNull($container->getDefinition('monolog.logger.additional')); |
| 55 | + } |
| 56 | + |
| 57 | + public function testTypeHintedAliasesExistForEachChannel() |
| 58 | + { |
| 59 | + if (!\method_exists(ContainerBuilder::class, 'registerAliasForArgument')) { |
| 60 | + $this->markTestSkipped('Need DependencyInjection 4.2+ to register type-hinted aliases for channels.'); |
| 61 | + } |
| 62 | + |
| 63 | + $container = $this->getContainer(); |
| 64 | + $expectedChannels = ['test', 'foo', 'bar', 'additional']; |
| 65 | + |
| 66 | + foreach ($expectedChannels as $channelName) { |
| 67 | + $aliasName = LoggerInterface::class.' $' .$channelName.'Logger'; |
| 68 | + $this->assertTrue($container->hasAlias($aliasName), 'type-hinted alias should be exists for each logger channel'); |
| 69 | + } |
55 | 70 | }
|
56 | 71 |
|
57 | 72 | public function testProcessSetters()
|
@@ -166,7 +181,7 @@ private function getContainer()
|
166 | 181 | $container->setDefinition($name, $service);
|
167 | 182 | }
|
168 | 183 |
|
169 |
| - $container->setParameter('monolog.additional_channels', ['manualchan']); |
| 184 | + $container->setParameter('monolog.additional_channels', ['additional']); |
170 | 185 | $container->setParameter('monolog.handlers_to_channels', [
|
171 | 186 | 'monolog.handler.a' => [
|
172 | 187 | 'type' => 'inclusive',
|
@@ -202,7 +217,7 @@ private function getContainerWithSetter()
|
202 | 217 | $service->addMethodCall('setLogger', [new Reference('logger')]);
|
203 | 218 | $container->setDefinition('foo', $service);
|
204 | 219 |
|
205 |
| - $container->setParameter('monolog.additional_channels', ['manualchan']); |
| 220 | + $container->setParameter('monolog.additional_channels', ['additional']); |
206 | 221 | $container->setParameter('monolog.handlers_to_channels', []);
|
207 | 222 |
|
208 | 223 | $container->getCompilerPassConfig()->setOptimizationPasses([]);
|
|
0 commit comments