Bug fixes and clean ups

This commit is contained in:
Clemens Schwaighofer
2023-06-01 08:47:40 +09:00
parent 72f0810898
commit 2c2826ac24
5 changed files with 39 additions and 86 deletions

View File

@@ -3123,16 +3123,13 @@ class IO
/** /**
* switches the debug flag on or off * 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 * @param bool $debug True/False to turn debugging in this calss on or off
* @return bool Current debug flag as set * @return void
*/ */
public function dbSetDebug(?bool $debug = null): bool public function dbSetDebug(bool $debug): void
{ {
if ($debug !== null) { $this->db_debug = $debug;
$this->db_debug = $debug;
}
return $this->db_debug;
} }
/** /**
@@ -3140,9 +3137,11 @@ class IO
* OR * OR
* with the optional parameter fix sets debug * with the optional parameter fix sets debug
* returns current set stats * returns current set stats
*
* @param bool|null $debug Flag to turn debug on off or null for toggle * @param bool|null $debug Flag to turn debug on off or null for toggle
* @return bool Current debug status * @return bool Current debug status
* True for debug is on, False for off * True for debug is on, False for off
* @deprecated Use dbSetDebug and dbGetDebug
*/ */
public function dbToggleDebug(?bool $debug = null): bool public function dbToggleDebug(?bool $debug = null): bool
{ {
@@ -3156,6 +3155,7 @@ class IO
/** /**
* Return current set db debug flag status * Return current set db debug flag status
*
* @return bool Current debug status * @return bool Current debug status
*/ */
public function dbGetDebug(): bool public function dbGetDebug(): bool

View File

@@ -177,7 +177,6 @@ class Support
$caller_level = 1; $caller_level = 1;
$caller_list = self::getCallerMethodList(); $caller_list = self::getCallerMethodList();
if ($caller_list[0] == 'dV') { if ($caller_list[0] == 'dV') {
echo "Raise caller level<br>: " . $caller_list[0] . "<br>";
$caller_level = 2; $caller_level = 2;
} }
// we need to strip the string in <small></small that is // we need to strip the string in <small></small that is

View File

@@ -675,9 +675,11 @@ class Logging
* *
* @return bool True, we are at debug level * @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) // log file id set (file name prefix)

View File

@@ -99,7 +99,6 @@ final class CoreLibsDBIOTest extends TestCase
], ],
]; ];
private static $log; private static $log;
private static bool $db_debug = false;
/** /**
* Test if pgsql module loaded * Test if pgsql module loaded
@@ -123,7 +122,6 @@ final class CoreLibsDBIOTest extends TestCase
'log_file_id' => 'CoreLibs-DB-IO-Test', 'log_file_id' => 'CoreLibs-DB-IO-Test',
]); ]);
// will be true, default logging is true // will be true, default logging is true
self::$db_debug = self::$log->getLoggingLevel()->includes(Level::Debug);
$db = new \CoreLibs\DB\IO( $db = new \CoreLibs\DB\IO(
self::$db_config['valid'], self::$db_config['valid'],
self::$log self::$log
@@ -521,6 +519,9 @@ final class CoreLibsDBIOTest extends TestCase
*/ */
public function debugSetProvider(): array public function debugSetProvider(): array
{ {
// 0: db connecdtion
// 1: override log flag, null for default
// 2: set flag
return [ return [
'default debug set' => [ 'default debug set' => [
// what base connection // 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 * Test dbSetDbug, dbGetDebug
* *
* @covers ::dbGetDbug * @covers ::dbGetDbug
* @covers ::dbSetDebug * @covers ::dbSetDebug
* @dataProvider debugSetProvider * @testdox Set and Get Debug flag
* @testdox Setting debug $set will be $expected [$_dataName]
* *
* @return void * @return void
*/ */
public function testDbSetDebug( public function testDbSetDebug(): void
string $connection, {
?bool $set, $connection = 'valid';
bool $expected // default set, expect true
): void {
$db = new \CoreLibs\DB\IO( $db = new \CoreLibs\DB\IO(
self::$db_config[$connection], self::$db_config[$connection],
self::$log self::$log
); );
echo "Expected: " . self::$db_debug . "\n"; $this->assertTrue(
$this->assertEquals( $db->dbGetDebug()
$expected,
$set === null ?
$db->dbSetDebug() :
$db->dbSetDebug($set)
); );
// must always match // switch off
$this->assertEquals( $db->dbSetDebug(false);
$expected, $this->assertFalse(
$db->dbGetDebug() $db->dbGetDebug()
); );
$db->dbClose(); $db->dbClose();
} // second conenction with log set NOT debug
$log = new \CoreLibs\Logging\Logging([
/** // 'log_folder' => __DIR__ . DIRECTORY_SEPARATOR . 'log',
* Test dbToggleDebug, dbGetDebug 'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
* 'log_file_id' => 'CoreLibs-DB-IO-Test',
* @covers ::dbGetDbug 'log_level' => \CoreLibs\Logging\Logger\Level::Notice,
* @covers ::dbSetDebug ]);
* @dataProvider debugToggleProvider
* @testdox Toggle debug $toggle will be $expected [$_dataName]
*
* @return void
*/
public function testDbToggleDebug(
string $connection,
?bool $toggle,
bool $expected
): void {
$db = new \CoreLibs\DB\IO( $db = new \CoreLibs\DB\IO(
self::$db_config[$connection], self::$db_config[$connection],
self::$log $log
); );
$this->assertEquals( $this->assertFalse(
$expected,
$toggle === null ?
$db->dbToggleDebug() :
$db->dbToggleDebug($toggle)
);
// must always match
$this->assertEquals(
$expected,
$db->dbGetDebug() $db->dbGetDebug()
); );
$db->dbClose();
} }
// - set max query call sets // - set max query call sets

View File

@@ -217,14 +217,14 @@ final class CoreLibsLoggingLoggingTest extends TestCase
// setLoggingLevel // setLoggingLevel
// getLoggingLevel // getLoggingLevel
// getJsDebug // loggingLevelIsDebug
/** /**
* Undocumented function * Undocumented function
* *
* @covers ::setLoggingLevel * @covers ::setLoggingLevel
* @covers ::getLoggingLevel * @covers ::getLoggingLevel
* @covers ::getJsDebug * @covers ::loggingLevelIsDebug
* @testdox setLoggingLevel set/get checks * @testdox setLoggingLevel set/get checks
* *
* @return void * @return void
@@ -242,7 +242,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase
$log->getLoggingLevel() $log->getLoggingLevel()
); );
$this->assertFalse( $this->assertFalse(
$log->getJsDebug() $log->loggingLevelIsDebug()
); );
// not set, should be debug] // not set, should be debug]
$log = new \CoreLibs\Logging\Logging([ $log = new \CoreLibs\Logging\Logging([
@@ -254,7 +254,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase
$log->getLoggingLevel() $log->getLoggingLevel()
); );
$this->assertTrue( $this->assertTrue(
$log->getJsDebug() $log->loggingLevelIsDebug()
); );
// invalid, should be debug, will throw excpetion too // invalid, should be debug, will throw excpetion too
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
@@ -269,7 +269,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase
$log->getLoggingLevel() $log->getLoggingLevel()
); );
$this->assertTrue( $this->assertTrue(
$log->getJsDebug() $log->loggingLevelIsDebug()
); );
// set valid, then change // set valid, then change
$log = new \CoreLibs\Logging\Logging([ $log = new \CoreLibs\Logging\Logging([