@@ -20,7 +20,6 @@ class MonologExtensionTest extends TestCase
2020{
2121 public function testLoadWithDefault ()
2222 {
23- // logger
2423 $ container = new ContainerBuilder ();
2524 $ loader = new MonologExtension ();
2625
@@ -38,7 +37,6 @@ public function testLoadWithDefault()
3837
3938 public function testLoadWithCustomValues ()
4039 {
41- // logger
4240 $ container = new ContainerBuilder ();
4341 $ loader = new MonologExtension ();
4442
@@ -56,13 +54,12 @@ public function testLoadWithCustomValues()
5654
5755 public function testLoadWithSeveralHandlers ()
5856 {
59- // logger
6057 $ container = new ContainerBuilder ();
6158 $ loader = new MonologExtension ();
6259
6360 $ loader ->load (array (array ('handlers ' => array (
6461 'custom ' => array ('type ' => 'stream ' , 'path ' => '/tmp/symfony.log ' , 'bubble ' => true , 'level ' => 'ERROR ' ),
65- 'main ' => array ('type ' => 'fingerscrossed ' , 'action_level ' => 'ERROR ' , 'handler ' => 'nested ' ),
62+ 'main ' => array ('type ' => 'fingers_crossed ' , 'action_level ' => 'ERROR ' , 'handler ' => 'nested ' ),
6663 'nested ' => array ('type ' => 'stream ' )
6764 ))), $ container );
6865 $ this ->assertTrue ($ container ->hasDefinition ('monolog.logger ' ));
@@ -79,10 +76,151 @@ public function testLoadWithSeveralHandlers()
7976 $ this ->assertDICConstructorArguments ($ handler , array ('/tmp/symfony.log ' , \Monolog \Logger::ERROR , true ));
8077
8178 $ handler = $ container ->getDefinition ('monolog.handler.main ' );
82- $ this ->assertDICDefinitionClass ($ handler , '%monolog.handler.fingerscrossed .class% ' );
79+ $ this ->assertDICDefinitionClass ($ handler , '%monolog.handler.fingers_crossed .class% ' );
8380 $ this ->assertDICConstructorArguments ($ handler , array (new Reference ('monolog.handler.nested ' ), \Monolog \Logger::ERROR , 0 , false ));
8481 }
8582
83+ public function testLoadWithOverwriting ()
84+ {
85+ $ container = new ContainerBuilder ();
86+ $ loader = new MonologExtension ();
87+
88+ $ loader ->load (array (
89+ array ('handlers ' => array (
90+ 'custom ' => array ('type ' => 'stream ' , 'path ' => '/tmp/symfony.log ' , 'bubble ' => true , 'level ' => 'ERROR ' ),
91+ 'main ' => array ('type ' => 'fingers_crossed ' , 'action_level ' => 'ERROR ' , 'handler ' => 'nested ' ),
92+ 'nested ' => array ('type ' => 'stream ' )
93+ )),
94+ array ('handlers ' => array (
95+ 'custom ' => array ('type ' => 'stream ' , 'path ' => '/tmp/symfony.log ' , 'bubble ' => true , 'level ' => 'WARNING ' ),
96+ ))
97+ ), $ container );
98+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.logger ' ));
99+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.custom ' ));
100+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.main ' ));
101+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.nested ' ));
102+
103+ $ logger = $ container ->getDefinition ('monolog.logger ' );
104+ $ this ->assertDICDefinitionMethodCallAt (1 , $ logger , 'pushHandler ' , array (new Reference ('monolog.handler.custom ' )));
105+ $ this ->assertDICDefinitionMethodCallAt (0 , $ logger , 'pushHandler ' , array (new Reference ('monolog.handler.main ' )));
106+
107+ $ handler = $ container ->getDefinition ('monolog.handler.custom ' );
108+ $ this ->assertDICDefinitionClass ($ handler , '%monolog.handler.stream.class% ' );
109+ $ this ->assertDICConstructorArguments ($ handler , array ('/tmp/symfony.log ' , \Monolog \Logger::WARNING , true ));
110+
111+ $ handler = $ container ->getDefinition ('monolog.handler.main ' );
112+ $ this ->assertDICDefinitionClass ($ handler , '%monolog.handler.fingers_crossed.class% ' );
113+ $ this ->assertDICConstructorArguments ($ handler , array (new Reference ('monolog.handler.nested ' ), \Monolog \Logger::ERROR , 0 , false ));
114+ }
115+
116+ public function testLoadWithNewAtEnd ()
117+ {
118+ $ container = new ContainerBuilder ();
119+ $ loader = new MonologExtension ();
120+
121+ $ loader ->load (array (
122+ array ('handlers ' => array (
123+ 'custom ' => array ('type ' => 'stream ' , 'path ' => '/tmp/symfony.log ' , 'bubble ' => true , 'level ' => 'ERROR ' ),
124+ 'main ' => array ('type ' => 'fingers_crossed ' , 'action_level ' => 'ERROR ' , 'handler ' => 'nested ' ),
125+ 'nested ' => array ('type ' => 'stream ' )
126+ )),
127+ array ('handlers ' => array (
128+ 'custom ' => array ('type ' => 'stream ' , 'path ' => '/tmp/symfony.log ' , 'bubble ' => true , 'level ' => 'WARNING ' ),
129+ 'new ' => array ('type ' => 'stream ' , 'path ' => '/tmp/monolog.log ' , 'bubble ' => true , 'level ' => 'ERROR ' ),
130+ ))
131+ ), $ container );
132+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.logger ' ));
133+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.custom ' ));
134+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.main ' ));
135+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.nested ' ));
136+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.new ' ));
137+
138+ $ logger = $ container ->getDefinition ('monolog.logger ' );
139+ $ this ->assertDICDefinitionMethodCallAt (2 , $ logger , 'pushHandler ' , array (new Reference ('monolog.handler.new ' )));
140+ $ this ->assertDICDefinitionMethodCallAt (1 , $ logger , 'pushHandler ' , array (new Reference ('monolog.handler.custom ' )));
141+ $ this ->assertDICDefinitionMethodCallAt (0 , $ logger , 'pushHandler ' , array (new Reference ('monolog.handler.main ' )));
142+
143+ $ handler = $ container ->getDefinition ('monolog.handler.new ' );
144+ $ this ->assertDICDefinitionClass ($ handler , '%monolog.handler.stream.class% ' );
145+ $ this ->assertDICConstructorArguments ($ handler , array ('/tmp/monolog.log ' , \Monolog \Logger::ERROR , true ));
146+ }
147+
148+ public function testLoadWithNewAndPriority ()
149+ {
150+ $ container = new ContainerBuilder ();
151+ $ loader = new MonologExtension ();
152+
153+ $ loader ->load (array (
154+ array ('handlers ' => array (
155+ 'custom ' => array ('type ' => 'stream ' , 'path ' => '/tmp/symfony.log ' , 'bubble ' => true , 'level ' => 'ERROR ' ),
156+ 'main ' => array ('type ' => 'buffer ' , 'level ' => 'INFO ' , 'handler ' => 'nested ' ),
157+ 'nested ' => array ('type ' => 'stream ' )
158+ )),
159+ array ('handlers ' => array (
160+ 'custom ' => array ('type ' => 'stream ' , 'path ' => '/tmp/symfony.log ' , 'bubble ' => true , 'level ' => 'WARNING ' ),
161+ 'first ' => array ('type ' => 'rotating_file ' , 'path ' => '/tmp/monolog.log ' , 'bubble ' => true , 'level ' => 'ERROR ' , 'priority ' => 3 ),
162+ 'last ' => array ('type ' => 'stream ' , 'path ' => '/tmp/last.log ' , 'bubble ' => true , 'level ' => 'ERROR ' , 'priority ' => -3 ),
163+ ))
164+ ), $ container );
165+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.logger ' ));
166+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.custom ' ));
167+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.main ' ));
168+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.nested ' ));
169+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.first ' ));
170+ $ this ->assertTrue ($ container ->hasDefinition ('monolog.handler.last ' ));
171+
172+ $ logger = $ container ->getDefinition ('monolog.logger ' );
173+ $ this ->assertDICDefinitionMethodCallAt (2 , $ logger , 'pushHandler ' , array (new Reference ('monolog.handler.last ' )));
174+ $ this ->assertDICDefinitionMethodCallAt (1 , $ logger , 'pushHandler ' , array (new Reference ('monolog.handler.custom ' )));
175+ $ this ->assertDICDefinitionMethodCallAt (0 , $ logger , 'pushHandler ' , array (new Reference ('monolog.handler.main ' )));
176+ $ this ->assertDICDefinitionMethodCallAt (2 , $ logger , 'pushHandler ' , array (new Reference ('monolog.handler.first ' )));
177+
178+ $ handler = $ container ->getDefinition ('monolog.handler.main ' );
179+ $ this ->assertDICDefinitionClass ($ handler , '%monolog.handler.buffer.class% ' );
180+ $ this ->assertDICConstructorArguments ($ handler , array (new Reference ('monolog.handler.nested ' ), 0 , \Monolog \Logger::INFO , false ));
181+
182+ $ handler = $ container ->getDefinition ('monolog.handler.first ' );
183+ $ this ->assertDICDefinitionClass ($ handler , '%monolog.handler.rotating_file.class% ' );
184+ $ this ->assertDICConstructorArguments ($ handler , array ('/tmp/monolog.log ' , 0 , \Monolog \Logger::ERROR , true ));
185+
186+ $ handler = $ container ->getDefinition ('monolog.handler.last ' );
187+ $ this ->assertDICDefinitionClass ($ handler , '%monolog.handler.stream.class% ' );
188+ $ this ->assertDICConstructorArguments ($ handler , array ('/tmp/last.log ' , \Monolog \Logger::ERROR , true ));
189+ }
190+
191+ /**
192+ * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
193+ */
194+ public function testExceptionWhenUsingFingerscrossedWithoutHandler ()
195+ {
196+ $ container = new ContainerBuilder ();
197+ $ loader = new MonologExtension ();
198+
199+ $ loader ->load (array (array ('handlers ' => array ('main ' => array ('type ' => 'fingers_crossed ' )))), $ container );
200+ }
201+
202+ /**
203+ * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
204+ */
205+ public function testExceptionWhenUsingBufferWithoutHandler ()
206+ {
207+ $ container = new ContainerBuilder ();
208+ $ loader = new MonologExtension ();
209+
210+ $ loader ->load (array (array ('handlers ' => array ('main ' => array ('type ' => 'buffer ' )))), $ container );
211+ }
212+
213+ /**
214+ * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
215+ */
216+ public function testExceptionWhenUsingServiceWithoutId ()
217+ {
218+ $ container = new ContainerBuilder ();
219+ $ loader = new MonologExtension ();
220+
221+ $ loader ->load (array (array ('handlers ' => array ('main ' => array ('type ' => 'service ' )))), $ container );
222+ }
223+
86224 /**
87225 * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
88226 */
0 commit comments