From e44bee6825fc0e9e9bd72bdae202729012523789 Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Mon, 6 Jul 2026 17:27:47 +0200 Subject: [PATCH] fix connection pgsql --- .github/workflows/ci.yml | 4 ++-- Tests/Pgsql/PgsqlDriverTest.php | 30 +++++++++++++++++++++++++++++- Tests/Stubs/Schema/pgsql.sql | 3 +-- phpunit.pgsql.xml.dist | 8 ++++---- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51fca5c22..6cff000e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,9 +146,9 @@ jobs: postgres: image: postgres:${{ matrix.db_version }}-alpine env: - POSTGRES_USER: root + POSTGRES_USER: joomla_ut POSTGRES_PASSWORD: joomla_ut - POSTGRES_DB: test_joomla + POSTGRES_DB: joomla_ut tests-unit-sqlsrv: name: Run Unit tests on SQLsrv diff --git a/Tests/Pgsql/PgsqlDriverTest.php b/Tests/Pgsql/PgsqlDriverTest.php index ee297a713..eb01272a4 100644 --- a/Tests/Pgsql/PgsqlDriverTest.php +++ b/Tests/Pgsql/PgsqlDriverTest.php @@ -6,6 +6,8 @@ namespace Joomla\Database\Tests\Pgsql; +use Joomla\Database\DatabaseDriver; +use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Database\ParameterType; use Joomla\Database\Pgsql\PgsqlDriver; use Joomla\Database\Pgsql\PgsqlExporter; @@ -36,6 +38,32 @@ public static function setUpBeforeClass(): void } } + /** + * Sets up the fixture. + * + * This method is called before a test is executed. + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + try { + foreach (DatabaseDriver::splitSql(file_get_contents(dirname(__DIR__) . '/Stubs/Schema/pgsql.sql')) as $query) { + static::$connection->setQuery($query) + ->execute(); + } + } catch (ExecutionFailureException $exception) { + $this->markTestSkipped( + \sprintf( + 'Could not load PostgreSQL database: %s', + $exception->getMessage() + ) + ); + } + } + /** * Tears down the fixture. * @@ -44,7 +72,7 @@ public static function setUpBeforeClass(): void protected function tearDown(): void { foreach (static::$connection->getTableList() as $table) { - static::$connection->truncateTable($table); + static::$connection->dropTable($table); } } diff --git a/Tests/Stubs/Schema/pgsql.sql b/Tests/Stubs/Schema/pgsql.sql index a112adfa1..10a8e056b 100644 --- a/Tests/Stubs/Schema/pgsql.sql +++ b/Tests/Stubs/Schema/pgsql.sql @@ -1,5 +1,4 @@ --- Purposefully do not add the table prefix to this file as it is mainly processed by the psql CLI or an application like pgAdmin -CREATE TABLE "dbtest" ( +CREATE TABLE "#__dbtest" ( "id" serial NOT NULL, "title" character varying(50) NOT NULL, "start_date" timestamp without time zone NOT NULL, diff --git a/phpunit.pgsql.xml.dist b/phpunit.pgsql.xml.dist index bc50e29f0..6857920a6 100644 --- a/phpunit.pgsql.xml.dist +++ b/phpunit.pgsql.xml.dist @@ -2,10 +2,10 @@ - - - - + + + +