@@ -28,6 +28,28 @@ public function testProcess()
2828
2929 $ service = $ container ->getDefinition ('test ' );
3030 $ this ->assertEquals ('monolog.logger.test ' , (string ) $ service ->getArgument (1 ), '->process replaces the logger by the new one ' );
31+
32+
33+ // pushHandlers for service "test"
34+ $ expected = array (
35+ 'test ' => array ('monolog.handler.a ' , 'monolog.handler.b ' , 'monolog.handler.c ' ),
36+ 'foo ' => array ('monolog.handler.b ' ),
37+ 'bar ' => array ('monolog.handler.b ' , 'monolog.handler.c ' ),
38+ );
39+
40+ foreach ($ expected as $ serviceName => $ handlers ) {
41+ $ service = $ container ->getDefinition ($ serviceName );
42+ $ channel = $ container ->getDefinition ((string ) $ service ->getArgument (1 ));
43+
44+ $ calls = $ channel ->getMethodCalls ();
45+ $ this ->assertCount (count ($ handlers ), $ calls );
46+ foreach ($ handlers as $ i => $ handler ) {
47+ list ($ methodName , $ arguments ) = $ calls [$ i ];
48+ $ this ->assertEquals ('pushHandler ' , $ methodName );
49+ $ this ->assertCount (1 , $ arguments );
50+ $ this ->assertEquals ($ handler , (string ) $ arguments [0 ]);
51+ }
52+ }
3153 }
3254
3355 protected function getContainer ()
@@ -39,9 +61,29 @@ protected function getContainer()
3961 $ container ->set ('monolog.handler.test ' , new Definition ('%monolog.handler.null.class% ' , array (100 , false )));
4062 $ definition ->addMethodCall ('pushHandler ' , array (new Reference ('monolog.handler.test ' )));
4163
42- $ service = new Definition ('TestClass ' , array ('false ' , new Reference ('logger ' )));
43- $ service ->addTag ('monolog.logger ' , array ('channel ' => 'test ' ));
44- $ container ->setDefinition ('test ' , $ service );
64+ // Handlers
65+ $ container ->set ('monolog.handler.a ' , new Definition ('%monolog.handler.null.class% ' , array (100 , false )));
66+ $ container ->set ('monolog.handler.b ' , new Definition ('%monolog.handler.null.class% ' , array (100 , false )));
67+ $ container ->set ('monolog.handler.c ' , new Definition ('%monolog.handler.null.class% ' , array (100 , false )));
68+
69+ // Channels
70+ foreach (array ('test ' , 'foo ' , 'bar ' ) as $ name ) {
71+ $ service = new Definition ('TestClass ' , array ('false ' , new Reference ('logger ' )));
72+ $ service ->addTag ('monolog.logger ' , array ('channel ' => $ name ));
73+ $ container ->setDefinition ($ name , $ service );
74+ }
75+
76+ $ container ->setParameter ('monolog.handlers_to_channels ' , array (
77+ 'monolog.handler.a ' => array (
78+ 'type ' => 'inclusive ' ,
79+ 'elements ' => array ('test ' )
80+ ),
81+ 'monolog.handler.b ' => null ,
82+ 'monolog.handler.c ' => array (
83+ 'type ' => 'exclusive ' ,
84+ 'elements ' => array ('foo ' )
85+ )
86+ ));
4587
4688 $ container ->getCompilerPassConfig ()->setOptimizationPasses (array ());
4789 $ container ->getCompilerPassConfig ()->setRemovingPasses (array ());
0 commit comments