Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/phpunit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: PHPUnit Test Runner

on:
workflow_call:
inputs:
php-version:
required: false
type: string
default: '8.1'
description: 'PHP version to test against'

jobs:
phpunit-test:
name: PHPUnit tests (PHP ${{ inputs.php-version }})
runs-on: ubuntu-22.04

services:
mysql:
image: mysql:8.0
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 source code
uses: actions/checkout@v4

- name: Set up PHP
uses: codesnippetspro/setup-php@v2
with:
php-version: ${{ inputs.php-version }}

- name: Compute dependency hash
id: deps-hash
run: |
set -euo pipefail
tmpfile=$(mktemp)
if [ -f "src/composer.lock" ]; then
cat "src/composer.lock" >> "$tmpfile"
fi
if [ -s "$tmpfile" ]; then
deps_hash=$(shasum -a 1 "$tmpfile" | awk '{print $1}' | cut -c1-8)
else
deps_hash=$(echo "${GITHUB_SHA:-unknown}" | cut -c1-8)
fi
echo "deps_hash=$deps_hash" >> "$GITHUB_OUTPUT"

- name: Get Composer cache
id: composer-cache
uses: actions/cache/restore@v4
with:
path: src/vendor
key: ${{ runner.os }}-php-${{ inputs.php-version }}-composer-${{ steps.deps-hash.outputs.deps_hash }}
restore-keys: |
${{ runner.os }}-php-${{ inputs.php-version }}-composer-

- name: Install Composer dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: |
cd src
composer install --no-progress --prefer-dist --optimize-autoloader

- name: Save Composer cache
if: steps.composer-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: src/vendor
key: ${{ runner.os }}-php-${{ inputs.php-version }}-composer-${{ steps.deps-hash.outputs.deps_hash }}

- name: Install WordPress test suite
run: |
bash tests/install-wp-tests.sh wordpress_test root root 127.0.0.1:3306 latest true

- name: Run PHPUnit tests
run: |
cd src
vendor/bin/phpunit -c ../phpunit.xml --testdox

- uses: actions/upload-artifact@v4
if: always()
with:
name: phpunit-test-results-php-${{ inputs.php-version }}
path: |
.phpunit.result.cache
if-no-files-found: ignore
retention-days: 2

79 changes: 79 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: "(Test): PHPUnit"

on:
pull_request:
types: [labeled, synchronize, opened, reopened]
push:
branches:
- 'core'
- 'pro'
paths-ignore:
- '**.md'
- '**.txt'
- '.gitignore'
- 'docs/**'
workflow_dispatch:

permissions:
contents: read
pull-requests: read
actions: read

concurrency:
group: phpunit-${{ github.event_name }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
phpunit-php-7-4:
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests')
uses: ./.github/workflows/phpunit-test.yml
with:
php-version: '7.4'

phpunit-php-8-0:
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests')
uses: ./.github/workflows/phpunit-test.yml
with:
php-version: '8.0'

phpunit-php-8-1:
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests')
uses: ./.github/workflows/phpunit-test.yml
with:
php-version: '8.1'

phpunit-php-8-2:
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests')
uses: ./.github/workflows/phpunit-test.yml
with:
php-version: '8.2'

phpunit-php-8-3:
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests')
uses: ./.github/workflows/phpunit-test.yml
with:
php-version: '8.3'

test-result:
needs: [phpunit-php-7-4, phpunit-php-8-0, phpunit-php-8-1, phpunit-php-8-2, phpunit-php-8-3]
if: always() && (needs.phpunit-php-7-4.result != 'skipped' || needs.phpunit-php-8-0.result != 'skipped' || needs.phpunit-php-8-1.result != 'skipped' || needs.phpunit-php-8-2.result != 'skipped' || needs.phpunit-php-8-3.result != 'skipped')
runs-on: ubuntu-22.04
name: PHPUnit - Test Results Summary
steps:
- name: Test status summary
run: |
echo "PHP 7.4: ${{ needs.phpunit-php-7-4.result }}"
echo "PHP 8.0: ${{ needs.phpunit-php-8-0.result }}"
echo "PHP 8.1: ${{ needs.phpunit-php-8-1.result }}"
echo "PHP 8.2: ${{ needs.phpunit-php-8-2.result }}"
echo "PHP 8.3: ${{ needs.phpunit-php-8-3.result }}"

- name: Check overall status
if: |
(needs.phpunit-php-7-4.result != 'success' && needs.phpunit-php-7-4.result != 'skipped') ||
(needs.phpunit-php-8-0.result != 'success' && needs.phpunit-php-8-0.result != 'skipped') ||
(needs.phpunit-php-8-1.result != 'success' && needs.phpunit-php-8-1.result != 'skipped') ||
(needs.phpunit-php-8-2.result != 'success' && needs.phpunit-php-8-2.result != 'skipped') ||
(needs.phpunit-php-8-3.result != 'success' && needs.phpunit-php-8-3.result != 'skipped')
run: exit 1

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ node_modules/
npm-debug.log
.sass-cache/

# PHPUnit
.phpunit.result.cache
/coverage/

# Playwright
playwright-report/
test-results/
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"test": "tests"
},
"scripts": {
"test:php": "cd src && vendor/bin/phpunit -c ../phpunit.xml",
"test:php:watch": "npm run test:php -- --testdox",
"test:playwright": "playwright test -c tests/playwright/playwright.config.ts",
"test:playwright:debug": "npm run test:playwright -- --debug",
"test:playwright:ui": "npm run test:playwright -- --ui",
Expand Down
4 changes: 3 additions & 1 deletion src/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"require-dev": {
"wp-coding-standards/wpcs": "^3.1",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0"
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"phpunit/phpunit": "^9.6",
"yoast/phpunit-polyfills": "^2.0"
},
"config": {
"platform": {
Expand Down
Loading
Loading