Skip to content
Merged
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
6 changes: 5 additions & 1 deletion .env.testing.slic
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Consumed by both CI and local slic runs.
WP_VERSION=latest
#
# There is deliberately no WP_VERSION here: slic ignores it. In CI the
# WordPress version is set by the workflow's "Pin the WordPress version" step
# (site-cli core update), and locally you get whatever core the slic image
# ships.
WP_ROOT_FOLDER=/var/www/html
WP_URL=http://plugin-absorber.test
WP_DOMAIN=plugin-absorber.test
Expand Down
156 changes: 156 additions & 0 deletions .github/workflows/tests-php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# cspell:ignore DotReporter
name: PHP Tests

on:
pull_request:
push:
branches:
- main
workflow_dispatch:

# This workflow only reads the repository. Narrow the token accordingly.
permissions:
contents: read

# A superseded PR run is a result nobody is waiting on any more. Pushes to a
# long-lived branch are left alone so their history stays complete.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 20

# A broken WordPress nightly is upstream's problem, not this library's, so
# those legs report without blocking the PR.
continue-on-error: ${{ matrix.wp == 'nightly' }}

strategy:
fail-fast: false
matrix:
# The ends of the supported range only. A deprecation introduced at any
# PHP version fires on every later one, so 8.5 catches what 8.0-8.4
# would, and every leg resolves identical dependencies because
# config.platform.php pins resolution to 7.4 regardless of runtime.
php:
- "7.4"
- "8.5"
# The nightly column is early warning for core regressions; when a
# nightly leg is red, its latest counterpart on the same PHP tells you
# whether WordPress or PHP is at fault.
wp:
- "latest"
- "nightly"

name: "Tests: PHP ${{ matrix.php }} / WP ${{ matrix.wp }}"

steps:
- name: Checkout the repository
uses: actions/checkout@v6
with:
fetch-depth: 1

# This workflow reaches into slic's own file layout, so tracking its main
# branch would let an upstream reorganisation change CI without a commit
# here. Pin to a tag and bump it deliberately when slic is upgraded.
- name: Checkout slic
uses: actions/checkout@v6
with:
repository: stellarwp/slic
ref: "2.3.0"
path: slic
fetch-depth: 1

# Codeception refuses to start unless register_argc_argv is On. slic's
# php.ini does not set it, so the base image default applies, and that
# differs between PHP versions -- 7.4 is On, 8.5 is Off. This file is
# bind-mounted into the slic container as conf.d/zz-docker.ini, which
# loads after the main php.ini, so appending here wins. The existence
# check is there because a bare append would happily create the file if
# slic ever moves or renames it, leaving the override silently unapplied
# and the 8.5 legs failing later at "cc build" for no visible reason.
- name: Enable register_argc_argv for Codeception
run: |
php_ini="${GITHUB_WORKSPACE}/slic/containers/slic/php.ini"
if [ ! -f "${php_ini}" ]; then
echo "Expected slic php.ini at ${php_ini}, but it does not exist. slic's layout has changed; update this workflow." >&2
exit 1
fi
echo "register_argc_argv=On" >> "${php_ini}"

- name: Set up slic env vars
run: |
echo "SLIC_BIN=${GITHUB_WORKSPACE}/slic/slic" >> $GITHUB_ENV
echo "SLIC_WP_DIR=${GITHUB_WORKSPACE}/slic/_wordpress" >> $GITHUB_ENV
echo "SLIC_WORDPRESS_DOCKERFILE=Dockerfile.base" >> $GITHUB_ENV

- name: Set run context for slic
run: echo "SLIC=1" >> $GITHUB_ENV

- name: Start ssh-agent
run: |
eval `ssh-agent -s`
echo "SSH_AUTH_SOCK=${SSH_AUTH_SOCK}" >> $GITHUB_ENV

- name: Set up slic for CI
run: |
cd ${GITHUB_WORKSPACE}/..
${SLIC_BIN} here
${SLIC_BIN} interactive off
${SLIC_BIN} build-prompt off
${SLIC_BIN} build-subdir off
${SLIC_BIN} xdebug off
${SLIC_BIN} debug on
${SLIC_BIN} php-version set ${{ matrix.php }} --skip-rebuild

- name: Set up the library
run: |
${SLIC_BIN} use ${{ github.event.repository.name }}
${SLIC_BIN} composer set-version 2
${SLIC_BIN} composer validate
${SLIC_BIN} composer install

# The slic image ships a fixed WordPress that varies by PHP version, and
# no environment variable overrides it -- this step is the only lever.
# Without it a leg named "WP latest" silently tests whatever core the
# image happened to bake in. WPLoader installs from this codebase, so
# pinning here is what puts the suite on the version the leg claims.
- name: Pin the WordPress version
run: ${SLIC_BIN} site-cli core update --version=${{ matrix.wp }} --force

- name: Build codeception
id: build
run: ${SLIC_BIN} cc build

- name: Run unit tests (singlesite)
run: ${SLIC_BIN} run unit --env singlesite --ext DotReporter

# Run even when singlesite failed: one run should report both envs rather
# than making you fix one and rediscover the other. It is gated on the
# build having succeeded, because running the suite after a failed
# install or build only stacks a second, misleading failure on top of the
# real one.
- name: Run unit tests (multisite)
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: ${SLIC_BIN} run unit --env multisite --ext DotReporter

# continue-on-error keeps a red nightly leg from blocking the PR, but it
# also makes it report as a pass in the checks list, so the only way to
# notice is to open the run. Leave a trace where it will actually be seen.
- name: Flag a failing nightly leg
if: ${{ failure() && matrix.wp == 'nightly' }}
run: |
echo "::warning title=WordPress nightly failed::PHP ${{ matrix.php }} against WordPress nightly is red. This does not block the PR."
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
echo "> PHP ${{ matrix.php }} / WP nightly failed. Non-blocking, but worth a look." >> $GITHUB_STEP_SUMMARY

- name: Upload test output
if: failure()
uses: actions/upload-artifact@v7
with:
name: "test-output-php${{ matrix.php }}-wp${{ matrix.wp }}"
path: tests/_output
if-no-files-found: ignore
retention-days: 7
2 changes: 1 addition & 1 deletion codeception.dist.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
actor: Tester
bootstrap: _bootstrap.php
namespace: Nexcess\PluginAbsorber\Tests\Support
paths:
tests: tests
output: tests/_output
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
},
"autoload-dev": {
"psr-4": {
"Nexcess\\PluginAbsorber\\Tests\\": "tests/",
"Nexcess\\PluginAbsorber\\Tests\\Support\\": "tests/_support",
"Nexcess\\PluginAbsorber\\Tests\\Unit\\": "tests/unit"
}
Expand Down
Loading