Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 81 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,93 @@ jobs:
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --with="phpunit/phpunit:~${{ matrix.phpunit }}"

- name: Execute tests
run: vendor/bin/phpunit
run: vendor/bin/phpunit --exclude-group database-external
env:
DB_PORT: ${{ job.services.mysql.ports[3306] }}
DB_USERNAME: root

database_driver_tests:
runs-on: ubuntu-24.04

services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: testing
ports:
- 33306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
postgres:
image: postgres:16
env:
POSTGRES_DB: testing
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 35432:5432
options: >-
--health-cmd="pg_isready -U postgres -d testing"
--health-interval=10s
--health-timeout=5s
--health-retries=5

strategy:
fail-fast: false
matrix:
driver: [mysql, pgsql]

name: External DB - ${{ matrix.driver }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.5
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, pdo_mysql, pgsql, pdo_pgsql
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: none

- name: Set Framework version
run: composer config version "2.x-dev"

- name: Install dependencies
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress --with="phpunit/phpunit:~12.5.8"

- name: Execute MySQL model query tests
if: matrix.driver == 'mysql'
run: vendor/bin/phpunit --group mysql
env:
DOPPAR_TEST_MYSQL_HOST: 127.0.0.1
DOPPAR_TEST_MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
DOPPAR_TEST_MYSQL_DATABASE: testing
DOPPAR_TEST_MYSQL_USERNAME: root
DOPPAR_TEST_MYSQL_PASSWORD: ''
DOPPAR_TEST_MYSQL_CHARSET: utf8mb4

- name: Execute PostgreSQL model query tests
if: matrix.driver == 'pgsql'
run: vendor/bin/phpunit --group pgsql
env:
DOPPAR_TEST_PGSQL_HOST: 127.0.0.1
DOPPAR_TEST_PGSQL_PORT: ${{ job.services.postgres.ports[5432] }}
DOPPAR_TEST_PGSQL_DATABASE: testing
DOPPAR_TEST_PGSQL_USERNAME: postgres
DOPPAR_TEST_PGSQL_PASSWORD: postgres

- name: Store artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: linux-logs-${{ matrix.php }}-${{ matrix.phpunit }}-${{ matrix.stability }}
name: external-db-logs-${{ matrix.driver }}
path: |
vendor/orchestra/testbench-core/doppar/storage/logs
!vendor/**/.gitignore
Expand Down Expand Up @@ -132,7 +209,7 @@ jobs:
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --with="phpunit/phpunit:~${{ matrix.phpunit }}"

- name: Execute tests
run: vendor/bin/phpunit
run: vendor/bin/phpunit --exclude-group database-external

- name: Store artifacts
if: always()
Expand All @@ -141,4 +218,4 @@ jobs:
name: windows-logs-${{ matrix.php }}-${{ matrix.phpunit }}-${{ matrix.stability }}
path: |
vendor/orchestra/testbench-core/doppar/storage/logs
!vendor/**/.gitignore
!vendor/**/.gitignore
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
"Tests\\": "tests/"
}
},
"scripts": {
"test": "vendor/bin/phpunit --exclude-group database-external",
"test:sqlite": "@test",
"test:mysql": "vendor/bin/phpunit --group mysql",
"test:pgsql": "vendor/bin/phpunit --group pgsql",
"test:all": "vendor/bin/phpunit"
},
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
Expand All @@ -74,4 +81,4 @@
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ protected function buildNestedRelationshipSubquery(Model $model, array $relation
$escapeValue = fn($val) => $this->escapeValue($val);

$currentModel = $model;
$currentTable = $this->table;
$rootAlias = $this->table . '_sub';
$currentTable = $rootAlias;
$joins = [];
$lastForeignKey = null;
$lastLocalKey = null;
Expand Down Expand Up @@ -243,7 +244,7 @@ protected function buildNestedRelationshipSubquery(Model $model, array $relation
}

// Build the final subquery
$subquery = "SELECT 1 FROM {$quote($this->table)} AS {$quote($this->table . '_sub')}";
$subquery = "SELECT 1 FROM {$quote($this->table)} AS {$quote($rootAlias)}";

// Add all the joins
$subquery .= ' ' . implode(' ', $joins);
Expand All @@ -254,7 +255,7 @@ protected function buildNestedRelationshipSubquery(Model $model, array $relation
$model->$firstRelation();
$firstLocalKey = $model->getLastLocalKey();

$subquery .= " WHERE {$quote($this->table . '_sub')}.{$quote($firstLocalKey)} = {$quote($this->table)}.{$quote($firstLocalKey)}";
$subquery .= " WHERE {$quote($rootAlias)}.{$quote($firstLocalKey)} = {$quote($this->table)}.{$quote($firstLocalKey)}";
}

// Add the condition on the final table
Expand Down
Loading
Loading