forked from WordPress/wordpress.org
-
Notifications
You must be signed in to change notification settings - Fork 1
85 lines (74 loc) · 2.85 KB
/
unit-tests.yml
File metadata and controls
85 lines (74 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Unit Tests
on:
pull_request:
push:
branches: [ trunk ]
jobs:
# Standalone PHP tests — no WordPress or database dependency.
php-standalone:
name: "PHP: ${{ matrix.name }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: Serve Happy API
working-directory: api.wordpress.org/public_html/core/serve-happy/1.0
phpunit-args: "--no-configuration --exclude-group serve-happy-live-http --bootstrap tests/bootstrap.php tests/"
- name: Browse Happy API
working-directory: api.wordpress.org/public_html/core/browse-happy/1.0
phpunit-args: "--no-configuration tests/phpunit/tests/"
- name: Slack Trac Bot
working-directory: common/includes/tests/slack/trac
phpunit-args: "bot.php"
- name: Slack Props Library
working-directory: common/includes/slack/props/tests
phpunit-args: "--bootstrap /tmp/phpunit-bootstrap.php ."
bootstrap: wpdb-stub
steps:
- uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.4"
tools: phpunit:^11
- name: Create wpdb stub bootstrap
if: matrix.bootstrap == 'wpdb-stub'
run: |
cat > /tmp/phpunit-bootstrap.php << 'PHPEOF'
<?php
class wpdbStub {
public function prepare( $query, ...$args ) { return $query; }
public function get_results( $query, $output = 'OBJECT' ) { return []; }
}
PHPEOF
- 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/