Skip to content

Commit e508fda

Browse files
dd32claude
andcommitted
Add wp-env WordPress integration tests for Handbook plugin
Add a wp-env-based CI job for the Handbook plugin tests alongside the existing standalone PHP tests. - Add wp-env path fallback to Handbook bootstrap - Add void return types to setUp/tearDown for PHPUnit 9+ compat - Update sidebar assertion for WordPress show_in_rest key Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8cb99d9 commit e508fda

5 files changed

Lines changed: 49 additions & 7 deletions

File tree

.github/workflows/unit-tests.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,36 @@ jobs:
5151
- name: Run PHPUnit
5252
working-directory: ${{ matrix.working-directory }}
5353
run: phpunit ${{ matrix.phpunit-args }}
54+
55+
# WordPress-dependent PHP tests — require wp-env (Docker).
56+
php-wordpress:
57+
name: "WP: ${{ matrix.name }}"
58+
runs-on: ubuntu-latest
59+
strategy:
60+
fail-fast: false
61+
matrix:
62+
include:
63+
- name: Handbook Plugin
64+
plugin-directory: wordpress.org/public_html/wp-content/plugins/handbook
65+
steps:
66+
- uses: actions/checkout@v4
67+
68+
- name: Set up Node.js
69+
uses: actions/setup-node@v4
70+
with:
71+
node-version: 20
72+
73+
- name: Install wp-env
74+
run: npm -g install @wordpress/env
75+
76+
- name: Start wp-env
77+
working-directory: ${{ matrix.plugin-directory }}
78+
run: wp-env start
79+
80+
- name: Install PHPUnit Polyfills
81+
working-directory: ${{ matrix.plugin-directory }}
82+
run: wp-env run tests-cli composer require --dev yoast/phpunit-polyfills:^4.0 --working-dir=/wordpress-phpunit
83+
84+
- name: Run PHPUnit
85+
working-directory: ${{ matrix.plugin-directory }}
86+
run: wp-env run tests-cli --env-cwd=wp-content/plugins/$(basename ${{ matrix.plugin-directory }}) phpunit --no-configuration --bootstrap phpunit/bootstrap.php phpunit/tests/

wordpress.org/public_html/wp-content/plugins/handbook/phpunit/bootstrap.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
if ( ! $_tests_dir && false !== ( $pos = stripos( __FILE__, '/src/wp-content/plugins/' ) ) ) {
1515
$_tests_dir = substr( __FILE__, 0, $pos ) . '/tests/phpunit/';
1616
}
17+
// Check for wp-env test directory.
18+
elseif ( ! $_tests_dir && file_exists( '/wordpress-phpunit/includes/functions.php' ) ) {
19+
$_tests_dir = '/wordpress-phpunit/';
20+
}
1721
// Elseif no path yet, assume a temp directory path.
1822
elseif ( ! $_tests_dir ) {
1923
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib/tests/phpunit/';
@@ -24,6 +28,11 @@
2428
exit( 1 );
2529
}
2630

31+
// Set polyfills path if available (required by WP test suite).
32+
if ( ! defined( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) && file_exists( $_tests_dir . '/vendor/yoast/phpunit-polyfills' ) ) {
33+
define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', $_tests_dir . '/vendor/yoast/phpunit-polyfills' );
34+
}
35+
2736
// Give access to tests_add_filter() function.
2837
require_once $_tests_dir . '/includes/functions.php';
2938

wordpress.org/public_html/wp-content/plugins/handbook/phpunit/tests/handbook.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ class WPorg_Handbook_Handbook_Test extends WP_UnitTestCase {
1717

1818
protected $handbook;
1919

20-
public function setUp() {
20+
public function setUp(): void {
2121
parent::setup();
2222
WPorg_Handbook_Init::init();
2323

2424
$handbooks = WPorg_Handbook_Init::get_handbook_objects();
2525
$this->handbook = reset( $handbooks );
2626
}
2727

28-
public function tearDown() {
28+
public function tearDown(): void {
2929
parent::tearDown();
3030

3131
foreach ( WPorg_Handbook_Init::get_handbook_objects() as $obj ) {
@@ -455,7 +455,7 @@ public function test_handbook_sidebar() {
455455

456456
$this->assertTrue( isset( $wp_registered_sidebars[ 'handbook' ] ) );
457457
$this->assertSame(
458-
[ 'name', 'id', 'description', 'class', 'before_widget', 'after_widget', 'before_title', 'after_title', 'before_sidebar', 'after_sidebar' ],
458+
[ 'name', 'id', 'description', 'class', 'before_widget', 'after_widget', 'before_title', 'after_title', 'before_sidebar', 'after_sidebar', 'show_in_rest' ],
459459
array_keys( $wp_registered_sidebars[ 'handbook' ] )
460460
);
461461
$this->assertEquals( 'handbook', $wp_registered_sidebars[ 'handbook' ]['id'] );

wordpress.org/public_html/wp-content/plugins/handbook/phpunit/tests/init.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
class WPorg_Handbook_Init_Test extends WP_UnitTestCase {
66

7-
public function setUp() {
7+
public function setUp(): void {
88
parent::setup();
99

1010
WPorg_Handbook_Init::init();
1111
}
1212

13-
public function tearDown() {
13+
public function tearDown(): void {
1414
parent::tearDown();
1515

1616
WPorg_Handbook_Init::reset( true );

wordpress.org/public_html/wp-content/plugins/handbook/phpunit/tests/template-tags.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
class WPorg_Handbook_Template_Tags_Test extends WP_UnitTestCase {
66

7-
public function setUp() {
7+
public function setUp(): void {
88
parent::setup();
99

1010
WPorg_Handbook_Init::init();
1111
}
1212

13-
public function tearDown() {
13+
public function tearDown(): void {
1414
parent::tearDown();
1515

1616
WPorg_Handbook_Init::reset( true );

0 commit comments

Comments
 (0)