1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-07-31 10:20:14 +02:00

Throw an exception on invalid level name

This commit is contained in:
Jordi Boggiano
2012-11-14 16:46:10 +01:00
parent bcb51e0140
commit b23cfd3d6c
2 changed files with 21 additions and 0 deletions

View File

@@ -322,6 +322,10 @@ class Logger
*/
public static function getLevelName($level)
{
if (!isset(static::$levels[$level])) {
throw new \InvalidArgumentException('Level "'.$level.'" is not defined, use one of: '.implode(', ', array_keys(static::$levels)));
}
return static::$levels[$level];
}

View File

@@ -25,6 +25,23 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foo', $logger->getName());
}
/**
* @covers Monolog\Logger::getLevelName
*/
public function testGetLevelName()
{
$this->assertEquals('ERROR', Logger::getLevelName(Logger::ERROR));
}
/**
* @covers Monolog\Logger::getLevelName
* @expectedException InvalidArgumentException
*/
public function testGetLevelNameThrows()
{
Logger::getLevelName(5);
}
/**
* @covers Monolog\Logger::__construct
*/