Add PostgreSQL Support (#3)

Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
2024-06-21 13:46:41 +00:00
parent 330e272187
commit 124426fa12
61 changed files with 2290 additions and 223 deletions

View File

@@ -2,13 +2,9 @@
namespace Test\Integration\SQLite;
use BitBadger\PDODocument\Configuration;
use BitBadger\PDODocument\Definition;
use BitBadger\PDODocument\Document;
use BitBadger\PDODocument\DocumentException;
use BitBadger\PDODocument\Mode;
use Test\Integration\SubDocument;
use Test\Integration\TestDocument;
use BitBadger\PDODocument\{AutoId, Configuration, Definition, Document, DocumentException, Mode};
use Random\RandomException;
use Test\Integration\{SubDocument, TestDocument};
/**
* Utilities to create and destroy a throwaway SQLite database to use for testing
@@ -16,18 +12,18 @@ use Test\Integration\TestDocument;
class ThrowawayDb
{
/** @var string The table used for document manipulation */
public const string TABLE = "test_table";
public const TABLE = "test_table";
/**
* Create a throwaway SQLite database
*
* @param bool $withData Whether to initialize this database with data (optional; defaults to `true`)
* @return string The name of the database (use to pass to `destroy` function at end of test)
* @throws DocumentException If any is encountered
* @throws DocumentException|RandomException If any is encountered
*/
public static function create(bool $withData = true): string
{
$fileName = sprintf('throwaway-%s-%d.db', date('His'), rand(10, 99));
$fileName = sprintf('throwaway-%s.db', AutoId::generateRandom(10));
Configuration::$pdoDSN = "sqlite:./$fileName";
Configuration::$mode = Mode::SQLite;
Configuration::resetPDO();
@@ -52,20 +48,6 @@ class ThrowawayDb
public static function destroy(string $fileName): void
{
Configuration::resetPDO();
unlink("./$fileName");
}
/**
* Destroy the given throwaway database and create another
*
* @param string $fileName The name of the database to be destroyed
* @param bool $withData Whether to initialize the database with data (optional; defaults to `true`)
* @return string The name of the new database
* @throws DocumentException If any is encountered
*/
public static function exchange(string $fileName, bool $withData = true): string
{
self::destroy($fileName);
return self::create($withData);
if (file_exists("./$fileName")) unlink("./$fileName");
}
}