4
4
5
5
namespace Bizkit \LoggableCommandBundle \Tests \DependencyInjection \Compiler ;
6
6
7
+ use Bizkit \LoggableCommandBundle \BizkitLoggableCommandBundle ;
7
8
use Bizkit \LoggableCommandBundle \DependencyInjection \Compiler \ExcludeMonologChannelPass ;
8
9
use Bizkit \LoggableCommandBundle \Tests \TestCase ;
10
+ use Symfony \Bundle \MonologBundle \MonologBundle ;
9
11
use Symfony \Component \DependencyInjection \ContainerBuilder ;
12
+ use Symfony \Component \HttpKernel \Bundle \BundleInterface ;
10
13
11
14
/**
12
15
* @covers \Bizkit\LoggableCommandBundle\DependencyInjection\Compiler\ExcludeMonologChannelPass
@@ -16,27 +19,52 @@ final class ExcludeMonologChannelPassTest extends TestCase
16
19
/**
17
20
* @dataProvider handlerChannels
18
21
*/
19
- public function testChannelIsExcludedWhenExpected (?array $ channels , array $ expectedChannels , array $ expectedLog ): void
22
+ public function testChannelIsExcludedWhenExpected (?array $ channels , ? array $ expectedChannels , array $ expectedLog ): void
20
23
{
21
24
$ container = new ContainerBuilder ();
22
- $ container ->setParameter ('bizkit_loggable_command.channel_name ' , ' channel_name ' );
23
- $ container ->setParameter ('monolog.handlers_to_channels ' , [ ' monolog.handler.foobar ' => $ channels ] );
25
+ $ container ->setParameter ('kernel.logs_dir ' , __DIR__ );
26
+ $ container ->setParameter ('kernel.environment ' , ' dev ' );
24
27
25
- (new ExcludeMonologChannelPass ())->process ($ container );
28
+ /** @var BundleInterface $bundle */
29
+ foreach ([new MonologBundle (), new BizkitLoggableCommandBundle ()] as $ bundle ) {
30
+ $ container ->registerExtension ($ extension = $ bundle ->getContainerExtension ());
31
+ $ bundle ->build ($ container );
32
+ $ container ->loadFromExtension ($ extension ->getAlias ());
33
+ }
26
34
27
- /** @var array<string, array{type: string, elements: list<string>}> $handlersToChannels */
35
+ $ container ->loadFromExtension ('monolog ' , [
36
+ 'handlers ' => [
37
+ 'foobar ' => [
38
+ 'type ' => 'stream ' ,
39
+ 'channels ' => $ channels ,
40
+ ],
41
+ ],
42
+ ]);
43
+
44
+ $ container ->compile ();
45
+
46
+ /** @var array<string, array{type: string, elements: list<string>}|null> $handlersToChannels */
28
47
$ handlersToChannels = $ container ->getParameter ('monolog.handlers_to_channels ' );
29
- $ this ->assertSame ($ expectedChannels , $ handlersToChannels ['monolog.handler.foobar ' ][ ' elements ' ] );
48
+ $ this ->assertSame ($ expectedChannels , $ handlersToChannels ['monolog.handler.foobar ' ]);
30
49
31
- $ this ->assertSame ($ expectedLog , $ container ->getCompiler ()->getLog ());
50
+ $ this ->assertSame ($ expectedLog , array_values (array_filter (
51
+ $ container ->getCompiler ()->getLog (),
52
+ function (string $ log ): bool {
53
+ return 0 === strpos ($ log , ExcludeMonologChannelPass::class);
54
+ }
55
+ )));
32
56
}
33
57
34
58
public function handlerChannels (): iterable
35
59
{
36
- $ log = sprintf ('%s: Excluded Monolog channel "channel_name " from the following exclusive handlers "foobar". ' , ExcludeMonologChannelPass::class);
60
+ $ log = sprintf ('%s: Excluded Monolog channel "loggable_output " from the following exclusive handlers "foobar". ' , ExcludeMonologChannelPass::class);
37
61
38
- yield 'Inclusive ' => [['type ' => 'inclusive ' , 'elements ' => ['foo ' , 'bar ' , 'baz ' ]], ['foo ' , 'bar ' , 'baz ' ], []];
39
- yield 'Exclusive without exception ' => [['type ' => 'exclusive ' , 'elements ' => ['foo ' , 'baz ' ]], ['foo ' , 'baz ' , 'channel_name ' ], [$ log ]];
40
- yield 'Exclusive with exception ' => [['type ' => 'exclusive ' , 'elements ' => ['foo ' , '!channel_name ' , 'baz ' ]], ['foo ' , 'baz ' ], []];
62
+ yield 'None ' => [null , ['type ' => 'exclusive ' , 'elements ' => ['loggable_output ' ]], [$ log ]];
63
+ yield 'Empty array ' => [[], ['type ' => 'exclusive ' , 'elements ' => ['loggable_output ' ]], [$ log ]];
64
+ yield 'Inclusive ' => [['app ' ], ['type ' => 'inclusive ' , 'elements ' => ['app ' ]], []];
65
+ yield 'Exclusive without exception ' => [['!event ' ], ['type ' => 'exclusive ' , 'elements ' => ['event ' , 'loggable_output ' ]], [$ log ]];
66
+ yield 'Exclusive with exception ' => [['!event ' , '!!loggable_output ' ], ['type ' => 'exclusive ' , 'elements ' => ['event ' ]], []];
67
+ yield 'Exclusive with only an exception ' => [['!!loggable_output ' ], null , []];
68
+ yield 'Explicitly excluded ' => [['!loggable_output ' ], ['type ' => 'exclusive ' , 'elements ' => ['loggable_output ' ]], []];
41
69
}
42
70
}
0 commit comments