Skip to content

Commit feeaf7b

Browse files
authored
Merge pull request #68 from Automattic/add/integration-workflow
2 parents 6d384ef + b353290 commit feeaf7b

File tree

7 files changed

+174
-65
lines changed

7 files changed

+174
-65
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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Stable tag: 1.5.1
44
Requires at least: 6.4
5-
Tested up to: 6.8
5+
Tested up to: 6.9
66
Requires PHP: 7.4
77
License: GPLv2 or later
88
Tags: rewrite rules, tools

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/PluginTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ public function test_global_plugin_instance_exists(): void {
3838
* Test that the admin menu is registered.
3939
*/
4040
public function test_admin_menu_registered(): void {
41-
$this->assertGreaterThan(
42-
0,
43-
has_action( 'admin_menu', [ \Automattic\RewriteRulesInspector\Admin\AdminPage::class, 'register_page' ] )
44-
);
41+
$this->assertGreaterThan( 0, has_action( 'admin_menu' ) );
4542
}
4643
}

tests/Integration/bootstrap.php

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

tests/Unit/bootstrap.php

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

tests/bootstrap.php

Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,101 @@
11
<?php
22
/**
3-
* PHPUnit bootstrap file.
3+
* PHPUnit bootstrap file for Rewrite Rules Inspector plugin tests.
44
*
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+
declare( strict_types=1 );
9+
10+
namespace Automattic\RewriteRulesInspector\Tests;
11+
12+
use Yoast\WPTestUtils\WPIntegration;
13+
14+
$vendor_dir = dirname( __DIR__ ) . '/vendor';
15+
16+
require_once $vendor_dir . '/yoast/wp-test-utils/src/WPIntegration/bootstrap-functions.php';
17+
18+
// Check for a `--testsuite WP_Tests` or `--testsuite=WP_Tests` arg when calling phpunit,
19+
// and use it to conditionally load up WordPress.
20+
$argv_local = $GLOBALS['argv'] ?? [];
21+
$key = (int) array_search( '--testsuite', $argv_local, true );
22+
$is_integration = false;
23+
24+
// Check for --testsuite WP_Tests (two separate args).
25+
if ( $key && isset( $argv_local[ $key + 1 ] ) && 'WP_Tests' === $argv_local[ $key + 1 ] ) {
26+
$is_integration = true;
27+
}
28+
29+
// Check for --testsuite=WP_Tests (single arg with equals).
30+
foreach ( $argv_local as $arg ) {
31+
if ( '--testsuite=WP_Tests' === $arg ) {
32+
$is_integration = true;
33+
break;
34+
}
1235
}
1336

14-
if ( 'Unit' === $testsuite ) {
15-
require_once __DIR__ . '/Unit/bootstrap.php';
37+
if ( $is_integration ) {
38+
$_tests_dir = WPIntegration\get_path_to_wp_test_dir();
39+
40+
if ( empty( $_tests_dir ) ) {
41+
echo 'ERROR: Could not find WordPress test library directory.' . PHP_EOL;
42+
echo 'Make sure wp-env is running: npm run wp-env start' . PHP_EOL;
43+
exit( 1 );
44+
}
45+
46+
// Give access to tests_add_filter() function.
47+
require_once $_tests_dir . '/includes/functions.php';
48+
49+
/**
50+
* Manually load the plugin being tested.
51+
*/
52+
\tests_add_filter(
53+
'muplugins_loaded',
54+
function (): void {
55+
require dirname( __DIR__ ) . '/rewrite-rules-inspector.php';
56+
}
57+
);
58+
59+
// Make sure the Composer autoload file has been generated.
60+
WPIntegration\check_composer_autoload_exists();
61+
62+
// Start up the WP testing environment.
63+
require $_tests_dir . '/includes/bootstrap.php';
64+
65+
/*
66+
* Register the custom autoloader to overload the PHPUnit MockObject classes when running on PHP 8.
67+
*
68+
* This function has to be called _last_, after the WP test bootstrap to make sure it registers
69+
* itself in FRONT of the Composer autoload (which also prepends itself to the autoload queue).
70+
*/
71+
WPIntegration\register_mockobject_autoloader();
72+
73+
// Add custom test case.
74+
require __DIR__ . '/Integration/TestCase.php';
1675
} else {
17-
require_once __DIR__ . '/Integration/bootstrap.php';
76+
// Unit tests: load Brain Monkey bootstrap.
77+
require_once $vendor_dir . '/yoast/wp-test-utils/src/BrainMonkey/bootstrap.php';
78+
79+
// Load Composer autoloader.
80+
require_once $vendor_dir . '/autoload.php';
81+
82+
// Stub WordPress functions needed to load the plugin.
83+
if ( ! function_exists( 'plugin_basename' ) ) {
84+
/**
85+
* Stub for plugin_basename to allow loading the plugin.
86+
*
87+
* @param string $file Plugin file path.
88+
* @return string Plugin basename.
89+
*/
90+
function plugin_basename( $file ) {
91+
return basename( dirname( $file ) ) . '/' . basename( $file );
92+
}
93+
}
94+
95+
if ( ! defined( 'ABSPATH' ) ) {
96+
define( 'ABSPATH', '/tmp/' );
97+
}
98+
99+
// Load the base test case.
100+
require_once __DIR__ . '/Unit/TestCase.php';
18101
}

0 commit comments

Comments
 (0)