get overall coverage to 76%

This commit is contained in:
Dennis Eichhorn 2021-10-24 13:18:08 +02:00
parent 2cfcb24742
commit 892788ece2
3 changed files with 30 additions and 9 deletions

View File

@ -82,6 +82,10 @@ final class SQLiteConnection extends ConnectionAbstract
$this->close();
try {
if (!\is_file($this->dbdata['database'])) {
throw new \PDOException();
}
$this->con = new \PDO($this->dbdata['db'] . ':' . $this->dbdata['database']);
$this->con->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
$this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

View File

@ -148,37 +148,37 @@ $CONFIG = [
'sqlite' => [
'admin' => [
'db' => 'sqlite', /* db type */
'database' => __DIR__ . '/test.sqlite', /* db name */
'database' => __DIR__ . '/../Localization/Defaults/localization.sqlite', /* db name */
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'insert' => [
'db' => 'sqlite', /* db type */
'database' => __DIR__ . '/test.sqlite', /* db name */
'database' => __DIR__ . '/../Localization/Defaults/localization.sqlite', /* db name */
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'select' => [
'db' => 'sqlite', /* db type */
'database' => __DIR__ . '/test.sqlite', /* db name */
'database' => __DIR__ . '/../Localization/Defaults/localization.sqlite', /* db name */
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'update' => [
'db' => 'sqlite', /* db type */
'database' => __DIR__ . '/test.sqlite', /* db name */
'database' => __DIR__ . '/../Localization/Defaults/localization.sqlite', /* db name */
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'delete' => [
'db' => 'sqlite', /* db type */
'database' => __DIR__ . '/test.sqlite', /* db name */
'database' => __DIR__ . '/../Localization/Defaults/localization.sqlite', /* db name */
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],
'schema' => [
'db' => 'sqlite', /* db type */
'database' => __DIR__ . '/test.sqlite', /* db name */
'database' => __DIR__ . '/../Localization/Defaults/localization.sqlite', /* db name */
'weight' => 1000, /* db table prefix */
'datetimeformat' => 'Y-m-d H:i:s',
],

View File

@ -62,6 +62,21 @@ final class SQLiteConnectionTest extends \PHPUnit\Framework\TestCase
self::assertEquals(DatabaseStatus::FAILURE, $sqlite->getStatus());
}
/**
* @testdox Valid sqlite connection data result in a valid database connection
* @covers phpOMS\DataStorage\Database\Connection\SQLiteConnection<extended>
* @group framework
*/
public function testInvalidDatabasePath() : void
{
$db = $GLOBALS['CONFIG']['db']['core']['masters']['admin'];
$db['database'] = 'invalid.sqlite';
$sqlite = new SQLiteConnection($db);
$sqlite->connect();
self::assertEquals(DatabaseStatus::MISSING_DATABASE, $sqlite->getStatus());
}
/**
* @testdox A missing database returns a failure
* @covers phpOMS\DataStorage\Database\Connection\SQLiteConnection
@ -86,15 +101,17 @@ final class SQLiteConnectionTest extends \PHPUnit\Framework\TestCase
$db = $GLOBALS['CONFIG']['db']['core']['masters']['admin'];
$db['database'] = 'invalid';
$mysql = new SQLiteConnection($db);
$mysql->connect();
self::assertEquals(DatabaseStatus::MISSING_DATABASE, $mysql->getStatus());
$sqlite = new SQLiteConnection($db);
$sqlite->connect();
self::assertEquals(DatabaseStatus::MISSING_DATABASE, $sqlite->getStatus());
}
/*
public static function tearDownAfterClass() : void
{
if (\is_file($GLOBALS['CONFIG']['db']['core']['sqlite']['admin']['database'])) {
\unlink($GLOBALS['CONFIG']['db']['core']['sqlite']['admin']['database']);
}
}
*/
}