Skip to content

Commit

Permalink
Reduce duplication of EXPECT_DB_DRIVER env var, require it in CI
Browse files Browse the repository at this point in the history
Set the EXPECT_DB_DRIVER consistently across all steps of each job
rather than duplicating it from step to step. It can't go higher
than job level (even if github supported that) since not all jobs
are matrix jobs.

Additionally, when the `CI` env var is set then enforce that an
`EXPECT_DB_DRIVER` value must also be set. This will help protect
against falling back to the wrong driver again on future updates to
CI config / platform.
  • Loading branch information
acoulton committed Mar 12, 2021
1 parent 35dbfb6 commit 10c8633
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
phpunit-smoke-check:
name: "PHPUnit with SQLite"
runs-on: "ubuntu-20.04"
env:
EXPECT_DB_DRIVER: pdo_sqlite

strategy:
matrix:
Expand Down Expand Up @@ -48,7 +50,6 @@ jobs:
run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --coverage-clover=coverage-no-cache.xml"
env:
ENABLE_SECOND_LEVEL_CACHE: 0
EXPECT_DB_DRIVER: pdo_sqlite

- name: "Run PHPUnit with Second Level Cache"
run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --exclude-group performance,non-cacheable,locking_functional --coverage-clover=coverage-cache.xml"
Expand All @@ -66,6 +67,8 @@ jobs:
name: "PHPUnit with PostgreSQL"
runs-on: "ubuntu-20.04"
needs: "phpunit-smoke-check"
env:
EXPECT_DB_DRIVER: pdo_pgsql

strategy:
matrix:
Expand Down Expand Up @@ -105,8 +108,6 @@ jobs:

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/pdo_pgsql.xml --coverage-clover=coverage.xml"
env:
EXPECT_DB_DRIVER: pdo_pgsql

- name: "Upload coverage file"
uses: "actions/upload-artifact@v2"
Expand All @@ -119,6 +120,8 @@ jobs:
name: "PHPUnit with MariaDB"
runs-on: "ubuntu-20.04"
needs: "phpunit-smoke-check"
env:
EXPECT_DB_DRIVER: ${{ matrix.extension }}

strategy:
matrix:
Expand Down Expand Up @@ -162,8 +165,6 @@ jobs:

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage.xml"
env:
EXPECT_DB_DRIVER: ${{ matrix.extension }}

- name: "Upload coverage file"
uses: "actions/upload-artifact@v2"
Expand All @@ -176,6 +177,8 @@ jobs:
name: "PHPUnit with MySQL"
runs-on: "ubuntu-20.04"
needs: "phpunit-smoke-check"
env:
EXPECT_DB_DRIVER: ${{ matrix.extension }}

strategy:
matrix:
Expand Down Expand Up @@ -221,13 +224,11 @@ jobs:
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage-no-cache.xml"
env:
ENABLE_SECOND_LEVEL_CACHE: 0
EXPECT_DB_DRIVER: ${{ matrix.extension }}

- name: "Run PHPUnit with Second Level Cache"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --exclude-group performance,non-cacheable,locking_functional --coverage-clover=coverage-no-cache.xml"
env:
ENABLE_SECOND_LEVEL_CACHE: 1
EXPECT_DB_DRIVER: ${{ matrix.extension }}

- name: "Upload coverage files"
uses: "actions/upload-artifact@v2"
Expand Down
6 changes: 6 additions & 0 deletions tests/Doctrine/Tests/TestUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public static function getConnection(): Connection
);

$expectDriver = getenv('EXPECT_DB_DRIVER');
if (getenv('CI') && empty($expectDriver)) {
throw new UnexpectedValueException(
'CI builds must provide an EXPECT_DB_DRIVER environment variable'
);
}

if ($expectDriver && ($expectDriver !== $params['driver'])) {
// Compare the resolved driver type manually rather than using a phpunit assert method, so that we don't
// affect phpunit's count of assertions run during the calling test.
Expand Down

0 comments on commit 10c8633

Please sign in to comment.