ci: run PHPUnit in CI (tests exist, were never executed) (#2)
* ci: add PHPUnit workflow that runs the existing test suite 59 tests exist across 8 files but were never running in CI. This adds a ci.yml with PHP Lint + PHPCS + PHPUnit against WP test framework on a MySQL service. Agent-Session: cowork-pr-theme-tests-20260414 * ci: vendor install-wp-tests.sh for the PHPUnit workflow Standard WP-CLI scaffold script, lightly hardened. Kept in-repo instead of curl-from-github so CI is reproducible. Agent-Session: cowork-pr-theme-tests-20260414 * chore: retrigger CI after reviewer fix landed on main Agent-Session: cowork-pr-theme-tests-20260414 * ci: install subversion before bootstrap (svn no longer preinstalled) ubuntu-latest dropped svn from the default image. install-wp-tests.sh still uses svn to fetch the WP test suite from develop.svn.wordpress.org. Add a step to apt-install subversion before the bootstrap runs. Agent-Session: cowork-pr-theme-tests-20260414 * ci: skip db creation in install-wp-tests.sh (MySQL service already created it) Agent-Session: cowork-pr-theme-tests-20260414 * ci: WP_CORE_DIR needs trailing slash for ABSPATH substitution The wp-tests-config.php substitution copies WP_CORE_DIR into ABSPATH verbatim, then later WordPress concatenates wp-settings.php. Without the trailing slash you get /tmp/wordpresswp-settings.php. Agent-Session: cowork-pr-theme-tests-20260414
This commit is contained in:
112
.github/workflows/ci.yml
vendored
Normal file
112
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
name: CI — Lint & Test
|
||||
|
||||
# Runs on every PR and every push to main.
|
||||
# Three jobs in parallel:
|
||||
# 1. PHP Lint — syntax check across supported PHP versions
|
||||
# 2. PHPCS — WordPress coding standards (non-blocking during theme rollout)
|
||||
# 3. PHPUnit — runs the theme's test suite against the WordPress test framework
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
php-lint:
|
||||
name: PHP Lint (${{ matrix.php }})
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
php: ['7.4', '8.1', '8.3']
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Setup PHP ${{ matrix.php }}
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
coverage: none
|
||||
- name: Syntax check all PHP files
|
||||
run: |
|
||||
set -e
|
||||
find . -name '*.php' \
|
||||
-not -path './vendor/*' \
|
||||
-not -path './node_modules/*' \
|
||||
-not -path './.git/*' \
|
||||
-print0 | xargs -0 -n1 -P4 php -l > /dev/null
|
||||
|
||||
phpcs:
|
||||
name: PHPCS (WordPress standards)
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.1'
|
||||
coverage: none
|
||||
tools: composer:v2
|
||||
- name: Install dependencies
|
||||
run: composer install --no-progress --no-interaction --prefer-dist
|
||||
- name: Run PHPCS
|
||||
run: vendor/bin/phpcs --standard=.phpcs.xml.dist
|
||||
|
||||
phpunit:
|
||||
name: PHPUnit (PHP ${{ matrix.php }}, WP ${{ matrix.wp }})
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
php: ['8.1']
|
||||
wp: ['latest']
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:8.0
|
||||
env:
|
||||
MYSQL_ROOT_PASSWORD: root
|
||||
MYSQL_DATABASE: wp_tests
|
||||
ports:
|
||||
- 3306:3306
|
||||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install subversion
|
||||
# ubuntu-latest no longer ships svn preinstalled. The WP test suite
|
||||
# bootstrap script checks out develop.svn.wordpress.org via svn.
|
||||
run: sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends subversion
|
||||
- name: Setup PHP ${{ matrix.php }}
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
coverage: none
|
||||
tools: composer:v2
|
||||
extensions: mysqli
|
||||
- name: Install composer dependencies
|
||||
run: composer install --no-progress --no-interaction --prefer-dist
|
||||
- name: Wait for MySQL
|
||||
run: |
|
||||
for i in {1..30}; do
|
||||
if mysqladmin ping -h 127.0.0.1 -P 3306 -u root -proot --silent; then
|
||||
echo "MySQL is up"; break
|
||||
fi
|
||||
echo "Waiting for MySQL..."; sleep 2
|
||||
done
|
||||
- name: Install WordPress test suite
|
||||
env:
|
||||
WP_TESTS_DIR: /tmp/wordpress-tests-lib
|
||||
# Trailing slash matters: the bootstrap config substitutes this verbatim into ABSPATH,
|
||||
# then concatenates 'wp-settings.php'. Without the slash you get '/tmp/wordpresswp-settings.php'.
|
||||
WP_CORE_DIR: /tmp/wordpress/
|
||||
run: |
|
||||
chmod +x bin/install-wp-tests.sh
|
||||
# 6th arg = skip-database-creation: the MySQL service already created wp_tests via MYSQL_DATABASE env.
|
||||
bin/install-wp-tests.sh wp_tests root root 127.0.0.1:3306 ${{ matrix.wp }} true
|
||||
- name: Run PHPUnit
|
||||
env:
|
||||
WP_TESTS_DIR: /tmp/wordpress-tests-lib
|
||||
run: vendor/bin/phpunit --colors=always
|
||||
Reference in New Issue
Block a user