diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b5659d25..5df09b069 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -19,6 +19,7 @@ jobs: database: [ mysql, mongo ] use-dama: [ 1 ] use-migrate: [ 0 ] + phpunit: [ 9 ] exclude: - php: 8.1 symfony: 7.0.* @@ -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' || '' }} @@ -119,60 +143,10 @@ 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 @@ -180,6 +154,8 @@ jobs: 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 @@ -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 @@ -242,27 +218,6 @@ jobs: env: DOCS_DIR: 'docs/' - build-docs: - 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 diff --git a/.gitignore b/.gitignore index 670bad451..ee9e61fd3 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/bin/tools/phpstan/composer.lock b/bin/tools/phpstan/composer.lock index 433b35c76..a8b309c85 100644 --- a/bin/tools/phpstan/composer.lock +++ b/bin/tools/phpstan/composer.lock @@ -117,16 +117,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.11.3", + "version": "1.11.10", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "e64220a05c1209fc856d58e789c3b7a32c0bb9a5" + "reference": "640410b32995914bde3eed26fa89552f9c2c082f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e64220a05c1209fc856d58e789c3b7a32c0bb9a5", - "reference": "e64220a05c1209fc856d58e789c3b7a32c0bb9a5", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/640410b32995914bde3eed26fa89552f9c2c082f", + "reference": "640410b32995914bde3eed26fa89552f9c2c082f", "shasum": "" }, "require": { @@ -171,25 +171,25 @@ "type": "github" } ], - "time": "2024-05-31T13:53:37+00:00" + "time": "2024-08-08T09:02:50+00:00" }, { "name": "phpstan/phpstan-doctrine", - "version": "1.4.1", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-doctrine.git", - "reference": "a223e357c5f153b446b8a5da57dbc1132eb7a88d" + "reference": "caa046bd6152818e781260fb3a7a96d6b0fadeed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/a223e357c5f153b446b8a5da57dbc1132eb7a88d", - "reference": "a223e357c5f153b446b8a5da57dbc1132eb7a88d", + "url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/caa046bd6152818e781260fb3a7a96d6b0fadeed", + "reference": "caa046bd6152818e781260fb3a7a96d6b0fadeed", "shasum": "" }, "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.11" + "phpstan/phpstan": "^1.11.7" }, "conflict": { "doctrine/collections": "<1.0", @@ -241,9 +241,9 @@ "description": "Doctrine extensions for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-doctrine/issues", - "source": "https://github.com/phpstan/phpstan-doctrine/tree/1.4.1" + "source": "https://github.com/phpstan/phpstan-doctrine/tree/1.5.0" }, - "time": "2024-05-28T15:37:29+00:00" + "time": "2024-08-05T13:47:07+00:00" }, { "name": "phpstan/phpstan-phpunit", @@ -299,22 +299,22 @@ }, { "name": "phpstan/phpstan-symfony", - "version": "1.4.3", + "version": "1.4.6", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-symfony.git", - "reference": "af6ae0f4b91bc080265e80776af26da3e5befb28" + "reference": "e909a075d69e0d4db262ac3407350ae2c6b6ab5f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-symfony/zipball/af6ae0f4b91bc080265e80776af26da3e5befb28", - "reference": "af6ae0f4b91bc080265e80776af26da3e5befb28", + "url": "https://api.github.com/repos/phpstan/phpstan-symfony/zipball/e909a075d69e0d4db262ac3407350ae2c6b6ab5f", + "reference": "e909a075d69e0d4db262ac3407350ae2c6b6ab5f", "shasum": "" }, "require": { "ext-simplexml": "*", "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.11" + "phpstan/phpstan": "^1.11.7" }, "conflict": { "symfony/framework-bundle": "<3.0" @@ -365,9 +365,9 @@ "description": "Symfony Framework extensions and rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-symfony/issues", - "source": "https://github.com/phpstan/phpstan-symfony/tree/1.4.3" + "source": "https://github.com/phpstan/phpstan-symfony/tree/1.4.6" }, - "time": "2024-05-30T15:01:27+00:00" + "time": "2024-07-16T11:48:54+00:00" } ], "packages-dev": [], diff --git a/composer.json b/composer.json index 325ebe8cb..9038492c0 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/phpstan.neon b/phpstan.neon index 35138158c..030b3b5e3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -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/ diff --git a/phpunit b/phpunit new file mode 100755 index 000000000..e9e9d337c --- /dev/null +++ b/phpunit @@ -0,0 +1,83 @@ +#!/bin/bash + +set -o errexit +set -o nounset + +check_phpunit_version() { + INSTALLED_PHPUNIT_VERSION=$(composer info phpunit/phpunit | grep versions | cut -c 14-) + + REQUIRED_PHPUNIT_VERSION="${1?}" + + if [[ "${INSTALLED_PHPUNIT_VERSION}" == *"dev"* ]] && [ "${REQUIRED_PHPUNIT_VERSION}" != "11.4" ]; then + echo 0; + elif [[ "${INSTALLED_PHPUNIT_VERSION}" == "${REQUIRED_PHPUNIT_VERSION}"* ]]; 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 +### << diff --git a/phpunit-10.xml.dist b/phpunit-10.xml.dist index 2e25f73f4..1727f9b8b 100644 --- a/phpunit-10.xml.dist +++ b/phpunit-10.xml.dist @@ -1,23 +1,26 @@ - - - - - - - - - - tests - - - - - src - - - - - + + + + + + + + + + tests + + + + + src + + diff --git a/phpunit.dama.xml.dist b/phpunit.dama.xml.dist deleted file mode 100644 index 75b4ab93d..000000000 --- a/phpunit.dama.xml.dist +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - tests - - - - - - src - - - - - - - - - - - diff --git a/rector-phpunit-10.php b/rector-phpunit-10.php deleted file mode 100644 index 2e9df9f1c..000000000 --- a/rector-phpunit-10.php +++ /dev/null @@ -1,16 +0,0 @@ -withPaths([ - __DIR__.'/tests', - ]) - ->withSets([ - PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES, - ]); diff --git a/tests/Fixture/TestKernel.php b/tests/Fixture/TestKernel.php index c94c45310..990a7acbb 100644 --- a/tests/Fixture/TestKernel.php +++ b/tests/Fixture/TestKernel.php @@ -101,6 +101,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load 'alias' => 'Model', ], ], + 'controller_resolver' => ['auto_mapping' => true] ], ]); diff --git a/tests/Integration/Maker/MakerTestCase.php b/tests/Integration/Maker/MakerTestCase.php index fc278f3d3..3e0c389dd 100644 --- a/tests/Integration/Maker/MakerTestCase.php +++ b/tests/Integration/Maker/MakerTestCase.php @@ -42,7 +42,7 @@ protected static function tempFile(string $path): string protected function expectedFile(): string { - $testName = \method_exists($this, 'getName') ? $this->getName() : $this->nameWithDataSet(); // @phpstan-ignore method.notFound + $testName = \method_exists($this, 'getName') ? $this->getName() : $this->nameWithDataSet(); $path = \sprintf( __DIR__.'/../../Fixture/Maker/expected/%s.php',