Skip to content

Commit b13708c

Browse files
GaryJonesclaude
andcommitted
ci: add integration test workflow
Adds the missing integration test workflow to run PHPUnit tests against WordPress. Tests against WP 6.4 + PHP 7.4 (minimum) and WP master + PHP latest. Uses the standard workflow structure consistent with other Automattic plugins. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6d384ef commit b13708c

File tree

4 files changed

+137
-16
lines changed

4 files changed

+137
-16
lines changed

.github/workflows/integration.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Run PHPUnit
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- trunk
8+
paths:
9+
- '.github/workflows/integration.yml'
10+
- '**.php'
11+
- 'phpunit.xml.dist'
12+
- 'composer.json'
13+
pull_request:
14+
paths:
15+
- '.github/workflows/integration.yml'
16+
- '**.php'
17+
- 'phpunit.xml.dist'
18+
- 'composer.json'
19+
workflow_dispatch:
20+
21+
permissions:
22+
contents: read
23+
24+
# Cancels all previous workflow runs for the same branch that have not yet completed.
25+
concurrency:
26+
group: ${{ github.workflow }}-${{ github.ref }}
27+
cancel-in-progress: true
28+
29+
jobs:
30+
test:
31+
name: WP ${{ matrix.wordpress }} on PHP ${{ matrix.php }}
32+
runs-on: ubuntu-latest
33+
34+
env:
35+
WP_ENV_CORE: WordPress/WordPress#${{ matrix.wordpress }}
36+
37+
strategy:
38+
matrix:
39+
include:
40+
# Check lowest supported WP version, with the lowest supported PHP.
41+
- wordpress: '6.4'
42+
php: '7.4'
43+
# Check latest WP with the latest PHP.
44+
- wordpress: 'master'
45+
php: 'latest'
46+
fail-fast: false
47+
48+
steps:
49+
- name: Checkout code
50+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
51+
with:
52+
persist-credentials: false
53+
54+
- name: Install wordpress environment
55+
run: npm install -g @wordpress/env
56+
57+
- name: Setup PHP ${{ matrix.php }}
58+
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # 2.36.0
59+
with:
60+
php-version: ${{ matrix.php }}
61+
tools: composer
62+
63+
- name: Install Composer dependencies
64+
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # 3.1.1
65+
66+
- name: Setup problem matchers for PHP
67+
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
68+
69+
- name: Setup problem matchers for PHPUnit
70+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
71+
72+
- name: Setup wp-env
73+
run: wp-env start
74+
75+
- name: Run integration tests (single site)
76+
run: composer test:integration
77+
78+
- name: Run integration tests (multisite)
79+
run: composer test:integration-ms

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
"lint": "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git",
4848
"lint-ci": "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git --checkstyle",
4949
"test:unit": "@php ./vendor/bin/phpunit --testsuite Unit",
50-
"test:integration": "wp-env run tests-cli --env-cwd=wp-content/plugins/rewrite-rules-inspector ./vendor/bin/phpunit --testsuite WP_Tests",
51-
"test:integration-ms": "wp-env run tests-cli --env-cwd=wp-content/plugins/rewrite-rules-inspector /bin/bash -c 'WP_MULTISITE=1 ./vendor/bin/phpunit --testsuite WP_Tests'"
50+
"test:integration": "wp-env run tests-cli --env-cwd=wp-content/plugins/Rewrite-Rules-Inspector ./vendor/bin/phpunit --testsuite WP_Tests",
51+
"test:integration-ms": "wp-env run tests-cli --env-cwd=wp-content/plugins/Rewrite-Rules-Inspector /bin/bash -c 'WP_MULTISITE=1 ./vendor/bin/phpunit --testsuite WP_Tests'"
5252
},
5353
"scripts-descriptions": {
5454
"coverage": "Run tests with code coverage reporting",

tests/Integration/bootstrap.php

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,46 @@
55
* @package Automattic\RewriteRulesInspector\Tests\Integration
66
*/
77

8+
namespace Automattic\RewriteRulesInspector\Tests\Integration;
9+
810
use Yoast\WPTestUtils\WPIntegration;
911

10-
// Load Composer autoloader.
11-
require_once dirname( __DIR__, 2 ) . '/vendor/autoload.php';
12+
$vendor_dir = dirname( __DIR__, 2 ) . '/vendor';
13+
14+
// Load the Yoast WP test utils bootstrap functions.
15+
require_once $vendor_dir . '/yoast/wp-test-utils/src/WPIntegration/bootstrap-functions.php';
16+
17+
$_tests_dir = WPIntegration\get_path_to_wp_test_dir();
18+
19+
if ( empty( $_tests_dir ) ) {
20+
echo 'ERROR: Could not find WordPress test library directory.' . PHP_EOL;
21+
echo 'Make sure wp-env is running: npm run wp-env start' . PHP_EOL;
22+
exit( 1 );
23+
}
1224

13-
// Get access to tests_add_filter() function.
14-
require_once getenv( 'WP_PHPUNIT__DIR' ) . '/includes/functions.php';
25+
// Give access to tests_add_filter() function.
26+
require_once $_tests_dir . '/includes/functions.php';
1527

1628
/**
1729
* Manually load the plugin being tested.
1830
*/
19-
tests_add_filter(
31+
\tests_add_filter(
2032
'muplugins_loaded',
2133
static function (): void {
2234
require dirname( __DIR__, 2 ) . '/rewrite-rules-inspector.php';
2335
}
2436
);
2537

26-
// Bootstrap WordPress.
27-
WPIntegration\bootstrap_it();
38+
// Make sure the Composer autoload file has been generated.
39+
WPIntegration\check_composer_autoload_exists();
40+
41+
// Start up the WP testing environment.
42+
require $_tests_dir . '/includes/bootstrap.php';
43+
44+
/*
45+
* Register the custom autoloader to overload the PHPUnit MockObject classes when running on PHP 8.
46+
*
47+
* This function has to be called _last_, after the WP test bootstrap to make sure it registers
48+
* itself in FRONT of the Composer autoload (which also prepends itself to the autoload queue).
49+
*/
50+
WPIntegration\register_mockobject_autoloader();

tests/bootstrap.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,33 @@
55
* @package Automattic\RewriteRulesInspector\Tests
66
*/
77

8-
// Detect which testsuite is being run based on environment variable or default.
9-
$testsuite = getenv( 'TESTSUITE' );
10-
if ( ! $testsuite ) {
11-
$testsuite = 'Unit';
8+
// Check for a `--testsuite WP_Tests` or `--testsuite=WP_Tests` arg when calling phpunit,
9+
// and use it to conditionally load up WordPress.
10+
$argv_local = $GLOBALS['argv'] ?? [];
11+
$key = (int) array_search( '--testsuite', $argv_local, true );
12+
$is_integration = false;
13+
14+
// Check for --testsuite WP_Tests (two separate args).
15+
if ( $key && isset( $argv_local[ $key + 1 ] ) && 'WP_Tests' === $argv_local[ $key + 1 ] ) {
16+
$is_integration = true;
1217
}
1318

14-
if ( 'Unit' === $testsuite ) {
15-
require_once __DIR__ . '/Unit/bootstrap.php';
16-
} else {
19+
// Check for --testsuite=WP_Tests (single arg with equals).
20+
foreach ( $argv_local as $arg ) {
21+
if ( '--testsuite=WP_Tests' === $arg ) {
22+
$is_integration = true;
23+
break;
24+
}
25+
}
26+
27+
// Also check for TESTSUITE environment variable as fallback.
28+
$testsuite_env = getenv( 'TESTSUITE' );
29+
if ( 'WP_Tests' === $testsuite_env || 'integration' === $testsuite_env ) {
30+
$is_integration = true;
31+
}
32+
33+
if ( $is_integration ) {
1734
require_once __DIR__ . '/Integration/bootstrap.php';
35+
} else {
36+
require_once __DIR__ . '/Unit/bootstrap.php';
1837
}

0 commit comments

Comments
 (0)