fix and complete testcase

This commit is contained in:
odain
2019-12-12 14:14:36 +01:00
parent 6ec441e501
commit abd5e27c2e
2 changed files with 55 additions and 14 deletions

View File

@@ -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;

View File

@@ -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()],
];
}