PMCORE-546

This commit is contained in:
Paulis
2019-08-09 14:27:53 -04:00
committed by Paula Quispe
parent 22197248dc
commit 4d5cabdc45
2 changed files with 226 additions and 4 deletions

View File

@@ -425,6 +425,9 @@ class MonologProvider
if (isset(static::$levels[$levelDebug])) { if (isset(static::$levels[$levelDebug])) {
$level = static::$levels[$levelDebug]; $level = static::$levels[$levelDebug];
$this->levelDebug = $level; $this->levelDebug = $level;
} else {
//If is other value like NONE will set with empty level
$this->levelDebug = '';
} }
} }
@@ -467,7 +470,8 @@ class MonologProvider
} }
/** /**
* Register log * Register log if the level correspond to the logging_level defined
* In other way return false if the log was turn off or the actions does not logged
* *
* @access public * @access public
* *
@@ -475,12 +479,14 @@ class MonologProvider
* @param string $message The log message * @param string $message The log message
* @param array $context The log context * @param array $context The log context
* *
* @return void * @return bool
*/ */
public function addLog($level, $message, $context) public function addLog($level, $message, $context)
{ {
if (!empty($this->getLevelDebug())) { if (!empty($this->getLevelDebug()) && $level >= $this->getLevelDebug()) {
$this->getLogger()->addRecord($level, $message, $context); return $this->getLogger()->addRecord($level, $message, $context);
} else {
return false;
} }
} }
} }

View File

@@ -0,0 +1,216 @@
<?php
namespace Tests\unit\gulliver\system;
use MonologProvider;
use Tests\TestCase;
/**
* @coversDefaultClass \MonologProvider
*/
class MonologProviderTest extends TestCase
{
/**
* It tests an undefined level
*
* @covers ::setLevelDebug
* @test
*/
public function it_check_log_when_logging_level_is_undefined()
{
$log = MonologProvider::getSingleton('Channel Test', 'processmaker.log', true);
// Define the logging_level = UNDEFINED value
$log->setLevelDebug('UNDEFINED');
$this->assertEmpty($log->getLevelDebug());
// Register a log debug
$res = $log->addLog(100, 'This test can not be registered', []);
// Check that the DEBUG was not registered
$this->assertFalse($res);
// Register a log info
$res = $log->addLog(200, 'This test can not be registered', []);
// Check that the INFO was not registered
$this->assertFalse($res);
// Register a log warning
$res = $log->addLog(300, 'This test can not be registered', []);
// Check that the WARNING was not registered
$this->assertFalse($res);
// Register a log error
$res = $log->addLog(400, 'This test can not be registered', []);
// Check that the ERROR was not registered
$this->assertFalse($res);
// Register a log critical
$res = $log->addLog(500, 'This test can not be registered', []);
// Check that the CRITICAL was not registered
$this->assertFalse($res);
}
/**
* It tests that the log register from NONE, it to turn off the log
*
* @covers ::addLog
* @test
*/
public function it_check_log_when_logging_level_is_turn_off()
{
$log = MonologProvider::getSingleton('Channel Test', 'processmaker.log', true);
// Define the logging_level = NONE
$log->setLevelDebug('NONE');
$this->assertEmpty($log->getLevelDebug());
// Register a log debug
$res = $log->addLog(100, 'This test can not be registered', []);
// Check that the DEBUG was not registered
$this->assertFalse($res);
// Register a log info
$res = $log->addLog(200, 'This test can not be registered', []);
// Check that the INFO was not registered
$this->assertFalse($res);
// Register a log warning
$res = $log->addLog(300, 'This test can not be registered', []);
// Check that the WARNING was not registered
$this->assertFalse($res);
// Register a log error
$res = $log->addLog(400, 'This test can not be registered', []);
// Check that the ERROR was not registered
$this->assertFalse($res);
// Register a log critical
$res = $log->addLog(500, 'This test can not be registered', []);
// Check that the CRITICAL was not registered
$this->assertFalse($res);
}
/**
* It tests that the log register from INFO
*
* @covers ::addLog
* @test
*/
public function it_check_log_when_logging_level_is_info()
{
$log = MonologProvider::getSingleton('Channel Test', 'processmaker.log', true);
// Define the logging_level = INFO (200)
$log->setLevelDebug('INFO');
$this->assertEquals($log->getLevelDebug(), 200);
// Register a log debug
$res = $log->addLog(100, 'This test can not be registered', []);
// Check that the DEBUG was not registered
$this->assertFalse($res);
// Register a log info
$res = $log->addLog(200, 'Test', []);
// Check that the INFO was registered
$this->assertTrue($res);
// Register a log warning
$res = $log->addLog(300, 'Test', []);
// Check that the WARNING was registered
$this->assertTrue($res);
// Register a log error
$res = $log->addLog(400, 'Test', []);
// Check that the ERROR was registered
$this->assertTrue($res);
// Register a log critical
$res = $log->addLog(500, 'Test', []);
// Check that the CRITICAL was registered
$this->assertTrue($res);
}
/**
* It tests that the log register from WARNING
*
* @covers ::addLog
* @test
*/
public function it_check_log_when_logging_level_is_warning()
{
$log = MonologProvider::getSingleton('Channel Test', 'processmaker.log', true);
// Define the logging_level WARNING (300)
$log->setLevelDebug('WARNING');
$this->assertEquals($log->getLevelDebug(), 300);
// Register a log debug
$res = $log->addLog(100, 'This test can not be registered', []);
// Check that the DEBUG was not registered
$this->assertFalse($res);
// Register a log info
$res = $log->addLog(200, 'This test can not be registered', []);
// Check that the INFO was not registered
$this->assertFalse($res);
// Register a log warning
$res = $log->addLog(300, 'Test', []);
// Check that the WARNING was registered
$this->assertTrue($res);
// Register a log error
$res = $log->addLog(400, 'Test', []);
// Check that the ERROR was registered
$this->assertTrue($res);
// Register a log critical
$res = $log->addLog(500, 'Test', []);
// Check that the CRITICAL was registered
$this->assertTrue($res);
}
/**
* It tests that the log register from ERROR
*
* @covers ::addLog
* @test
*/
public function it_check_log_when_logging_level_is_error()
{
$log = MonologProvider::getSingleton('Channel Test', 'processmaker.log', true);
// Define the logging_level ERROR (400)
$log->setLevelDebug('ERROR');
$this->assertEquals($log->getLevelDebug(), 400);
// Register a log debug
$res = $log->addLog(100, 'This test can not be registered', []);
// Check that the DEBUG was not registered
$this->assertFalse($res);
// Register a log info
$res = $log->addLog(200, 'This test can not be registered', []);
// Check that the INFO was not registered
$this->assertFalse($res);
// Register a log warning
$res = $log->addLog(300, 'This test can not be registered', []);
// Check that the WARNING was not registered
$this->assertFalse($res);
// Register a log error
$res = $log->addLog(400, 'Test', []);
// Check that the ERROR was registered
$this->assertTrue($res);
// Register a log critical
$res = $log->addLog(500, 'Test', []);
// Check that the CRITICAL was registered
$this->assertTrue($res);
}
/**
* It tests that the log register from CRITICAL
*
* @covers ::addLog
* @test
*/
public function it_check_log_when_logging_level_is_critical()
{
$log = MonologProvider::getSingleton('Channel Test', 'processmaker.log', true);
// Define the logging_level CRITICAL (500)
$log->setLevelDebug('CRITICAL');
$this->assertEquals($log->getLevelDebug(), 500);
// Register a log debug
$res = $log->addLog(100, 'This test can not be registered', []);
// Check that the DEBUG was not registered
$this->assertFalse($res);
// Register a log info
$res = $log->addLog(200, 'This test can not be registered', []);
// Check that the INFO was not registered
$this->assertFalse($res);
// Register a log warning
$res = $log->addLog(300, 'This test can not be registered', []);
// Check that the WARNING was not registered
$this->assertFalse($res);
// Register a log error
$res = $log->addLog(400, 'This test can not be registered', []);
// Check that the ERROR was not registered
$this->assertFalse($res);
// Register a log critical
$res = $log->addLog(500, 'Test', []);
// Check that the CRITICAL was registered
$this->assertTrue($res);
}
}