Autoloader updates, read env to class, DB IO update
Move autolaoder loading from config.master.php to config.php and before we read config.master.php The read env function has moved into a class and is launched after the auto loader has been loaded DB IO class update with better error reporting with last error set and error history of all errors in order. TODO: per query or per action error grouping
This commit is contained in:
@@ -15,8 +15,51 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
final class CoreLibsDBIOTest extends TestCase
|
||||
{
|
||||
private static $db_config = [];
|
||||
private static $log;
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
// define basic connection set valid and one invalid
|
||||
self::$db_config = [
|
||||
// self localhost/ip connection
|
||||
'valid' => [
|
||||
'db_name' => 'corelibs_db_io_test',
|
||||
'db_user' => 'corelibs_db_io_test',
|
||||
'db_pass' => 'corelibs_db_io_test',
|
||||
'db_host' => 'localhost',
|
||||
'db_port' => 5432,
|
||||
'db_schema' => 'public',
|
||||
'db_type' => 'pgsql',
|
||||
'db_encoding' => '',
|
||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
||||
'db_debug' => true,
|
||||
],
|
||||
'invalid' => [
|
||||
'db_name' => '',
|
||||
'db_user' => '',
|
||||
'db_pass' => '',
|
||||
'db_host' => '',
|
||||
'db_port' => 5432,
|
||||
'db_schema' => 'public',
|
||||
'db_type' => 'pgsql',
|
||||
'db_encoding' => '',
|
||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
||||
'db_debug' => true,
|
||||
],
|
||||
];
|
||||
self::$log = new \CoreLibs\Debug\Logging([
|
||||
// 'log_folder' => __DIR__ . DIRECTORY_SEPARATOR . 'log',
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'file_id' => 'CoreLibs-DB-IO-Test',
|
||||
'debug_all' => false,
|
||||
'echo_all' => false,
|
||||
'print_all' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Check that we can actually do these tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -27,10 +70,55 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
'The PgSQL extension is not available.'
|
||||
);
|
||||
}
|
||||
// print_r(self::$db_config);
|
||||
}
|
||||
|
||||
// - connect to DB test (getConnectionStatus)
|
||||
// - connected get dbInfo data check (show true, false)
|
||||
// - disconnect: dbClose
|
||||
// - connected get all default settings via get
|
||||
// dbGetDebug, dbGetMaxQueryCall, dbGetSchema, dbGetEncoding,
|
||||
// dbVerions, dbCompareVersion
|
||||
// dbGetSetting (name, user, ecnoding, schema, host, port, ssl, debug, password)
|
||||
// - connected set
|
||||
// dbSetMaxQueryCall, dbSetDebug, dbToggleDebug, dbSetSchema, dbSetEncoding
|
||||
// - db execution tests
|
||||
// dbReturn, dbDumpData, dbCacheReset, dbExec, dbExecAsync, dbCheckAsync
|
||||
// dbFetchArray, dbReturnRow, dbReturnArray, dbCursorPos, dbCursorNumRows,
|
||||
// dbShowTableMetaData, dbPrepare, dbExecute
|
||||
// dbEscapeString, dbEscapeLiteral, dbEscapeBytea, dbSqlEscape, dbArrayParse
|
||||
// - complex write sets
|
||||
// dbWriteData, dbWriteDataExt
|
||||
// - non connection tests
|
||||
// dbBoolean, dbTimeFormat
|
||||
// - internal read data (post exec)
|
||||
// dbGetReturning, dbGetInsertPKName, dbGetInsertPK, dbGetReturningExt,
|
||||
// dbGetReturningArray, dbGetCursorExt, dbGetNumRows,
|
||||
// getHadError, getHadWarning,
|
||||
// dbResetQueryCalled, dbGetQueryCalled
|
||||
// - deprecated tests
|
||||
// getInsertReturn, getReturning, getInsertPK, getReturningExt,
|
||||
// getCursorExt, getNumRows
|
||||
|
||||
public function testConnection()
|
||||
{
|
||||
//
|
||||
$db = new \CoreLibs\DB\IO(
|
||||
self::$db_config['invalid'],
|
||||
self::$log
|
||||
);
|
||||
print "INIT ERROR INVALID: " . $db->getConnectionStatus() . "\n";
|
||||
print "LAST ERROR: " . $db->dbGetLastError(true) . "\n";
|
||||
print "ERRORS: " . print_r($db->dbGetErrorHistory(true), true) . "\n";
|
||||
$db = new \CoreLibs\DB\IO(
|
||||
self::$db_config['valid'],
|
||||
self::$log
|
||||
);
|
||||
print "INIT ERROR VALID: " . $db->getConnectionStatus() . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* grouped DB IO test
|
||||
*
|
||||
* @testdox DB\IO Class tests
|
||||
*
|
||||
|
||||
3
4dev/tests/log/.gitignore
vendored
Normal file
3
4dev/tests/log/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
*log
|
||||
*LOG
|
||||
!.gitignore
|
||||
Reference in New Issue
Block a user