Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add a wrapper for PHPUnit binary #683

Merged
merged 1 commit into from
Aug 18, 2024
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
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
DATABASE_URL="mysql://root:[email protected]:3307/foundry_test?serverVersion=5.7.42"
MONGO_URL="mongodb://127.0.0.1:27018/dbName?compressors=disabled&gssapiServiceName=mongodb"
DATABASE_RESET_MODE="schema"
USE_DAMA_DOCTRINE_TEST_BUNDLE="0"
PHPUNIT_VERSION="9"
103 changes: 29 additions & 74 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,19 @@ 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
PHPUNIT_VERSION: 9
services:
mongo:
image: mongo:4
Expand Down Expand Up @@ -215,7 +191,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: ./phpunit --coverage-text --coverage-clover coverage.xml
shell: bash
env:
SYMFONY_DEPRECATIONS_HELPER: disabled
Expand All @@ -242,27 +218,6 @@ jobs:
env:
DOCS_DIR: 'docs/'

build-docs:
kbond marked this conversation as resolved.
Show resolved Hide resolved
name: Build Documentation
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

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

- name: Install dependencies
uses: ramsey/composer-install@v2
with:
composer-options: --prefer-dist

- name: Build docs
run: bin/build-docs

static-analysis:
name: Static Analysis
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/composer.lock
/phpunit.xml
/phpunit-dama-doctrine.xml
/phpunit-10.xml
/.phpunit.cache
/vendor/
/bin/tools/*/vendor/
/bin/tools/php-cs-fixer/composer.lock
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ $ composer update
$ composer test

# run only one permutation
$ vendor/bin/phpunit
$ ./phpunit

# run test suite with dama/doctrine-test-bundle
$ vendor/bin/phpunit -c phpunit.dama.xml.dist
$ USE_DAMA_DOCTRINE_TEST_BUNDLE=1 vendor/bin/phpunit

# run test suite with postgreSQL instead of MySQL
$ DATABASE_URL="postgresql://zenstruck:[email protected]:5433/zenstruck_foundry?serverVersion=15" vendor/bin/phpunit

# run test suite with another PHPUnit version
$ PHPUNIT_VERSION=10 vendor/bin/phpunit
```

### Overriding the default configuration
Expand All @@ -66,7 +69,10 @@ You can override default environment variables by creating a `.env.local` file,

```bash
# .env.local
DATABASE_URL="postgresql://zenstruck:[email protected]:5433/zenstruck_foundry?serverVersion=15"
DATABASE_URL="postgresql://zenstruck:[email protected]:5433/zenstruck_foundry?serverVersion=15" # enables postgreSQL instead of MySQL
MONGO_URL="" # disables Mongo
USE_DAMA_DOCTRINE_TEST_BUNDLE="1" # enables dama/doctrine-test-bundle
PHPUNIT_VERSION="11" # possible values: 9, 10, 11, 11.4

# run test suite with postgreSQL
$ vendor/bin/phpunit
Expand Down
38 changes: 19 additions & 19 deletions bin/tools/phpstan/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 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 Expand Up @@ -76,10 +76,10 @@
"@test-schema-dama",
"@test-migrate-dama"
],
"test-schema-no-dama": "DATABASE_RESET_MODE=schema vendor/bin/phpunit",
"test-migrate-no-dama": "DATABASE_RESET_MODE=migrate vendor/bin/phpunit",
"test-schema-dama": "DATABASE_RESET_MODE=schema vendor/bin/phpunit -c phpunit.dama.xml.dist",
"test-migrate-dama": "DATABASE_RESET_MODE=migrate vendor/bin/phpunit -c phpunit.dama.xml.dist"
"test-schema-no-dama": "DATABASE_RESET_MODE=schema USE_DAMA_DOCTRINE_TEST_BUNDLE=0 ./phpunit",
"test-migrate-no-dama": "DATABASE_RESET_MODE=migrate USE_DAMA_DOCTRINE_TEST_BUNDLE=0 ./phpunit",
"test-schema-dama": "DATABASE_RESET_MODE=schema USE_DAMA_DOCTRINE_TEST_BUNDLE=1 ./phpunit",
"test-migrate-dama": "DATABASE_RESET_MODE=migrate USE_DAMA_DOCTRINE_TEST_BUNDLE=1 ./phpunit"
},
"scripts-descriptions": {
"test": "Run all test permutations",
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ parameters:
- message: '#Return type of call to function Zenstruck\\Foundry\\Persistence\\proxy contains unresolvable type#'
path: src/Persistence/ProxyRepositoryDecorator.php

- message: '#Attribute class PHPUnit\\Framework\\Attributes\\(.*) does not exist.#'

# prevent PHPStan to force to type data providers
- identifier: missingType.iterableValue
path: tests/
Expand Down
Loading
Loading