mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 18:48:51 +02:00
fix and complete testcase
This commit is contained in:
@@ -365,7 +365,7 @@ abstract class LogAPI
|
|||||||
*/
|
*/
|
||||||
private static function GetMinLogLevel($sChannel)
|
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)
|
if (!$oConfig instanceof Config)
|
||||||
{
|
{
|
||||||
return self::LEVEL_OK;
|
return self::LEVEL_OK;
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ class LogAPITest extends ItopTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider LogApiProvider
|
* @dataProvider LogApiProvider
|
||||||
* @test
|
* @test
|
||||||
@@ -57,7 +56,6 @@ class LogAPITest extends ItopTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
/** TODISCUSS
|
|
||||||
* @test
|
* @test
|
||||||
* @backupGlobals disabled
|
* @backupGlobals disabled
|
||||||
*/
|
*/
|
||||||
@@ -71,12 +69,11 @@ class LogAPITest extends ItopTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
/**
|
* @dataProvider LogWarningWithASpecificChannelProvider
|
||||||
* @dataProvider LogWithChannelLogLevelApiProvider
|
|
||||||
* @test
|
* @test
|
||||||
* @backupGlobals disabled
|
* @backupGlobals disabled
|
||||||
*/
|
*/
|
||||||
public function TestLogWithChannelLogLevelApi($expectedCallNb, $sExpectedLevel, $ConfigReturnedObject, $bExceptionRaised=false)
|
public function TestLogWarningWithASpecificChannel($expectedCallNb, $sExpectedLevel, $ConfigReturnedObject, $bExceptionRaised=false)
|
||||||
{
|
{
|
||||||
$this->oMetaModelConfig
|
$this->oMetaModelConfig
|
||||||
->method("Get")
|
->method("Get")
|
||||||
@@ -96,7 +93,7 @@ class LogAPITest extends ItopTestCase
|
|||||||
$this->fail("raised should have been raised");
|
$this->fail("raised should have been raised");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch(\Exception $e)
|
||||||
{
|
{
|
||||||
if (!$bExceptionRaised)
|
if (!$bExceptionRaised)
|
||||||
{
|
{
|
||||||
@@ -105,15 +102,59 @@ class LogAPITest extends ItopTestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function LogWithChannelLogLevelApiProvider()
|
public function LogWarningWithASpecificChannelProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[ 0, "Ok", ''],
|
"empty config" => [ 0, "Ok", ''],
|
||||||
[ 0, "Ok", 'TotoLevel'],
|
"Default Unknown Level" => [ 0, "Ok", 'TotoLevel', true],
|
||||||
[ 0, "Ok", array()],
|
"Info as Default Level" => [ 1 , "Warning", 'Info'],
|
||||||
[ 0, "Ok", ["GaBuZoMeuChannel" => "TotoLevel"], true],
|
"Error as Default Level" => [ 0, "Warning", 'Error'],
|
||||||
[ 1, "Error", ["GaBuZoMeuChannel" => "Error"]],
|
"Empty array" => [ 0, "Ok", array()],
|
||||||
[ 0, "Info", ["GaBuZoMeuChannel" => "Info"]],
|
"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()],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user