Bug fixes and minor updates
- Removed echo from Support Debug dumpVar call - deprecated DB\IO toggle dbDebug and changed set/get to be like normal ones where set just sets and doesn't return anything - Renamed the logJsDebug to loggingLevelIsDebug (other levels can be checked with ->getLoggingLevel()->includes(Level::...)) Adjusted tests for all changes
This commit is contained in:
@@ -99,7 +99,6 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
],
|
||||
];
|
||||
private static $log;
|
||||
private static bool $db_debug = false;
|
||||
|
||||
/**
|
||||
* Test if pgsql module loaded
|
||||
@@ -123,7 +122,6 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
'log_file_id' => 'CoreLibs-DB-IO-Test',
|
||||
]);
|
||||
// will be true, default logging is true
|
||||
self::$db_debug = self::$log->getLoggingLevel()->includes(Level::Debug);
|
||||
$db = new \CoreLibs\DB\IO(
|
||||
self::$db_config['valid'],
|
||||
self::$log
|
||||
@@ -521,6 +519,9 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
*/
|
||||
public function debugSetProvider(): array
|
||||
{
|
||||
// 0: db connecdtion
|
||||
// 1: override log flag, null for default
|
||||
// 2: set flag
|
||||
return [
|
||||
'default debug set' => [
|
||||
// what base connection
|
||||
@@ -538,95 +539,46 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test set for toggleDEbug
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function debugToggleProvider(): array
|
||||
{
|
||||
return [
|
||||
'default debug set' => [
|
||||
// what base connection
|
||||
'valid',
|
||||
// actions
|
||||
null,
|
||||
// toggle is inverse
|
||||
self::$db_debug ? true : false,
|
||||
],
|
||||
'toggle debug to false' => [
|
||||
'valid',
|
||||
false,
|
||||
false,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test dbSetDbug, dbGetDebug
|
||||
*
|
||||
* @covers ::dbGetDbug
|
||||
* @covers ::dbSetDebug
|
||||
* @dataProvider debugSetProvider
|
||||
* @testdox Setting debug $set will be $expected [$_dataName]
|
||||
* @testdox Set and Get Debug flag
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDbSetDebug(
|
||||
string $connection,
|
||||
?bool $set,
|
||||
bool $expected
|
||||
): void {
|
||||
public function testDbSetDebug(): void
|
||||
{
|
||||
$connection = 'valid';
|
||||
// default set, expect true
|
||||
$db = new \CoreLibs\DB\IO(
|
||||
self::$db_config[$connection],
|
||||
self::$log
|
||||
);
|
||||
echo "Expected: " . self::$db_debug . "\n";
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set === null ?
|
||||
$db->dbSetDebug() :
|
||||
$db->dbSetDebug($set)
|
||||
$this->assertTrue(
|
||||
$db->dbGetDebug()
|
||||
);
|
||||
// must always match
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
// switch off
|
||||
$db->dbSetDebug(false);
|
||||
$this->assertFalse(
|
||||
$db->dbGetDebug()
|
||||
);
|
||||
$db->dbClose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test dbToggleDebug, dbGetDebug
|
||||
*
|
||||
* @covers ::dbGetDbug
|
||||
* @covers ::dbSetDebug
|
||||
* @dataProvider debugToggleProvider
|
||||
* @testdox Toggle debug $toggle will be $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDbToggleDebug(
|
||||
string $connection,
|
||||
?bool $toggle,
|
||||
bool $expected
|
||||
): void {
|
||||
// second conenction with log set NOT debug
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
// 'log_folder' => __DIR__ . DIRECTORY_SEPARATOR . 'log',
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'log_file_id' => 'CoreLibs-DB-IO-Test',
|
||||
'log_level' => \CoreLibs\Logging\Logger\Level::Notice,
|
||||
]);
|
||||
$db = new \CoreLibs\DB\IO(
|
||||
self::$db_config[$connection],
|
||||
self::$log
|
||||
$log
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$toggle === null ?
|
||||
$db->dbToggleDebug() :
|
||||
$db->dbToggleDebug($toggle)
|
||||
);
|
||||
// must always match
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$this->assertFalse(
|
||||
$db->dbGetDebug()
|
||||
);
|
||||
$db->dbClose();
|
||||
}
|
||||
|
||||
// - set max query call sets
|
||||
|
||||
@@ -217,14 +217,14 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
||||
|
||||
// setLoggingLevel
|
||||
// getLoggingLevel
|
||||
// getJsDebug
|
||||
// loggingLevelIsDebug
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLoggingLevel
|
||||
* @covers ::getLoggingLevel
|
||||
* @covers ::getJsDebug
|
||||
* @covers ::loggingLevelIsDebug
|
||||
* @testdox setLoggingLevel set/get checks
|
||||
*
|
||||
* @return void
|
||||
@@ -242,7 +242,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
||||
$log->getLoggingLevel()
|
||||
);
|
||||
$this->assertFalse(
|
||||
$log->getJsDebug()
|
||||
$log->loggingLevelIsDebug()
|
||||
);
|
||||
// not set, should be debug]
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
@@ -254,7 +254,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
||||
$log->getLoggingLevel()
|
||||
);
|
||||
$this->assertTrue(
|
||||
$log->getJsDebug()
|
||||
$log->loggingLevelIsDebug()
|
||||
);
|
||||
// invalid, should be debug, will throw excpetion too
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
@@ -269,7 +269,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
||||
$log->getLoggingLevel()
|
||||
);
|
||||
$this->assertTrue(
|
||||
$log->getJsDebug()
|
||||
$log->loggingLevelIsDebug()
|
||||
);
|
||||
// set valid, then change
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
|
||||
@@ -23,6 +23,8 @@ ob_end_flush();
|
||||
$ECHO_ALL = true;
|
||||
|
||||
// use CoreLibs\Debug\Support;
|
||||
|
||||
use CoreLibs\Debug\Support;
|
||||
use CoreLibs\Logging\Logger\Level;
|
||||
use CoreLibs\Logging\Logger\Flag;
|
||||
// use CoreLibs\Debug\Support;
|
||||
@@ -51,7 +53,18 @@ print "Flag: per_run ->value: " . Flag::per_class->value . "<br>";
|
||||
$log->setLogUniqueId();
|
||||
print "LogUniqId: " . $log->getLogUniqueId() . "<br>";
|
||||
|
||||
print "DUMP: " . $log->dV(['something' => 'error']) . "<br>";
|
||||
print "Is Debug (check): " . Support::printBool($log->getLoggingLevel()->includes(
|
||||
Level::Debug
|
||||
)) . "<br>";
|
||||
print "Is Debug (fk): " . Support::printBool($log->loggingLevelIsDebug()) . "<br>";
|
||||
$log->setLoggingLevel(Level::Notice);
|
||||
print "Is Debug (check): " . Support::printBool($log->getLoggingLevel()->includes(
|
||||
Level::Debug
|
||||
)) . "<br>";
|
||||
print "Is Debug (fk): " . Support::printBool($log->loggingLevelIsDebug()) . "<br>";
|
||||
$log->setLoggingLevel(Level::Debug);
|
||||
|
||||
print "DUMP: <pre>" . $log->dV(['something' => 'error']) . "</pre><br>";
|
||||
|
||||
$log->debug('LEGACY', 'Some legacy shit here');
|
||||
$log->debug('ARRAY', 'Dump some data: ' . $log->dV(['something' => 'error']));
|
||||
|
||||
@@ -121,6 +121,6 @@ if (!$login->loginActionRun()) {
|
||||
//------------------------------ logging end
|
||||
|
||||
// pass on DEBUG flag to JS via smarty variable
|
||||
$smarty->DATA['JS_DEBUG'] = $log->getJsDebug();
|
||||
$smarty->DATA['JS_DEBUG'] = $log->loggingLevelIsDebug();
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -3123,16 +3123,13 @@ class IO
|
||||
|
||||
/**
|
||||
* switches the debug flag on or off
|
||||
* if none given, then return current set only
|
||||
* @param bool|null $debug true/false or null for just getting current set
|
||||
* @return bool Current debug flag as set
|
||||
*
|
||||
* @param bool $debug True/False to turn debugging in this calss on or off
|
||||
* @return void
|
||||
*/
|
||||
public function dbSetDebug(?bool $debug = null): bool
|
||||
public function dbSetDebug(bool $debug): void
|
||||
{
|
||||
if ($debug !== null) {
|
||||
$this->db_debug = $debug;
|
||||
}
|
||||
return $this->db_debug;
|
||||
$this->db_debug = $debug;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3140,9 +3137,11 @@ class IO
|
||||
* OR
|
||||
* with the optional parameter fix sets debug
|
||||
* returns current set stats
|
||||
*
|
||||
* @param bool|null $debug Flag to turn debug on off or null for toggle
|
||||
* @return bool Current debug status
|
||||
* True for debug is on, False for off
|
||||
* @deprecated Use dbSetDebug and dbGetDebug
|
||||
*/
|
||||
public function dbToggleDebug(?bool $debug = null): bool
|
||||
{
|
||||
@@ -3156,6 +3155,7 @@ class IO
|
||||
|
||||
/**
|
||||
* Return current set db debug flag status
|
||||
*
|
||||
* @return bool Current debug status
|
||||
*/
|
||||
public function dbGetDebug(): bool
|
||||
|
||||
@@ -177,7 +177,6 @@ class Support
|
||||
$caller_level = 1;
|
||||
$caller_list = self::getCallerMethodList();
|
||||
if ($caller_list[0] == 'dV') {
|
||||
echo "Raise caller level<br>: " . $caller_list[0] . "<br>";
|
||||
$caller_level = 2;
|
||||
}
|
||||
// we need to strip the string in <small></small that is
|
||||
|
||||
@@ -675,9 +675,11 @@ class Logging
|
||||
*
|
||||
* @return bool True, we are at debug level
|
||||
*/
|
||||
public function getJsDebug(): bool
|
||||
public function loggingLevelIsDebug(): bool
|
||||
{
|
||||
return $this->log_level === Level::Debug ? true : false;
|
||||
return $this->getLoggingLevel()->includes(
|
||||
Level::Debug
|
||||
);
|
||||
}
|
||||
|
||||
// log file id set (file name prefix)
|
||||
|
||||
Reference in New Issue
Block a user