Skip to content

Commit eb02a38

Browse files
dd32claude
andcommitted
Merge trunk: adopt wp-env CI approach, remove stubs
Merge latest trunk which uses wp-env for WordPress-dependent CI tests. Add Plugin Directory to the wp-env CI matrix. Remove Classic_Search and WPORG_Ratings stubs as they are not needed (Jetpack is installed via wp-env, and WPORG_Ratings is guarded by class_exists checks). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2 parents 7f7d195 + 5cd00ba commit eb02a38

9 files changed

Lines changed: 38 additions & 124 deletions

File tree

.github/workflows/unit-tests.yml

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
name: Unit Tests
22

33
on:
4-
push:
5-
branches: [ trunk ]
64
pull_request:
5+
push:
76
branches: [ trunk ]
87

98
jobs:
@@ -52,52 +51,39 @@ jobs:
5251
working-directory: ${{ matrix.working-directory }}
5352
run: phpunit ${{ matrix.phpunit-args }}
5453

55-
# WordPress-dependent PHP tests — require the WP test framework and MySQL.
54+
# WordPress-dependent PHP tests — require wp-env (Docker).
5655
php-wordpress:
57-
name: "WP PHP: ${{ matrix.name }}"
56+
name: "WP: ${{ matrix.name }}"
5857
runs-on: ubuntu-latest
59-
services:
60-
mysql:
61-
image: mysql:8.0
62-
env:
63-
MYSQL_ROOT_PASSWORD: root
64-
MYSQL_DATABASE: wordpress_test
65-
ports:
66-
- 3306:3306
67-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
6858
strategy:
6959
fail-fast: false
7060
matrix:
7161
include:
7262
- name: Handbook Plugin
73-
working-directory: wordpress.org/public_html/wp-content/plugins/handbook
74-
phpunit-args: "--configuration phpunit.xml.dist"
63+
plugin-directory: wordpress.org/public_html/wp-content/plugins/handbook
64+
phpunit-args: "--no-configuration --bootstrap phpunit/bootstrap.php phpunit/tests/"
7565
- name: Plugin Directory
76-
working-directory: wordpress.org/public_html/wp-content/plugins/plugin-directory
66+
plugin-directory: wordpress.org/public_html/wp-content/plugins/plugin-directory
7767
phpunit-args: "--configuration phpunit.xml --group plugin-directory"
7868
steps:
7969
- uses: actions/checkout@v4
8070

81-
- name: Set up PHP
82-
uses: shivammathur/setup-php@v2
71+
- name: Set up Node.js
72+
uses: actions/setup-node@v4
8373
with:
84-
php-version: "8.4"
85-
extensions: mysqli
86-
tools: phpunit:9.6
74+
node-version: 20
8775

88-
- name: Install WordPress test suite
89-
run: |
90-
git clone --depth=1 https://github.com/WordPress/wordpress-develop.git /tmp/wp-develop
91-
cd /tmp/wp-develop && composer install --no-interaction
92-
cp wp-tests-config-sample.php tests/phpunit/wp-tests-config.php
93-
sed -i "s|dirname( __FILE__ ) . '/src/'|'/tmp/wp-develop/src/'|" tests/phpunit/wp-tests-config.php
94-
sed -i "s/youremptytestdbnamehere/wordpress_test/" tests/phpunit/wp-tests-config.php
95-
sed -i "s/yourusernamehere/root/" tests/phpunit/wp-tests-config.php
96-
sed -i "s/yourpasswordhere/root/" tests/phpunit/wp-tests-config.php
97-
sed -i "s/'localhost'/'127.0.0.1'/" tests/phpunit/wp-tests-config.php
76+
- name: Install wp-env
77+
run: npm -g install @wordpress/env
78+
79+
- name: Start wp-env
80+
working-directory: ${{ matrix.plugin-directory }}
81+
run: wp-env start
82+
83+
- name: Install PHPUnit Polyfills
84+
working-directory: ${{ matrix.plugin-directory }}
85+
run: wp-env run tests-cli composer require --dev yoast/phpunit-polyfills:^4.0 --working-dir=/wordpress-phpunit
9886

9987
- name: Run PHPUnit
100-
working-directory: ${{ matrix.working-directory }}
101-
env:
102-
WP_TESTS_DIR: /tmp/wp-develop/tests/phpunit
103-
run: phpunit ${{ matrix.phpunit-args }}
88+
working-directory: ${{ matrix.plugin-directory }}
89+
run: wp-env run tests-cli --env-cwd=wp-content/plugins/$(basename ${{ matrix.plugin-directory }}) phpunit ${{ matrix.phpunit-args }}

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 );

wordpress.org/public_html/wp-content/plugins/plugin-directory/.wp-env.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,5 @@
1010
"../../../themes/pub/wporg-plugins-2024",
1111
"https://github.com/WordPress/wporg-parent-2021"
1212
],
13-
"mappings": {
14-
"wp-content/mu-plugins/wporg-ratings-stub.php": "./tests/stubs/wporg-ratings-stub.php"
15-
}
13+
"mappings": {}
1614
}

wordpress.org/public_html/wp-content/plugins/plugin-directory/tests/bootstrap.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
// Give access to tests_add_filter() function.
2727
require_once $_tests_dir . '/includes/functions.php';
2828

29-
// Load Jetpack Search stub if Jetpack is not installed.
30-
require_once __DIR__ . '/stubs/jetpack-search-stub.php';
31-
3229
/**
3330
* Manually load the plugin being tested.
3431
*/

wordpress.org/public_html/wp-content/plugins/plugin-directory/tests/stubs/jetpack-search-stub.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

wordpress.org/public_html/wp-content/plugins/plugin-directory/tests/stubs/wporg-ratings-stub.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)