Skip to content

Commit

Permalink
Throw an exception on invalid level name
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Nov 14, 2012
1 parent bcb51e0 commit b23cfd3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Monolog/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ public function addEmergency($message, array $context = array())
*/
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];
}

Expand Down
17 changes: 17 additions & 0 deletions tests/Monolog/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ public function testGetName()
$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
*/
Expand Down

0 comments on commit b23cfd3

Please sign in to comment.