Skip to content

PHP Unit Tests

PHP Unit Tests #1

Workflow file for this run

name: Unit Testing
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
unit-tests:
name: "WP ${{ matrix.config.wp }}, multisite: ${{ matrix.config.ms }}, PHP: ${{ matrix.config.php }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
config:
- { wp: 6.5.x, ms: 'yes', php: '8.1' }
- { wp: 6.5.x, ms: 'no', php: '8.1' }
- { wp: latest, ms: 'yes', php: '8.1' }
- { wp: latest, ms: 'no', php: '8.1' }
- { wp: latest, ms: 'yes', php: '8.1' }
- { wp: nightly, ms: 'no', php: '8.1' }
- { wp: nightly, ms: 'yes', php: '8.1' }
- { wp: 6.5.x, ms: 'yes', php: '8.2' }
- { wp: 6.5.x, ms: 'no', php: '8.2' }
- { wp: latest, ms: 'no', php: '8.2', coverage: 'yes' }
- { wp: latest, ms: 'yes', php: '8.2', coverage: 'yes' }
- { wp: nightly, ms: 'no', php: '8.2' }
- { wp: nightly, ms: 'yes', php: '8.2' }
- { wp: 6.5.x, ms: 'yes', php: '8.3' }
- { wp: 6.5.x, ms: 'no', php: '8.3' }
- { wp: latest, ms: 'no', php: '8.3' }
- { wp: latest, ms: 'yes', php: '8.3' }
- { wp: nightly, ms: 'no', php: '8.3' }
- { wp: nightly, ms: 'yes', php: '8.3' }
services:
mysql:
image: mariadb:latest
ports:
- "3306:3306"
env:
MYSQL_ROOT_PASSWORD: wordpress
MARIADB_INITDB_SKIP_TZINFO: 1
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
MYSQL_DATABASE: wordpress_test
steps:
- name: Check out source code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Decide whether to enable coverage
id: coverage
run: |
if [ "${{ matrix.config.coverage }}" = "yes" ]; then
echo "::set-output name=coverage::pcov"
echo '::set-output name=ini::pcov.directory=plugins/auth-monitoring, pcov.exclude="~/(vendor|node_modules)/~"'
else
echo "::set-output name=coverage::none"
fi
- name: Set up PHP
uses: shivammathur/setup-php@a4e22b60bbb9c1021113f2860347b0759f66fe5d # 2.30.0
with:
coverage: ${{ steps.coverage.outputs.coverage }}
ini-values: ${{ steps.coverage.outputs.ini }}
php-version: ${{ matrix.config.php }}
env:
fail-fast: 'true'
- name: Install PHP dependencies
uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # 3.0.0
- name: Set up WordPress and WordPress Test Library
uses: sjinks/setup-wordpress-test-library@badbd264eafbfd40b3d1c280b08c83ff1b500334 # 2.0.2
with:
version: ${{ matrix.config.wp }}
- name: Set up multisite mode
run: echo "WP_MULTISITE=1" >> $GITHUB_ENV
if: matrix.config.ms == 'yes'
- name: Verify MariaDB connection
run: |
while ! mysqladmin ping -h 127.0.0.1 -P ${{ job.services.mysql.ports[3306] }} --silent; do
sleep 1
done
timeout-minutes: 1
- name: Run tests
run: |
if [ "${{ steps.coverage.outputs.coverage }}" != 'none' ]; then
CMD=test:coverage
else
CMD=test
fi
composer "${CMD}" -- --order-by=random