diff --git a/core/log.class.inc.php b/core/log.class.inc.php index 9fc2040ee..86100ffb9 100644 --- a/core/log.class.inc.php +++ b/core/log.class.inc.php @@ -365,7 +365,7 @@ abstract class LogAPI */ private static function GetMinLogLevel($sChannel) { - $oConfig = (static::$m_oMockMetaModelConfig === null) ? static::$m_oMockMetaModelConfig : \MetaModel::GetConfig(); + $oConfig = (static::$m_oMockMetaModelConfig !== null) ? static::$m_oMockMetaModelConfig : \MetaModel::GetConfig(); if (!$oConfig instanceof Config) { return self::LEVEL_OK; diff --git a/test/core/LogAPITest.php b/test/core/LogAPITest.php index 8e477c7b0..8eefd7de3 100644 --- a/test/core/LogAPITest.php +++ b/test/core/LogAPITest.php @@ -30,7 +30,6 @@ class LogAPITest extends ItopTestCase } - /** /** * @dataProvider LogApiProvider * @test @@ -57,7 +56,6 @@ class LogAPITest extends ItopTestCase } /** - /** TODISCUSS * @test * @backupGlobals disabled */ @@ -71,12 +69,11 @@ class LogAPITest extends ItopTestCase } /** - /** - * @dataProvider LogWithChannelLogLevelApiProvider + * @dataProvider LogWarningWithASpecificChannelProvider * @test * @backupGlobals disabled */ - public function TestLogWithChannelLogLevelApi($expectedCallNb, $sExpectedLevel, $ConfigReturnedObject, $bExceptionRaised=false) + public function TestLogWarningWithASpecificChannel($expectedCallNb, $sExpectedLevel, $ConfigReturnedObject, $bExceptionRaised=false) { $this->oMetaModelConfig ->method("Get") @@ -96,7 +93,7 @@ class LogAPITest extends ItopTestCase $this->fail("raised should have been raised"); } } - catch(Exception $e) + catch(\Exception $e) { if (!$bExceptionRaised) { @@ -105,15 +102,59 @@ class LogAPITest extends ItopTestCase } } - public function LogWithChannelLogLevelApiProvider() + public function LogWarningWithASpecificChannelProvider() { return [ - [ 0, "Ok", ''], - [ 0, "Ok", 'TotoLevel'], - [ 0, "Ok", array()], - [ 0, "Ok", ["GaBuZoMeuChannel" => "TotoLevel"], true], - [ 1, "Error", ["GaBuZoMeuChannel" => "Error"]], - [ 0, "Info", ["GaBuZoMeuChannel" => "Info"]], + "empty config" => [ 0, "Ok", ''], + "Default Unknown Level" => [ 0, "Ok", 'TotoLevel', true], + "Info as Default Level" => [ 1 , "Warning", 'Info'], + "Error as Default Level" => [ 0, "Warning", 'Error'], + "Empty array" => [ 0, "Ok", array()], + "Channel configured on an undefined level" => [ 0, "Ok", ["GaBuZoMeuChannel" => "TotoLevel"], true], + "Channel defined with Error" => [ 0, "Warning", ["GaBuZoMeuChannel" => "Error"]], + "Channel defined with Info" => [ 1, "Warning", ["GaBuZoMeuChannel" => "Info"]], + ]; + } + + /** + * @dataProvider LogOkWithASpecificChannel + * @test + * @backupGlobals disabled + */ + public function TestLogOkWithASpecificChannel($expectedCallNb, $sExpectedLevel, $ConfigReturnedObject, $bExceptionRaised=false) + { + $this->oMetaModelConfig + ->method("Get") + ->with('log_level_min') + ->willReturn($ConfigReturnedObject); + + \IssueLog::MockStaticObjects($this->mockFileLog, $this->oMetaModelConfig); + + $this->mockFileLog->expects($this->exactly($expectedCallNb)) + ->method($sExpectedLevel) + ->with("log msg", "GaBuZoMeuChannel"); + + try{ + \IssueLog::Ok("log msg", "GaBuZoMeuChannel"); + if ($bExceptionRaised) + { + $this->fail("raised should have been raised"); + } + } + catch(\Exception $e) + { + if (!$bExceptionRaised) + { + $this->fail("raised should NOT have been raised"); + } + } + } + + public function LogOkWithASpecificChannel() + { + return [ + "empty config" => [ 1, "Ok", ''], + "Empty array" => [ 1, "Ok", array()], ]; }