Skip to content
Open
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
36 changes: 34 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Unit Tests

on:
push:
branches: [ trunk ]
pull_request:
push:
branches: [ trunk ]

jobs:
Expand Down Expand Up @@ -51,3 +50,36 @@ jobs:
- name: Run PHPUnit
working-directory: ${{ matrix.working-directory }}
run: phpunit ${{ matrix.phpunit-args }}

# WordPress-dependent PHP tests — require wp-env (Docker).
php-wordpress:
name: "WP: ${{ matrix.name }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: Handbook Plugin
plugin-directory: wordpress.org/public_html/wp-content/plugins/handbook
steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install wp-env
run: npm -g install @wordpress/env

- name: Start wp-env
working-directory: ${{ matrix.plugin-directory }}
run: wp-env start

- name: Install PHPUnit Polyfills
working-directory: ${{ matrix.plugin-directory }}
run: wp-env run tests-cli composer require --dev yoast/phpunit-polyfills:^4.0 --working-dir=/wordpress-phpunit

- name: Run PHPUnit
working-directory: ${{ matrix.plugin-directory }}
run: wp-env run tests-cli --env-cwd=wp-content/plugins/$(basename ${{ matrix.plugin-directory }}) phpunit --no-configuration --bootstrap phpunit/bootstrap.php phpunit/tests/
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
if ( ! $_tests_dir && false !== ( $pos = stripos( __FILE__, '/src/wp-content/plugins/' ) ) ) {
$_tests_dir = substr( __FILE__, 0, $pos ) . '/tests/phpunit/';
}
// Check for wp-env test directory.
elseif ( ! $_tests_dir && file_exists( '/wordpress-phpunit/includes/functions.php' ) ) {
$_tests_dir = '/wordpress-phpunit/';
}
// Elseif no path yet, assume a temp directory path.
elseif ( ! $_tests_dir ) {
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib/tests/phpunit/';
Expand All @@ -24,6 +28,11 @@
exit( 1 );
}

// Set polyfills path if available (required by WP test suite).
if ( ! defined( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) && file_exists( $_tests_dir . '/vendor/yoast/phpunit-polyfills' ) ) {
define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', $_tests_dir . '/vendor/yoast/phpunit-polyfills' );
}

// Give access to tests_add_filter() function.
require_once $_tests_dir . '/includes/functions.php';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class WPorg_Handbook_Handbook_Test extends WP_UnitTestCase {

protected $handbook;

public function setUp() {
public function setUp(): void {
parent::setup();
WPorg_Handbook_Init::init();

$handbooks = WPorg_Handbook_Init::get_handbook_objects();
$this->handbook = reset( $handbooks );
}

public function tearDown() {
public function tearDown(): void {
parent::tearDown();

foreach ( WPorg_Handbook_Init::get_handbook_objects() as $obj ) {
Expand Down Expand Up @@ -455,7 +455,7 @@ public function test_handbook_sidebar() {

$this->assertTrue( isset( $wp_registered_sidebars[ 'handbook' ] ) );
$this->assertSame(
[ 'name', 'id', 'description', 'class', 'before_widget', 'after_widget', 'before_title', 'after_title', 'before_sidebar', 'after_sidebar' ],
[ 'name', 'id', 'description', 'class', 'before_widget', 'after_widget', 'before_title', 'after_title', 'before_sidebar', 'after_sidebar', 'show_in_rest' ],
array_keys( $wp_registered_sidebars[ 'handbook' ] )
);
$this->assertEquals( 'handbook', $wp_registered_sidebars[ 'handbook' ]['id'] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

class WPorg_Handbook_Init_Test extends WP_UnitTestCase {

public function setUp() {
public function setUp(): void {
parent::setup();

WPorg_Handbook_Init::init();
}

public function tearDown() {
public function tearDown(): void {
parent::tearDown();

WPorg_Handbook_Init::reset( true );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

class WPorg_Handbook_Template_Tags_Test extends WP_UnitTestCase {

public function setUp() {
public function setUp(): void {
parent::setup();

WPorg_Handbook_Init::init();
}

public function tearDown() {
public function tearDown(): void {
parent::tearDown();

WPorg_Handbook_Init::reset( true );
Expand Down