Permalink
Browse files

Throw an exception on invalid level name

  • Loading branch information...
1 parent bcb51e0 commit b23cfd3d6ce0b6c050dda723040b83a1a6d7637e @Seldaek committed Nov 14, 2012
Showing with 21 additions and 0 deletions.
  1. +4 −0 src/Monolog/Logger.php
  2. +17 −0 tests/Monolog/LoggerTest.php
View
@@ -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];
}
@@ -26,6 +26,23 @@ public function testGetName()
}
/**
+ * @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
*/
public function testChannel()

0 comments on commit b23cfd3

Please sign in to comment.