diff --git a/.github/workflows/php-test.yml b/.github/workflows/php-test.yml index 3b014ba3e..4757794c5 100644 --- a/.github/workflows/php-test.yml +++ b/.github/workflows/php-test.yml @@ -73,6 +73,38 @@ jobs: with: php-version: ${{ matrix.php }} + - name: Install PHP dependencies + uses: ramsey/composer-install@v2 + with: + composer-options: '--prefer-dist --no-progress --no-interaction --no-scripts' + + # Installs a different PHPUnit version depending on the PHP version we're testing against. + # + # | WP / PHP | PHPUnit | + # |-----------|---------| + # | * / 7.0 | 6 | + # | * / 7.1 | 7 | + # | * / 7.2 | 8 | + # | * / 7.3 | 9 | + # | * / 7.4 | 9 | + # | * / 8 | 9 | + # + # See https://make.wordpress.org/core/handbook/references/phpunit-compatibility-and-wordpress-versions/ + - name: Update PHPUnit + run: | + if [[ $PHP_VERSION == "7.1" ]]; then + echo "Installing PHPUnit 7.5x" + composer require --ignore-platform-reqs --no-interaction --no-scripts phpunit/phpunit:^7.5 --with-dependencies + elif [[ $PHP_VERSION == "7.2" ]]; then + echo "Installing PHPUnit 8.5x" + composer require --ignore-platform-reqs --no-interaction --no-scripts phpunit/phpunit:^8.5 --with-dependencies + else + echo "Installing latest version of PHPUnit" + composer update --ignore-platform-reqs --no-interaction --no-scripts yoast/phpunit-polyfills --with-dependencies + fi + env: + PHP_VERSION: ${{ matrix.php }} + - name: Setup Node.js (.nvmrc) uses: actions/setup-node@v3 with: diff --git a/package.json b/package.json index 36015eeee..f1e2129bb 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,7 @@ "phpstan": "wp-env run tests-cli --env-cwd=wp-content/plugins/plugin-check/ composer run-script phpstan", "lint-php": "wp-env run tests-cli --env-cwd=wp-content/plugins/plugin-check/ composer run-script lint", "format-php": "wp-env run tests-cli --env-cwd=wp-content/plugins/plugin-check/ composer run-script format", - "pretest-php": "wp-env run tests-cli --env-cwd=wp-content/plugins/plugin-check/ composer install --no-interaction", "test-php": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/plugin-check/ vendor/bin/phpunit --verbose", - "pretest-php-coverage": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/plugin-check/ composer install --no-interaction", "test-php-coverage": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/plugin-check/ vendor/bin/phpunit --verbose --coverage-clover build/logs/php-coverage.xml", "test-php-multisite": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/plugin-check/ vendor/bin/phpunit -c tests/phpunit/multisite.xml --verbose", "test-php-multisite-coverage": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/plugin-check/ vendor/bin/phpunit -c tests/phpunit/multisite.xml --verbose --coverage-clover build/logs/php-coverage-multisite.xml"