Set up code coverage for unit tests #780
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PHP Unit Testing | |
on: | |
push: | |
branches: | |
- trunk | |
- 'release/**' | |
# Only run if PHP-related files changed. | |
paths: | |
- '.github/workflows/php-test.yml' | |
- '**.php' | |
- '.wp-env.json' | |
- '**/package.json' | |
- 'package-lock.json' | |
- 'phpunit.xml.dist' | |
- 'composer.json' | |
- 'composer.lock' | |
pull_request: | |
branches: | |
- trunk | |
- 'release/**' | |
- 'feature/**' | |
# Only run if PHP-related files changed. | |
paths: | |
- '.github/workflows/php-test.yml' | |
- '**.php' | |
- '.wp-env.json' | |
- '**/package.json' | |
- 'package-lock.json' | |
- 'phpunit.xml.dist' | |
- 'composer.json' | |
- 'composer.lock' | |
types: | |
- opened | |
- reopened | |
- synchronize | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | |
jobs: | |
php-test: | |
name: PHP ${{ matrix.php }} - WP ${{ matrix.wordpress }}${{ matrix.experimental && ' (experimental)' || '' }}${{ matrix.coverage && ' (with coverage)' || '' }} | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
strategy: | |
fail-fast: true | |
matrix: | |
php: | |
- '7.0' | |
- '7.1' | |
- '7.2' | |
- '7.3' | |
- '7.4' | |
- '8.0' | |
- '8.1' | |
wordpress: [ 'latest' ] | |
include: | |
- php: '8.2' | |
wordpress: 'latest' | |
coverage: true | |
- php: '8.2' | |
wordpress: 'trunk' | |
experimental: true | |
env: | |
WP_ENV_PHP_VERSION: ${{ matrix.php }} | |
WP_ENV_CORE: ${{ matrix.wordpress == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wordpress ) }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: shivammathur/setup-php@v2 | |
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: | |
node-version-file: '.nvmrc' | |
cache: npm | |
- name: npm install | |
run: npm ci | |
- name: Start WordPress | |
run: | | |
if [[ ${{ matrix.coverage == true }} == true ]]; then | |
npm run wp-env start -- --xdebug=coverage | |
else | |
npm run wp-env start | |
fi | |
- name: Run tests | |
run: | | |
if [[ ${{ matrix.coverage == true }} == true ]]; then | |
npm run test-php-coverage | |
npm run test-php-multisite-coverage | |
else | |
npm run test-php | |
npm run test-php-multisite | |
fi | |
- name: Upload code coverage report | |
if: ${{ matrix.coverage }} | |
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d | |
with: | |
file: build/logs/*.xml | |
flags: unit |