|
15 | 15 | use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; |
16 | 16 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
17 | 17 | use Symfony\Component\DependencyInjection\Reference; |
| 18 | +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
18 | 19 |
|
19 | 20 | class MonologExtensionTest extends DependencyInjectionTest |
20 | 21 | { |
@@ -140,6 +141,34 @@ public function testSyslogHandlerWithLogopts() |
140 | 141 | $this->assertDICConstructorArguments($handler, array(false, 'user', \Monolog\Logger::DEBUG, true, LOG_CONS)); |
141 | 142 | } |
142 | 143 |
|
| 144 | + public function testSocketHandler() |
| 145 | + { |
| 146 | + try { |
| 147 | + $this->getContainer(array(array('handlers' => array('socket' => array('type' => 'socket'))))); |
| 148 | + $this->fail(); |
| 149 | + } catch (InvalidConfigurationException $e) { |
| 150 | + $this->assertContains('connection_string', $e->getMessage()); |
| 151 | + } |
| 152 | + |
| 153 | + $container = $this->getContainer(array(array('handlers' => array('socket' => array( |
| 154 | + 'type' => 'socket', 'timeout' => 1, 'persistent' => true, |
| 155 | + 'connection_string' => 'localhost:50505', 'connection_timeout' => '0.6') |
| 156 | + )))); |
| 157 | + $this->assertTrue($container->hasDefinition('monolog.logger')); |
| 158 | + $this->assertTrue($container->hasDefinition('monolog.handler.socket')); |
| 159 | + |
| 160 | + $logger = $container->getDefinition('monolog.logger'); |
| 161 | + $this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.socket'))); |
| 162 | + |
| 163 | + $handler = $container->getDefinition('monolog.handler.socket'); |
| 164 | + $this->assertDICDefinitionClass($handler, '%monolog.handler.socket.class%'); |
| 165 | + $this->assertDICConstructorArguments($handler, array('localhost:50505', \Monolog\Logger::DEBUG, true)); |
| 166 | + $this->assertDICDefinitionMethodCallAt(0, $handler, 'setTimeout', array('1')); |
| 167 | + $this->assertDICDefinitionMethodCallAt(1, $handler, 'setConnectionTimeout', array('0.6')); |
| 168 | + $this->assertDICDefinitionMethodCallAt(2, $handler, 'setPersistent', array(true)); |
| 169 | + |
| 170 | + } |
| 171 | + |
143 | 172 | protected function getContainer(array $config = array()) |
144 | 173 | { |
145 | 174 | $container = new ContainerBuilder(); |
|
0 commit comments