Skip to content

Commit 8cb99d9

Browse files
committed
Add a gitHub workflow that runs unit tests in the repository.
This only runs the unit tests for the standalone tests. Closes WordPress#558 git-svn-id: https://meta.svn.wordpress.org/sites/trunk@14690 74240141-8908-4e6f-9713-ba540dce6ec7
1 parent 2a41404 commit 8cb99d9

5 files changed

Lines changed: 62 additions & 8 deletions

File tree

.github/workflows/unit-tests.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 tests/bootstrap.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 tests/phpunit/tests/"
24+
- name: Slack Trac Bot
25+
working-directory: common/includes/tests/slack/trac
26+
phpunit-args: "bot.php"
27+
- name: Slack Props Library
28+
working-directory: common/includes/slack/props/tests
29+
phpunit-args: "--bootstrap /tmp/phpunit-bootstrap.php ."
30+
bootstrap: wpdb-stub
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- name: Set up PHP
35+
uses: shivammathur/setup-php@v2
36+
with:
37+
php-version: "8.4"
38+
tools: phpunit:^11
39+
40+
- name: Create wpdb stub bootstrap
41+
if: matrix.bootstrap == 'wpdb-stub'
42+
run: |
43+
cat > /tmp/phpunit-bootstrap.php << 'PHPEOF'
44+
<?php
45+
class wpdbStub {
46+
public function prepare( $query, ...$args ) { return $query; }
47+
public function get_results( $query, $output = 'OBJECT' ) { return []; }
48+
}
49+
PHPEOF
50+
51+
- name: Run PHPUnit
52+
working-directory: ${{ matrix.working-directory }}
53+
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' );

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22
namespace WordPressdotorg\API\Serve_Happy;
3-
use PHPUnit_Framework_TestCase;
3+
use PHPUnit\Framework\TestCase;
44

55
/**
66
* @group serve-happy
77
*/
8-
class Tests_API_Responses extends PHPUnit_Framework_TestCase {
8+
class Tests_API_Responses extends TestCase {
99

1010
function dataprovider_determine_request_valid() {
1111
return [

common/includes/tests/slack/trac/bot.php

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

33
require dirname( dirname( dirname( __DIR__ ) ) ) . '/slack/autoload.php';
44

5-
class Test_Slack_Trac_Bot extends PHPUnit_Framework_TestCase {
5+
class Test_Slack_Trac_Bot extends \PHPUnit\Framework\TestCase {
66
function test_commit_parse() {
77
$post_data = $this->mock_post_data( '[1234] r12345 r897-core https://core.trac.wordpress.org/changeset/11223' );
88
$receiving = new \Dotorg\Slack\Trac\Bot( $post_data );

0 commit comments

Comments
 (0)