Skip to content

Commit 6193c38

Browse files
committed
added config test and fix case with numeric log level
1 parent 10ea9b0 commit 6193c38

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

DependencyInjection/Configuration.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function getConfigTreeBuilder()
158158
$verbosity
159159
));
160160
}
161-
if (!is_int($level)) {
161+
if (!is_numeric($level)) {
162162
$levelConstant = 'Monolog\Logger::'.$level;
163163
if (!defined($levelConstant)) {
164164
throw new InvalidConfigurationException(sprintf(
@@ -167,6 +167,8 @@ public function getConfigTreeBuilder()
167167
));
168168
}
169169
$level = constant($levelConstant);
170+
} else {
171+
$level = (int) $level;
170172
}
171173

172174
$map[constant($verbosityConstant)] = $level;

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection;
1313

14+
use Monolog\Logger;
1415
use Symfony\Bundle\MonologBundle\DependencyInjection\Configuration;
1516
use Symfony\Component\Config\Definition\Processor;
17+
use Symfony\Component\Console\Output\OutputInterface;
1618

1719
class ConfigurationTest extends \PHPUnit_Framework_TestCase
1820
{
@@ -215,6 +217,34 @@ public function testWithSwiftMailerHandler()
215217
$this->assertEquals('mailer', $config['handlers']['swift']['mailer']);
216218
}
217219

220+
public function testWithConsoleHandler()
221+
{
222+
$configs = array(
223+
array(
224+
'handlers' => array(
225+
'console' => array(
226+
'type' => 'console',
227+
'verbosity_levels' => array(
228+
'VERBOSITY_NORMAL' => 'NOTICE',
229+
'verbosity_verbose' => 'info',
230+
'VERBOSITY_very_VERBOSE' => 150
231+
)
232+
)
233+
)
234+
)
235+
);
236+
237+
$config = $this->process($configs);
238+
239+
$this->assertSame('console', $config['handlers']['console']['type']);
240+
$this->assertSame(array(
241+
OutputInterface::VERBOSITY_NORMAL => Logger::NOTICE,
242+
OutputInterface::VERBOSITY_VERBOSE => Logger::INFO,
243+
OutputInterface::VERBOSITY_VERY_VERBOSE => 150,
244+
OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG
245+
), $config['handlers']['console']['verbosity_levels']);
246+
}
247+
218248
public function testWithType()
219249
{
220250
$configs = array(

0 commit comments

Comments
 (0)