Skip to content

Commit 2bf7f59

Browse files
committed
Use wp-env for PHP unit test
1 parent 2871de3 commit 2bf7f59

File tree

4 files changed

+56
-245
lines changed

4 files changed

+56
-245
lines changed

.github/workflows/pr-checks.yml

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,45 @@ jobs:
4545
if: success() || failure()
4646
run: npm run lint:pkg-json
4747

48+
compute-previous-wordpress-version:
49+
name: Compute previous WordPress version
50+
runs-on: ubuntu-latest
51+
permissions: {}
52+
outputs:
53+
previous-wordpress-version: ${{ steps.get-previous-wordpress-version.outputs.previous-wordpress-version }}
54+
55+
steps:
56+
- name: Get previous WordPress version
57+
id: get-previous-wordpress-version
58+
run: |
59+
curl \
60+
-H "Accept: application/json" \
61+
-o versions.json \
62+
"http://api.wordpress.org/core/stable-check/1.0/"
63+
LATEST_WP_VERSION="$(jq --raw-output 'with_entries(select(.value=="latest"))|keys[]' versions.json)"
64+
# shellcheck disable=SC2034
65+
IFS='.' read -r LATEST_WP_MAJOR LATEST_WP_MINOR LATEST_WP_PATCH <<< "${LATEST_WP_VERSION}"
66+
if [[ "${LATEST_WP_MINOR}" == "0" ]]; then
67+
PREVIOUS_WP_SERIES="$((LATEST_WP_MAJOR - 1)).9"
68+
else
69+
PREVIOUS_WP_SERIES="${LATEST_WP_MAJOR}.$((LATEST_WP_MINOR - 1))"
70+
fi
71+
PREVIOUS_WP_VERSION="$(jq --raw-output --arg series "${PREVIOUS_WP_SERIES}" 'with_entries(select(.key|startswith($series)))|keys[-1]' versions.json)"
72+
echo "previous-wordpress-version=${PREVIOUS_WP_VERSION}" >> "$GITHUB_OUTPUT"
73+
rm versions.json
74+
4875
tests:
49-
name: Test Suite
76+
name: PHP ${{ matrix.php }}${{ matrix.wordpress != '' && format( ' (WP {0})', matrix.wordpress ) || '' }}
77+
needs: [compute-previous-wordpress-version]
5078
runs-on: ubuntu-latest
79+
strategy:
80+
fail-fast: false
81+
matrix:
82+
php: ['7.4', '8.0', '8.1', '8.2', '8.3']
83+
wordpress: ['', 'previous major version']
84+
env:
85+
WP_ENV_PHP_VERSION: ${{ matrix.php }}
86+
WP_ENV_CORE: ${{ matrix.wordpress == '' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', needs.compute-previous-wordpress-version.outputs.previous-wordpress-version ) }}
5187
steps:
5288
- name: Checkout
5389
uses: actions/checkout@v3
@@ -66,23 +102,24 @@ jobs:
66102
- name: Install Node Dependencies
67103
run: npm i
68104

69-
- name: Compile JavaScript App
70-
run: npm run build
71-
72-
- name: Setup MySQL
73-
if: success() || failure()
74-
uses: shogo82148/actions-setup-mysql@v1
105+
- name: Set up PHP
106+
uses: shivammathur/setup-php@v2
75107
with:
76-
mysql-version: '8.0'
108+
php-version: '${{ matrix.php }}'
109+
ini-file: development
110+
coverage: none
111+
112+
- name: Docker debug information
113+
run: docker -v
77114

78-
- name: Run JavaScript unit tests
79-
run: npm run test:unit
115+
- name: Start Docker environment
116+
run: npm run wp-env start
80117

81-
- name: Install Subversion
82-
run: sudo apt-get update -y && sudo apt-get install -y subversion
118+
- name: Docker container debug information
119+
run: npm run wp-env run tests-cli wp core version
120+
121+
- name: Log running Docker containers
122+
run: docker ps -a
83123

84124
- name: Run PHP tests
85-
run: |
86-
mysql -uroot -h127.0.0.1 -e 'SELECT version()' \
87-
&& ./bin/install-wp-tests.sh --wp-version=trunk --recreate-db wordpress_test root '' > /dev/null \
88-
&& composer run-script test
125+
run: npm run test:unit:php

bin/install-wp-tests.sh

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
"lint:php:fix": "composer run-script format",
4949
"lint:md-docs": "wp-scripts lint-md-docs",
5050
"lint:pkg-json": "wp-scripts lint-pkg-json",
51-
"test:php": "npm run test:php:setup && wp-env run tests-wordpress --env-cwd='wp-content/plugins/create-block-theme' composer run-script test",
52-
"test:php:watch": "wp-env run cli --env-cwd='wp-content/plugins/create-block-theme' composer run-script test:watch",
53-
"test:php:setup": "wp-env start",
51+
"test:unit:php:setup": "wp-env start",
52+
"test:unit:php:base": "wp-env run tests-wordpress --env-cwd='wp-content/plugins/create-block-theme' vendor/bin/phpunit -c phpunit.xml.dist --verbose",
53+
"test:unit:php": "npm run test:unit:php:setup && npm run test:unit:php:base",
5454
"packages-update": "wp-scripts packages-update",
5555
"start": "wp-scripts start src/admin-landing-page.js src/plugin-sidebar.js",
5656
"composer": "wp-env run cli --env-cwd=wp-content/plugins/create-block-theme composer",

tests/bootstrap.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', $_phpunit_polyfills_path );
2020
}
2121

22-
if ( ! file_exists( "{$_tests_dir}/includes/functions.php" ) ) {
23-
echo "Could not find {$_tests_dir}/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
24-
exit( 1 );
25-
}
26-
2722
// Give access to tests_add_filter() function.
2823
require_once "{$_tests_dir}/includes/functions.php";
2924

0 commit comments

Comments
 (0)