Derive mode from DSN function

- Add headers in all files
- Minor field name changes
This commit is contained in:
2024-07-20 21:47:21 -04:00
parent 1a37b009ea
commit d8330d828a
81 changed files with 1053 additions and 551 deletions

View File

@@ -1,4 +1,10 @@
<?php declare(strict_types=1);
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace Test\Integration\PostgreSQL;

View File

@@ -1,4 +1,10 @@
<?php declare(strict_types=1);
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace Test\Integration\PostgreSQL;

View File

@@ -1,4 +1,10 @@
<?php declare(strict_types=1);
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace Test\Integration\PostgreSQL;

View File

@@ -1,4 +1,10 @@
<?php declare(strict_types=1);
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace Test\Integration\PostgreSQL;

View File

@@ -1,4 +1,10 @@
<?php declare(strict_types=1);
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace Test\Integration\PostgreSQL;

View File

@@ -1,4 +1,10 @@
<?php declare(strict_types=1);
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace Test\Integration\PostgreSQL;

View File

@@ -1,4 +1,10 @@
<?php declare(strict_types=1);
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace Test\Integration\PostgreSQL;

View File

@@ -1,4 +1,10 @@
<?php declare(strict_types=1);
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace Test\Integration\PostgreSQL;

View File

@@ -1,4 +1,10 @@
<?php declare(strict_types=1);
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace Test\Integration\PostgreSQL;

View File

@@ -1,4 +1,10 @@
<?php declare(strict_types=1);
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace Test\Integration\PostgreSQL;

View File

@@ -1,8 +1,15 @@
<?php declare(strict_types=1);
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
* @see https://github.com/Zaid-Ajaj/ThrowawayDb The origin concept
*/
declare(strict_types=1);
namespace Test\Integration\PostgreSQL;
use BitBadger\PDODocument\{AutoId, Configuration, Custom, Definition, Document, DocumentException, Mode};
use BitBadger\PDODocument\{AutoId, Configuration, Custom, Definition, Document, DocumentException};
use Random\RandomException;
use Test\Integration\{SubDocument, TestDocument};
@@ -12,21 +19,21 @@ use Test\Integration\{SubDocument, TestDocument};
class ThrowawayDb
{
/** @var string The table used for document manipulation */
public const TABLE = "test_table";
public const TABLE = 'test_table';
/**
* Configure the document library for the given database (or the main PostgreSQL connection, if the database name
* is not provided; this is used for creating and dropping databases)
*
* @param string|null $dbName The name of the database to configure (optional, defaults to env or "postgres")
* @throws DocumentException If any is encountered
*/
private static function configure(?string $dbName = null): void
{
Configuration::$pdoDSN = sprintf("pgsql:host=%s;dbname=%s", $_ENV['PDO_DOC_PGSQL_HOST'] ?? 'localhost',
$dbName ?? $_ENV['PDO_DOC_PGSQL_DB'] ?? 'postgres');
Configuration::useDSN(sprintf("pgsql:host=%s;dbname=%s", $_ENV['PDO_DOC_PGSQL_HOST'] ?? 'localhost',
$dbName ?? $_ENV['PDO_DOC_PGSQL_DB'] ?? 'postgres'));
Configuration::$username = $_ENV['PDO_DOC_PGSQL_USER'] ?? 'postgres';
Configuration::$password = $_ENV['PDO_DOC_PGSQL_PASS'] ?? 'postgres';
Configuration::$mode = Mode::PgSQL;
Configuration::resetPDO();
}
@@ -66,10 +73,9 @@ class ThrowawayDb
{
self::configure();
Custom::nonQuery("DROP DATABASE IF EXISTS $dbName WITH (FORCE)", []);
Configuration::$pdoDSN = '';
Configuration::useDSN('');
Configuration::$username = null;
Configuration::$password = null;
Configuration::$mode = null;
Configuration::resetPDO();
}
}