Skip to content

Update unit-tests.yml #50

Update unit-tests.yml

Update unit-tests.yml #50

Workflow file for this run

name: Unit Tests
on:
# Run on all pushes and on all pull requests.
# Prevent the build from running when there are only irrelevant changes.
push:
paths-ignore:
- '**.md'
- '**.txt'
pull_request:
paths-ignore:
- '**.md'
- '**.txt'
# Allow manually triggering the workflow.
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Notes regarding supported versions in WP:
# The base matrix only contains the PHP versions which are supported on all supported WP versions.
php: ['8.0', '8.1', '7.4']
wp: ['latest']
experimental: [false]
include:
# Complement the builds run via the matrix with high/low WP builds for PHP 7.4 and 8.0.
# PHP 8.0 is sort of supported since WP 5.6.
# PHP 7.4 is supported since WP 5.3.
- php: '8.3'
wp: 'latest'
experimental: true
- php: '8.2'
wp: 'latest'
experimental: true
- php: '8.2'
wp: '6.3'
experimental: true
- php: '8.0'
wp: '5.9'
experimental: true
name: "PHP ${{ matrix.php }} - WP ${{ matrix.wp }}"
continue-on-error: ${{ matrix.experimental }}
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: wordpress_test
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Subversion
run: sudo apt-get update && sudo apt-get install -y subversion
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mysql, mysqli
coverage: none
tools: composer, phpunit
- name: Get Composer Cache Directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Remove composer.lock
run: rm -f composer.lock
- name: Install dependencies
run: |
composer install --no-interaction --prefer-dist --no-progress
- name: Install WordPress Test Suite
env:
WP_VERSION: ${{ matrix.wp }}
run: |
bash phpunit/install.sh wordpress_test root root localhost ${{ matrix.wp }}
- name: Determine supported PHPUnit version
id: set_phpunit
run: |
if [[ "${{ matrix.php }}" > "8.0" ]]; then
echo "PHPUNIT=9.*" >> $GITHUB_ENV
else
echo "PHPUNIT=5.7.*||6.*||7.5.*||8.5.*" >> $GITHUB_ENV
fi
- name: 'Composer: set up PHPUnit'
env:
PHPUNIT: ${{ env.PHPUNIT }}
run: composer require --no-update phpunit/phpunit:"${{ env.PHPUNIT }}"
# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies for PHP < 8.0
if: ${{ matrix.php < 8.0 }}
uses: "ramsey/composer-install@v2"
# For the PHP 8.0 and above, we need to install with ignore platform reqs as not all dependencies allow it yet.
- name: Install Composer dependencies for PHP >= 8.0
if: ${{ matrix.php >= 8.0 }}
uses: "ramsey/composer-install@v2"
with:
composer-options: --ignore-platform-reqs
- name: 'Run Composer Update'
run: |
composer update --ignore-platform-reqs
- name: Tool versions
run: |
php --version
composer --version
phpunit --version
which phpunit
- name: Run PHPUnit
env:
WP_TESTS_DIR: /tmp/wordpress-tests-lib
run: vendor/bin/phpunit
- name: Run the unit tests - multisite
run: vendor/bin/phpunit
env:
WP_MULTISITE: 1