Skip to content

Commit 61aa6cb

Browse files
Merge pull request #1053 from 10up/update/phpunit-workflow
Update how we run PHPUnit
2 parents c6c51e7 + 20c50a1 commit 61aa6cb

27 files changed

+210
-292
lines changed

.github/workflows/phpunit.yml

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,68 @@ on:
1515

1616
jobs:
1717
phpunit:
18-
name: ${{ matrix.php }} on ${{ matrix.os }}
19-
runs-on: ${{ matrix.os }}
18+
name: Test PHP ${{ matrix.php }} WP ${{ matrix.wp }}
19+
runs-on: ubuntu-24.04
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
php: [ '7.4', '8.0', '8.1' ]
24-
os: [ ubuntu-latest ]
23+
php: [ '8.4', '8.3', '8.2', '8.1', '8.0', '7.4' ]
24+
wp: [ latest, trunk ]
25+
env:
26+
WP_ENV_PHP_VERSION: ${{ matrix.php }}
27+
WP_ENV_CORE: ${{ matrix.wp == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wp ) }}
2528

2629
steps:
27-
- name: Checkout
28-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29-
30-
- name: Get composer cache directory
31-
id: composer-cache
32-
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
33-
34-
- name: Cache dependencies
35-
id: cache-composer
36-
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
37-
env:
38-
cache-name: cache-composer
39-
with:
40-
path: ${{ steps.composer-cache.outputs.dir }}
41-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }}
42-
43-
- uses: getong/mariadb-action@d6d2ec41fd5588f369be4c9398ce77ee725ca9ea # v1.11
44-
45-
- name: Set PHP version
46-
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0
47-
with:
48-
php-version: ${{ matrix.php }}
49-
coverage: none
50-
tools: phpunit-polyfills, composer:v2
51-
52-
- name: Install dependencies
53-
run: composer update -W
54-
55-
- name: Setup WP Tests
56-
run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1
57-
58-
- name: PHPUnit
59-
run: './vendor/bin/phpunit'
30+
- name: Configure environment variables
31+
run: |
32+
echo "PHP_FPM_UID=$(id -u)" >> "$GITHUB_ENV"
33+
echo "PHP_FPM_GID=$(id -g)" >> "$GITHUB_ENV"
34+
35+
- name: Checkout repository
36+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
37+
with:
38+
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
39+
persist-credentials: false
40+
41+
##
42+
# This allows Composer dependencies to be installed using a single step.
43+
#
44+
# Since the tests are currently run within the Docker containers where the PHP version varies,
45+
# the same PHP version needs to be configured for the action runner machine so that the correct
46+
# dependency versions are installed and cached.
47+
##
48+
- name: Set up PHP
49+
uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4
50+
with:
51+
php-version: '${{ matrix.php }}'
52+
coverage: none
53+
54+
- name: Install Composer dependencies
55+
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1
56+
57+
- name: Setup Node
58+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
59+
with:
60+
cache: 'npm'
61+
node-version-file: '.nvmrc'
62+
63+
- name: Install NPM dependencies
64+
run: npm ci
65+
66+
- name: Start the Docker testing environment
67+
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
68+
with:
69+
timeout_minutes: 10
70+
max_attempts: 3
71+
command: |
72+
npm run env start
73+
74+
- name: Log versions
75+
run: |
76+
npm run env -- run cli php -- -v
77+
npm run env -- run cli wp core version
78+
79+
- name: Run PHPUnit tests
80+
id: phpunit
81+
run: |
82+
npm run test:php

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ Desktop.ini
4444

4545
config.local.php
4646

47-
# cypress.
47+
# Tests.
4848
tests/cypress/downloads
4949
tests/cypress/screenshots
5050
tests/cypress/videos
5151
tests/cypress/reports
52+
/tests/_output/*
53+
!/tests/_output/.gitkeep
5254
.wp-env.override.json
5355

5456
# docs

.wp-env.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
{
2+
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
3+
"core": null,
24
"plugins": [".", "./tests/test-plugin", "https://downloads.wordpress.org/plugin/classic-editor.zip", "https://downloads.wordpress.org/plugin/elasticpress.zip", "https://downloads.wordpress.org/plugin/woocommerce.zip"],
35
"env": {
6+
"development": {
7+
"config": {
8+
"WP_DEVELOPMENT_MODE": "plugin",
9+
"WP_ENVIRONMENT_TYPE": "development",
10+
"WP_DEBUG": true,
11+
"WP_DEBUG_LOG": "/var/www/html/wp-content/plugins/classifai/tests/_output/debug.log"
12+
}
13+
},
414
"tests": {
15+
"config": {
16+
"WP_DEBUG": true,
17+
"FS_METHOD": "direct"
18+
},
519
"mappings": {
620
"wp-cli.yml": "./tests/bin/wp-cli.yml"
721
}

bin/install-wp-tests.sh

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

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"phpstan/phpstan-deprecation-rules": "2.0.3",
3434
"sirbrillig/phpcs-changed": "^2.12.0",
3535
"szepeviktor/phpstan-wordpress": "^2.0.3",
36-
"yoast/phpunit-polyfills": "^1.0.0"
36+
"wp-phpunit/wp-phpunit": "^6.9",
37+
"yoast/phpunit-polyfills": "^4.0"
3738
},
3839
"scripts": {
3940
"lint": "phpcs -s . --runtime-set testVersion 7.4-",

0 commit comments

Comments
 (0)