Skip to content

Commit 17efc91

Browse files
authored
Merge pull request #388 from 10up/update/phpunit-workflow
Update how we run PHPUnit
2 parents 671b319 + 78d2409 commit 17efc91

14 files changed

Lines changed: 164 additions & 323 deletions

File tree

.github/workflows/phpunit.yml

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
name: PHPUnit
2-
permissions:
3-
contents: read
42

53
on:
64
push:
@@ -11,65 +9,73 @@ on:
119
branches:
1210
- develop
1311

12+
permissions:
13+
contents: read
14+
1415
jobs:
15-
check-diffs:
16+
phpunit:
17+
name: Test PHP ${{ matrix.php }} WP ${{ matrix.wp }}
1618
runs-on: ubuntu-latest
17-
outputs:
18-
has_changed: ${{ steps.files-changed.outputs.RSA_PHP_FILES_CHANGED }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
php: [ '8.4', '8.3', '8.2', '8.1', '8.0', '7.4' ]
23+
wp: [ latest, trunk ]
24+
env:
25+
WP_ENV_PHP_VERSION: ${{ matrix.php }}
26+
WP_ENV_CORE: ${{ matrix.wp == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wp ) }}
1927

2028
steps:
21-
- name: Checkout
22-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
23-
with:
24-
fetch-depth: 0
25-
26-
- name: Get updated PHP files
27-
id: changed-files
28-
uses: tj-actions/changed-files@2f7c5bfce28377bc069a65ba478de0a74aa0ca32 # v46.0.1
29-
with:
30-
files: |
31-
**/*.php
32-
composer.json
33-
composer.lock
34-
phpunit.xml
35-
36-
- id: files-changed
29+
- name: Configure environment variables
3730
run: |
38-
if [[ ( "${{ steps.changed-files.outputs.any_changed }}" == 'true' && "${{ github.event_name }}" == "pull_request" ) || "${{ github.event_name }}" == "push" ]]; then
39-
echo "RSA_PHP_FILES_CHANGED=yes" >> $GITHUB_OUTPUT
40-
fi
31+
echo "PHP_FPM_UID=$(id -u)" >> "$GITHUB_ENV"
32+
echo "PHP_FPM_GID=$(id -g)" >> "$GITHUB_ENV"
4133
42-
phpunit:
43-
runs-on: ubuntu-latest
44-
needs: check-diffs
45-
if: needs.check-diffs.outputs.has_changed == 'yes'
46-
47-
steps:
48-
- name: Checkout
49-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
34+
- name: Checkout repository
35+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
36+
with:
37+
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
38+
persist-credentials: false
5039

51-
- uses: getong/mariadb-action@d6d2ec41fd5588f369be4c9398ce77ee725ca9ea # v1.11
40+
##
41+
# This allows Composer dependencies to be installed using a single step.
42+
#
43+
# Since the tests are currently run within the Docker containers where the PHP version varies,
44+
# the same PHP version needs to be configured for the action runner machine so that the correct
45+
# dependency versions are installed and cached.
46+
##
47+
- name: Set up PHP
48+
uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4
49+
with:
50+
php-version: '${{ matrix.php }}'
51+
coverage: none
5252

53-
- name: Set PHP version
54-
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0
55-
with:
56-
php-version: '7.4'
57-
coverage: none
58-
tools: composer:v2
53+
- name: Install Composer dependencies
54+
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1
5955

60-
- name: Install dependencies
61-
run: composer install
56+
- name: Setup Node
57+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
58+
with:
59+
cache: 'npm'
60+
node-version-file: '.nvmrc'
6261

63-
- name: install node v16
64-
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
65-
with:
66-
node-version-file: '.nvmrc'
62+
- name: Install NPM dependencies
63+
run: npm ci && npm run build
6764

68-
- name: Install dependencies
69-
run: npm i && npm run build
65+
- name: Start the Docker testing environment
66+
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
67+
with:
68+
timeout_minutes: 10
69+
max_attempts: 3
70+
command: |
71+
npm run env:start
7072
71-
- name: Setup WP Tests
72-
run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1
73+
- name: Log versions
74+
run: |
75+
npm run env -- run cli php -- -v
76+
npm run env -- run cli wp core version
7377
74-
- name: PHPUnit
75-
run: './vendor/bin/phpunit'
78+
- name: Run PHPUnit tests
79+
id: phpunit
80+
run: |
81+
npm run test:php

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ assets/js/build
1010

1111
tests/cypress/screenshots
1212
tests/cypress/videos
13-
tests/cypress/reports
13+
tests/cypress/reports
14+
/tests/_output/*
15+
!/tests/_output/.gitkeep
16+
/tests/.phpunit.result.cache

.wp-env.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
{
2+
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
23
"core": null,
3-
"plugins": [ ".", "./tests/rsa-seeder" ],
4+
"plugins": [".", "./tests/rsa-seeder"],
45
"config": {
56
"WP_ALLOW_MULTISITE": true
67
},
78
"env": {
9+
"development": {
10+
"config": {
11+
"WP_DEVELOPMENT_MODE": "plugin",
12+
"WP_ENVIRONMENT_TYPE": "development",
13+
"WP_DEBUG": true,
14+
"WP_DEBUG_LOG": "/var/www/html/wp-content/plugins/restricted-site-access/tests/_output/debug.log"
15+
}
16+
},
817
"tests": {
18+
"config": {
19+
"WP_DEBUG": true,
20+
"FS_METHOD": "direct"
21+
},
922
"mappings": {
10-
".htaccess": "./tests/bin/.htaccess"
23+
".htaccess": "./tests/bin/.htaccess",
24+
"wp-cli.yml": "./tests/bin/wp-cli.yml"
1125
}
1226
}
27+
},
28+
"lifecycleScripts": {
29+
"afterStart": "bash ./tests/bin/initialize.sh"
1330
}
1431
}

bin/install-wp-tests.sh

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

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"require-dev": {
1515
"10up/phpcs-composer": "dev-master",
1616
"phpunit/phpunit": "9.6.33",
17-
"yoast/phpunit-polyfills": "1.x-dev"
17+
"yoast/phpunit-polyfills": "^4.0"
1818
},
1919
"scripts": {
2020
"test": "phpunit",

0 commit comments

Comments
 (0)