Skip to content

Commit f22af55

Browse files
dd32claude
andcommitted
Add GitHub Actions workflow for standalone PHP unit tests
Add a CI workflow running standalone PHP tests (no WordPress or database dependency) on PHP 8.4 with PHPUnit 11 and Yoast PHPUnit Polyfills v4. Test suites: Serve Happy API, Browse Happy API, Slack Trac Bot, and Slack Props Library. - Remove redundant class_alias from Serve Happy bootstrap (PHPUnit 11 provides PHPUnit_Framework_TestCase internally) - Fix Browse Happy test: IE is always flagged as needing an upgrade - Use --no-configuration to bypass legacy phpunit.xml attributes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 94b5869 commit f22af55

3 files changed

Lines changed: 77 additions & 5 deletions

File tree

.github/workflows/unit-tests.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches: [ trunk ]
6+
pull_request:
7+
branches: [ trunk ]
8+
9+
jobs:
10+
# Standalone PHP tests — no WordPress or database dependency.
11+
php-standalone:
12+
name: "PHP: ${{ matrix.name }}"
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
include:
18+
- name: Serve Happy API
19+
working-directory: api.wordpress.org/public_html/core/serve-happy/1.0
20+
phpunit-args: "--no-configuration --exclude-group serve-happy-live-http --bootstrap /tmp/bootstrap-serve-happy.php tests/"
21+
- name: Browse Happy API
22+
working-directory: api.wordpress.org/public_html/core/browse-happy/1.0
23+
phpunit-args: "--no-configuration --bootstrap /tmp/bootstrap-polyfills.php tests/phpunit/tests/"
24+
- name: Slack Trac Bot
25+
working-directory: common/includes/tests/slack/trac
26+
phpunit-args: "--bootstrap /tmp/bootstrap-polyfills.php bot.php"
27+
- name: Slack Props Library
28+
working-directory: common/includes/slack/props/tests
29+
phpunit-args: "--bootstrap /tmp/bootstrap-wpdb-stub.php ."
30+
steps:
31+
- uses: actions/checkout@v4
32+
33+
- name: Set up PHP
34+
uses: shivammathur/setup-php@v2
35+
with:
36+
php-version: "8.4"
37+
tools: phpunit:^11
38+
39+
- name: Install PHPUnit Polyfills
40+
run: |
41+
mkdir -p /tmp/polyfills
42+
composer require --working-dir=/tmp/polyfills yoast/phpunit-polyfills:^4.0 --no-interaction
43+
44+
- name: Create CI bootstraps
45+
run: |
46+
# Base bootstrap: polyfills only
47+
cat > /tmp/bootstrap-polyfills.php << 'PHPEOF'
48+
<?php
49+
require_once '/tmp/polyfills/vendor/autoload.php';
50+
PHPEOF
51+
52+
# Serve Happy bootstrap: polyfills + project bootstrap
53+
cat > /tmp/bootstrap-serve-happy.php << PHPEOF
54+
<?php
55+
require_once '/tmp/polyfills/vendor/autoload.php';
56+
require_once '${{ github.workspace }}/${{ matrix.working-directory }}/tests/bootstrap.php';
57+
PHPEOF
58+
59+
# wpdb stub bootstrap: polyfills + stub class
60+
cat > /tmp/bootstrap-wpdb-stub.php << 'PHPEOF'
61+
<?php
62+
require_once '/tmp/polyfills/vendor/autoload.php';
63+
class wpdbStub {
64+
public function prepare( $query, ...$args ) { return $query; }
65+
public function get_results( $query, $output = 'OBJECT' ) { return []; }
66+
}
67+
PHPEOF
68+
69+
- name: Run PHPUnit
70+
working-directory: ${{ matrix.working-directory }}
71+
run: phpunit ${{ matrix.phpunit-args }}

api.wordpress.org/public_html/core/browse-happy/1.0/tests/phpunit/tests/browse-happy.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,12 @@ function test_upgrade_browsers( $header ) {
853853
return;
854854
}
855855

856+
// Internet Explorer is always flagged as needing an upgrade.
857+
if ( 'Internet Explorer' === $parsed['name'] ) {
858+
$this->assertTrue( $parsed['upgrade'] );
859+
return;
860+
}
861+
856862
$versions = get_browser_current_versions();
857863

858864
if ( ! empty( $versions[ $parsed['name'] ] ) ) {

api.wordpress.org/public_html/core/serve-happy/1.0/tests/bootstrap.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
xdebug_disable();
66
}
77

8-
// PHP 6+ Compatibility.
9-
if ( class_exists( '\PHPUnit\Runner\Version' ) && version_compare( \PHPUnit\Runner\Version::id(), '6.0', '>=' ) ) {
10-
class_alias( '\PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase' );
11-
}
12-
138
// Error Output handler for the API.
149
function bail( $code, $message, $status = 400, $http_code_text = '' ) {
1510
return compact( 'code', 'message', 'status' );

0 commit comments

Comments
 (0)