Skip to content

Commit

Permalink
chore: add a wrapper for PHPUnit binary
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil committed Aug 8, 2024
1 parent 8bf8c4c commit e30cd8d
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 93 deletions.
81 changes: 28 additions & 53 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
tests:
name: P:${{ matrix.php }}, S:${{ matrix.symfony }}, D:${{ matrix.database }}${{ matrix.deps == 'lowest' && ' (lowest)' || '' }}${{ matrix.use-dama == 1 && contains(matrix.database, 'sql') && ' (dama)' || '' }}${{ !contains(matrix.database, 'sql') && '' || matrix.use-migrate == 1 && ' (migrate)' || ' (schema)' }}
name: P:${{ matrix.php }}, S:${{ matrix.symfony }}, D:${{ matrix.database }}, PU:${{ matrix.phpunit }}${{ matrix.deps == 'lowest' && ' (lowest)' || '' }}${{ matrix.use-dama == 1 && contains(matrix.database, 'sql') && ' (dama)' || '' }}${{ !contains(matrix.database, 'sql') && '' || matrix.use-migrate == 1 && ' (migrate)' || ' (schema)' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -19,6 +19,7 @@ jobs:
database: [ mysql, mongo ]
use-dama: [ 1 ]
use-migrate: [ 0 ]
phpunit: [ 9 ]
exclude:
- php: 8.1
symfony: 7.0.*
Expand All @@ -31,52 +32,75 @@ jobs:
database: none
use-dama: 1
use-migrate: 0
phpunit: 9
- php: 8.3
deps: highest
symfony: '*'
database: mysql|mongo
use-dama: 1
use-migrate: 0
phpunit: 9
- php: 8.3
deps: highest
symfony: '*'
database: pgsql|mongo
use-dama: 1
use-migrate: 0
phpunit: 9
- php: 8.3
deps: highest
symfony: '*'
database: pgsql
use-dama: 0
use-migrate: 0
phpunit: 9
- php: 8.3
deps: highest
symfony: '*'
database: sqlite
use-dama: 0
use-migrate: 0
phpunit: 9
- php: 8.3
deps: lowest
symfony: '*'
database: sqlite
use-dama: 0
use-migrate: 0
phpunit: 9
- php: 8.3
deps: lowest
symfony: '*'
database: mysql
use-dama: 1
use-migrate: 0
phpunit: 9
- php: 8.3
deps: highest
symfony: '*'
database: mysql
use-dama: 1
use-migrate: 1
phpunit: 9
- php: 8.3
deps: highest
symfony: '*'
database: mysql|mongo
use-dama: 1
use-migrate: 0
phpunit: 10
- php: 8.3
deps: highest
symfony: '*'
database: mysql|mongo
use-dama: 1
use-migrate: 0
phpunit: 11
env:
DATABASE_URL: ${{ contains(matrix.database, 'mysql') && 'mysql://root:root@localhost:3306/foundry?serverVersion=5.7.42' || contains(matrix.database, 'pgsql') && 'postgresql://root:root@localhost:5432/foundry?serverVersion=15' || contains(matrix.database, 'sqlite') && 'sqlite:///%kernel.project_dir%/var/data.db' || '' }}
MONGO_URL: ${{ contains(matrix.database, 'mongo') && 'mongodb://127.0.0.1:27017/dbName?compressors=disabled&gssapiServiceName=mongodb' || '' }}
USE_DAMA_DOCTRINE_TEST_BUNDLE: ${{ matrix.use-dama == 1 && contains(matrix.database, 'sql') && 1 || 0 }}
PHPUNIT_VERSION: ${{ matrix.phpunit }}
services:
postgres:
image: ${{ contains(matrix.database, 'pgsql') && 'postgres:15' || '' }}
Expand Down Expand Up @@ -119,67 +143,18 @@ jobs:
run: sudo /etc/init.d/mysql start

- name: Test
run: vendor/bin/phpunit -c "${PHPUNIT_CONFIG_FILE}"
run: ./phpunit
shell: bash
env:
DATABASE_RESET_MODE: ${{ matrix.use-migrate == 1 && 'migrate' || 'schema' }}
PHPUNIT_CONFIG_FILE: ${{ env.USE_DAMA_DOCTRINE_TEST_BUNDLE == 1 && 'phpunit.dama.xml.dist' || 'phpunit.xml.dist' }}

tests-no-phpunit-bridge:
name: PHPUnit:${{ matrix.phpunit }}, P:8.3, S:7.1.*, D:mysql|mongo (dama) (schema)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
phpunit: [10, 11]
env:
DATABASE_URL: 'mysql://root:root@localhost:3306/foundry?serverVersion=5.7.42'
MONGO_URL: 'mongodb://127.0.0.1:27017/dbName?compressors=disabled&gssapiServiceName=mongodb'
services:
mongo:
image: 'mongo:4'
ports:
- 27017:27017
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
coverage: none
tools: flex

- name: Install dependencies
uses: ramsey/composer-install@v2
with:
composer-options: --prefer-dist
env:
SYMFONY_REQUIRE: 7.1.*

- name: Set up MySQL
run: sudo /etc/init.d/mysql start

- name: Install PHPUnit ${{ matrix.phpunit }}
run: |
composer remove --dev symfony/phpunit-bridge
composer require --dev phpunit/phpunit:^${{ matrix.phpunit }} -W
- name: Install rector and change PHPUnit metadata from annotations to attributes
run: |
composer bin rector require --dev rector/rector
bin/tools/rector/vendor/rector/rector/bin/rector -c rector-phpunit-10.php
- name: Test
run: vendor/bin/phpunit -c phpunit-10.xml.dist

code-coverage:
name: Code Coverage
runs-on: ubuntu-latest
env:
DATABASE_URL: postgresql://root:root@localhost:5432/foundry?serverVersion=15
MONGO_URL: mongodb://127.0.0.1:27017/dbName?compressors=disabled&gssapiServiceName=mongodb
USE_DAMA_DOCTRINE_TEST_BUNDLE: 1
services:
mongo:
image: mongo:4
Expand Down Expand Up @@ -215,7 +190,7 @@ jobs:
composer-options: --prefer-dist

- name: Test with coverage
run: vendor/bin/phpunit -c phpunit.dama.xml.dist --coverage-text --coverage-clover coverage.xml
run: vendor/bin/phpunit --coverage-text --coverage-clover coverage.xml
shell: bash
env:
SYMFONY_DEPRECATIONS_HELPER: disabled
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8",
"dama/doctrine-test-bundle": "^7.0|^8.0",
"doctrine/common": "^3.2",
"doctrine/collections": "^1.7|^2.0",
"doctrine/common": "^3.2",
"doctrine/doctrine-bundle": "^2.10",
"doctrine/doctrine-migrations-bundle": "^2.2|^3.0",
"doctrine/mongodb-odm-bundle": "^4.6|^5.0",
"doctrine/orm": "^2.16|^3.0",
"phpunit/phpunit": "^9.5.0",
"phpunit/phpunit": "^9.5.0 || ^10.0 || ^11.0",
"symfony/console": "^6.4|^7.0",
"symfony/dotenv": "^6.4|^7.0",
"symfony/maker-bundle": "^1.55",
Expand Down
79 changes: 79 additions & 0 deletions phpunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

set -o errexit
set -o nounset

check_phpunit_version() {
INSTALLED_PHPUNIT_VERSION=$(composer info phpunit/phpunit | grep versions | cut -c 14-)

if [[ "${INSTALLED_PHPUNIT_VERSION}" == "${1?}"* ]]; then
echo 1;
else
echo 0;
fi
}

### >> load env vars from .env files if not in CI
if [ -z "${CI:-}" ]; then
source .env

if [ -f .env.local ]; then
source .env.local
fi
fi
### <<

### >> update PHPUnit if needed
if [[ " 9 10 11 11.4 " != *" ${PHPUNIT_VERSION-9} "* ]]; then
echo "❌ PHPUNIT_VERSION should be one of 9, 10, 11, 11.4";
exit 1;
fi

SHOULD_UPDATE_PHPUNIT=$(check_phpunit_version "${PHPUNIT_VERSION}")

if [ "${SHOULD_UPDATE_PHPUNIT}" = "0" ]; then
echo "ℹ️ Upgrading PHPUnit to ${PHPUNIT_VERSION}"
if [ "${PHPUNIT_VERSION}" = "9" ]; then
composer update phpunit/phpunit:^9 -W --dev
else
if [ "${PHPUNIT_VERSION}" = "11.4" ]; then
composer update phpunit/phpunit:11.4.x-dev -W --dev
else
composer update "phpunit/phpunit:^${PHPUNIT_VERSION}" -W --dev
fi
fi
fi
### <<

### >> guess extensions
EXTENSION=""

if [ "${USE_DAMA_DOCTRINE_TEST_BUNDLE:-0}" = "1" ]; then
EXTENSION="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension"
fi
### <<

### >> actually execute PHPUnit with the right options
case ${PHPUNIT_VERSION} in
"9")
if [ -z "${EXTENSION}" ]; then
vendor/bin/phpunit -c phpunit.xml.dist "$@"
else
vendor/bin/phpunit -c phpunit.xml.dist --extensions "${EXTENSION}" "$@"
fi
;;

"10")
# PHPUnit 10 does not have a --extension option
vendor/bin/phpunit -c phpunit-10.xml.dist "$@"
;;

"11"|"11.4")
if [ -z "${EXTENSION}" ]; then
vendor/bin/phpunit -c phpunit-10.xml.dist "$@"
else
vendor/bin/phpunit -c phpunit-10.xml.dist --extension "${EXTENSION}" "$@"
fi
;;
esac
### <<
38 changes: 0 additions & 38 deletions phpunit.dama.xml.dist

This file was deleted.

0 comments on commit e30cd8d

Please sign in to comment.