From 28040553671d20c512c7ede077eac1253ede1729 Mon Sep 17 00:00:00 2001 From: yoeriwalstra Date: Tue, 12 May 2026 16:55:08 +0200 Subject: [PATCH] replace sqlite with postgres --- .github/workflows/tests.yml | 23 ++++++++++++++++++++++- Dockerfile | 4 ++-- docker-compose.yml | 21 +++++++++++++++++++++ tests/TestCase.php | 8 ++++++-- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a91bb2e..3ddcb7a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,6 +11,21 @@ jobs: name: PHP ${{ matrix.php }} / Laravel ${{ matrix.laravel }} runs-on: ubuntu-latest + services: + postgres: + image: postgres:16-alpine + env: + POSTGRES_DB: resource_cleanup_testing + POSTGRES_USER: testing + POSTGRES_PASSWORD: testing + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U testing -d resource_cleanup_testing" + --health-interval 3s + --health-timeout 5s + --health-retries 10 + strategy: fail-fast: false matrix: @@ -31,7 +46,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: mbstring, pdo, pdo_sqlite, sqlite3 + extensions: mbstring, pdo, pdo_pgsql coverage: none - name: Install dependencies @@ -45,3 +60,9 @@ jobs: - name: Run tests run: vendor/bin/phpunit + env: + DB_HOST: 127.0.0.1 + DB_PORT: 5432 + DB_DATABASE: resource_cleanup_testing + DB_USERNAME: testing + DB_PASSWORD: testing diff --git a/Dockerfile b/Dockerfile index 0de6e73..e18e881 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,8 @@ RUN apk add --no-cache \ git \ unzip \ curl \ - sqlite-dev \ - && docker-php-ext-install pdo pdo_sqlite + libpq-dev \ + && docker-php-ext-install pdo pdo_pgsql # Install Composer COPY --from=composer:2 /usr/bin/composer /usr/bin/composer diff --git a/docker-compose.yml b/docker-compose.yml index 3916d1d..557c02a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,3 +7,24 @@ services: # Mount the source so edits are reflected instantly without rebuilding - .:/app command: vendor/bin/phpunit + depends_on: + postgres: + condition: service_healthy + environment: + DB_HOST: postgres + DB_PORT: 5432 + DB_DATABASE: resource_cleanup_testing + DB_USERNAME: testing + DB_PASSWORD: testing + + postgres: + image: postgres:16-alpine + environment: + POSTGRES_DB: resource_cleanup_testing + POSTGRES_USER: testing + POSTGRES_PASSWORD: testing + healthcheck: + test: [ "CMD-SHELL", "pg_isready -U testing -d resource_cleanup_testing" ] + interval: 3s + timeout: 5s + retries: 10 diff --git a/tests/TestCase.php b/tests/TestCase.php index c043b93..f27e0d4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -20,8 +20,12 @@ protected function getEnvironmentSetUp($app): void { $app['config']->set('database.default', 'testing'); $app['config']->set('database.connections.testing', [ - 'driver' => 'sqlite', - 'database' => ':memory:', + 'driver' => 'pgsql', + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', 5432), + 'database' => env('DB_DATABASE', 'resource_cleanup_testing'), + 'username' => env('DB_USERNAME', 'testing'), + 'password' => env('DB_PASSWORD', 'testing'), 'prefix' => '', ]); }