Skip to content

Commit 159e9c1

Browse files
authored
Merge branch 'master' into issue/161
2 parents 113cfc0 + db02f6b commit 159e9c1

File tree

13 files changed

+679
-103
lines changed

13 files changed

+679
-103
lines changed

.distignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ node_modules
2424
src
2525
webpack.config.js
2626
.eslintrc.js
27-
.prettierrc.js

.github/workflows/php-sniffer-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: PHP - Code Sniffer
1+
name: PHP - PHPCS
22

33
on:
44
push:

.github/workflows/phpstan-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run PHPStan
1+
name: PHP - PHPStan
22

33
on: [push]
44

.github/workflows/phpunit-ci.yml

Lines changed: 196 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,226 @@
1-
name: PHPUnit Tests
1+
name: PHP - PHPUnit Tests
22

33
on:
44
push:
55
branches:
66
- master
7-
- release/*
87
pull_request:
8+
branches:
9+
- master
910

1011
jobs:
11-
test:
12-
name: PHP ${{ matrix.php }} - WP ${{ matrix.wp }}
12+
phpunit:
1313
runs-on: ubuntu-latest
14-
15-
permissions:
16-
contents: read
17-
1814
strategy:
1915
fail-fast: false
2016
matrix:
21-
php: ['7.4', '8.0', '8.1', '8.2']
22-
wp: ['latest']
23-
experimental: [false]
17+
# Test matrix covering WordPress, PHP, and PHPUnit version combinations
18+
# Based on WordPress version requirements and PHP compatibility
19+
# Note: WordPress officially only supports PHPUnit up to 7.x
2420
include:
25-
# Test with older WordPress version
26-
- php: '7.4'
27-
wp: '4.9'
28-
experimental: false
29-
- php: '8.0'
30-
wp: '4.9'
31-
experimental: false
32-
# Test with WordPress trunk/master (allow failures)
33-
- php: '8.2'
34-
wp: 'trunk'
35-
experimental: true
36-
37-
continue-on-error: ${{ matrix.experimental }}
38-
39-
services:
40-
mysql:
41-
image: mysql:5.7
42-
env:
43-
MYSQL_ALLOW_EMPTY_PASSWORD: yes
44-
MYSQL_DATABASE: wordpress_tests
45-
ports:
46-
- 3306:3306
47-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
48-
21+
# WordPress 6.7+ (latest) - PHP 7.2+
22+
- wordpress: "latest"
23+
php: "8.3"
24+
phpunit: "9"
25+
wp-version: "6.7"
26+
- wordpress: "latest"
27+
php: "8.2"
28+
phpunit: "9"
29+
wp-version: "6.7"
30+
- wordpress: "latest"
31+
php: "8.1"
32+
phpunit: "9"
33+
wp-version: "6.7"
34+
- wordpress: "latest"
35+
php: "8.0"
36+
phpunit: "9"
37+
wp-version: "6.7"
38+
39+
# WordPress 6.4-6.6 - PHP 7.2+
40+
- wordpress: "6.6"
41+
php: "8.3"
42+
phpunit: "9"
43+
wp-version: "6.6"
44+
- wordpress: "6.5"
45+
php: "8.2"
46+
phpunit: "9"
47+
wp-version: "6.5"
48+
- wordpress: "6.4"
49+
php: "8.1"
50+
phpunit: "9"
51+
wp-version: "6.4"
52+
53+
# WordPress 6.0-6.3 - PHP 7.2+
54+
- wordpress: "6.3"
55+
php: "8.0"
56+
phpunit: "9"
57+
wp-version: "6.3"
58+
- wordpress: "6.2"
59+
php: "7.4"
60+
phpunit: "9"
61+
wp-version: "6.2"
62+
- wordpress: "6.1"
63+
php: "7.4"
64+
phpunit: "9"
65+
wp-version: "6.1"
66+
- wordpress: "6.0"
67+
php: "7.4"
68+
phpunit: "9"
69+
wp-version: "6.0"
70+
71+
# WordPress 5.9 - PHP 7.2+
72+
- wordpress: "5.9"
73+
php: "7.4"
74+
phpunit: "9"
75+
wp-version: "5.9"
76+
4977
steps:
5078
- name: Checkout
5179
uses: actions/checkout@v4
52-
53-
- name: Setup PHP
80+
81+
- name: Set up PHP ${{ matrix.php }}
5482
uses: shivammathur/setup-php@v2
5583
with:
5684
php-version: ${{ matrix.php }}
57-
extensions: mysqli
85+
extensions: mbstring, zip, xml, curl
86+
tools: composer:v2
5887
coverage: none
59-
tools: composer
60-
61-
- name: Get Composer cache directory
62-
id: composer-cache
63-
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
64-
65-
- name: Setup Composer cache
88+
89+
- name: Validate PHP
90+
run: php -v
91+
92+
- name: Restore Composer cache
6693
uses: actions/cache@v4
6794
with:
68-
path: ${{ steps.composer-cache.outputs.dir }}
95+
path: |
96+
~/.cache/composer
97+
vendor
6998
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
7099
restore-keys: |
71100
${{ runner.os }}-composer-
72-
101+
73102
- name: Install Composer dependencies
74-
run: composer install --prefer-dist --no-progress --no-interaction
75-
76-
- name: PHP Lint
77-
run: find -L . -path ./vendor -prune -o -name '*.php' -not -name 'class-wp-ms-network-command.php' -print0 | xargs -0 -n 1 -P 4 php -l
78-
79-
- name: Setup WordPress test environment
80-
env:
81-
WP_VERSION: ${{ matrix.wp }}
82103
run: |
83-
if [[ "$WP_VERSION" == "latest" ]]; then
84-
WP_VERSION=$(curl -s http://api.wordpress.org/core/version-check/1.7/ | grep -o '"version":"[^"]*' | sed 's/"version":"//' | head -1)
104+
# For PHP < 7.4, we need to ignore platform requirements since some dev dependencies require PHP 7.4+
105+
if [[ "${{ matrix.php }}" =~ ^7\.[0-3]$ ]]; then
106+
composer install --no-interaction --prefer-dist --no-progress --ignore-platform-req=php
107+
else
108+
composer install --no-interaction --prefer-dist --no-progress
85109
fi
86-
if [[ "$WP_VERSION" == "trunk" ]]; then
87-
WP_VERSION="master"
110+
111+
- name: Install system dependencies
112+
run: |
113+
sudo apt-get update
114+
sudo apt-get install -y subversion
115+
116+
- name: Set up MySQL
117+
run: |
118+
sudo systemctl start mysql.service
119+
mysql -e "CREATE DATABASE IF NOT EXISTS wordpress_test;" -uroot -proot
120+
mysql -e "CREATE USER IF NOT EXISTS 'wp'@'localhost' IDENTIFIED BY 'wp';" -uroot -proot
121+
mysql -e "GRANT ALL PRIVILEGES ON wordpress_test.* TO 'wp'@'localhost';" -uroot -proot
122+
mysql -e "FLUSH PRIVILEGES;" -uroot -proot
123+
124+
- name: Install job-specific PHPUnit
125+
# Install PHPUnit based on the version specified in the matrix
126+
# PHPUnit 9 requires PHP 7.3+, PHPUnit 8 supports PHP 7.2+
127+
run: |
128+
set -e
129+
echo "Installing PHPUnit ${{ matrix.phpunit }}"
130+
131+
# Determine the exact PHPUnit version to install
132+
case "${{ matrix.phpunit }}" in
133+
"9")
134+
PHPUNIT_VERSION="^9.6"
135+
;;
136+
"8")
137+
PHPUNIT_VERSION="^8.5"
138+
;;
139+
"7")
140+
PHPUNIT_VERSION="^7.5"
141+
;;
142+
*)
143+
PHPUNIT_VERSION="${{ matrix.phpunit }}"
144+
;;
145+
esac
146+
147+
echo "Resolved PHPUnit version: ${PHPUNIT_VERSION}"
148+
149+
# Try to install via composer
150+
# For PHP < 7.4, use platform override to allow installation of packages with higher PHP requirements
151+
COMPOSER_OPTS=""
152+
if [[ "${{ matrix.php }}" =~ ^7\.[0-3]$ ]]; then
153+
COMPOSER_OPTS="--ignore-platform-req=php"
88154
fi
89-
90-
# Get plugin slug from repository name
91-
PLUGIN_SLUG=$(basename "$GITHUB_WORKSPACE")
92-
93-
# Clone WordPress
94-
git clone --depth=1 --branch="$WP_VERSION" https://github.com/WordPress/wordpress-develop.git /tmp/wordpress
95-
96-
# Setup plugin directory
97-
mkdir -p /tmp/wordpress/src/wp-content/mu-plugins
98-
cp -r "$GITHUB_WORKSPACE" "/tmp/wordpress/src/wp-content/mu-plugins/$PLUGIN_SLUG"
99-
100-
# Configure tests
101-
cd /tmp/wordpress
102-
cp wp-tests-config-sample.php wp-tests-config.php
103-
sed -i "s/youremptytestdbnamehere/wordpress_tests/" wp-tests-config.php
104-
sed -i "s/yourusernamehere/root/" wp-tests-config.php
105-
sed -i "s/yourpasswordhere//" wp-tests-config.php
106-
sed -i "s/localhost/127.0.0.1/" wp-tests-config.php
107-
108-
- name: Run PHPUnit tests
155+
156+
composer require --dev --no-interaction --prefer-dist --update-with-dependencies ${COMPOSER_OPTS} "phpunit/phpunit:${PHPUNIT_VERSION}" || {
157+
echo "Composer install failed, attempting PHAR fallback"
158+
159+
# Determine PHAR version
160+
case "${{ matrix.phpunit }}" in
161+
"9")
162+
PHAR_VERSION="9.6.21"
163+
;;
164+
"8")
165+
PHAR_VERSION="8.5.40"
166+
;;
167+
"7")
168+
PHAR_VERSION="7.5.20"
169+
;;
170+
*)
171+
PHAR_VERSION="${{ matrix.phpunit }}.0"
172+
;;
173+
esac
174+
175+
PHAR_URL="https://phar.phpunit.de/phpunit-${PHAR_VERSION}.phar"
176+
echo "Downloading ${PHAR_URL}"
177+
curl -fsSL -o phpunit.phar "${PHAR_URL}"
178+
chmod +x phpunit.phar
179+
echo "Using phpunit.phar version ${PHAR_VERSION}"
180+
}
181+
182+
- name: Install WordPress test suite
183+
run: |
184+
bash tests/integration/bin/install-wp-tests.sh wordpress_test wp wp localhost ${{ matrix.wordpress }} true
185+
186+
- name: Verify test environment
187+
run: |
188+
echo "=== Test Configuration ==="
189+
echo "WordPress: ${{ matrix.wordpress }} (v${{ matrix.wp-version }})"
190+
echo "PHP: ${{ matrix.php }}"
191+
echo "PHPUnit: ${{ matrix.phpunit }}"
192+
echo ""
193+
echo "=== PHP Version ==="
194+
php -v
195+
echo ""
196+
echo "=== PHPUnit Version ==="
197+
if [ -x ./vendor/bin/phpunit ]; then
198+
./vendor/bin/phpunit --version
199+
elif [ -f phpunit.phar ]; then
200+
php phpunit.phar --version
201+
fi
202+
echo ""
203+
echo "=== Database Connection ==="
204+
mysql -e "SELECT VERSION();" -uwp -pwp wordpress_test
205+
206+
- name: Select PHPUnit configuration
207+
run: |
208+
# Use legacy config for PHPUnit 7-8, modern config for PHPUnit 9+
209+
if [ "${{ matrix.phpunit }}" = "7" ] || [ "${{ matrix.phpunit }}" = "8" ]; then
210+
echo "PHPUNIT_CONFIG=phpunit.xml.legacy" >> $GITHUB_ENV
211+
echo "Using legacy PHPUnit configuration (phpunit.xml.legacy)"
212+
else
213+
echo "PHPUNIT_CONFIG=phpunit.xml.dist" >> $GITHUB_ENV
214+
echo "Using modern PHPUnit configuration (phpunit.xml.dist)"
215+
fi
216+
217+
- name: Run tests
109218
run: |
110-
PLUGIN_SLUG=$(basename "$GITHUB_WORKSPACE")
111-
cd "/tmp/wordpress/src/wp-content/mu-plugins/$PLUGIN_SLUG"
112-
vendor/bin/phpunit -c phpunit.xml.dist
219+
if [ -x ./vendor/bin/phpunit ]; then
220+
./vendor/bin/phpunit --configuration $PHPUNIT_CONFIG --verbose
221+
elif [ -f phpunit.phar ]; then
222+
php phpunit.phar --configuration $PHPUNIT_CONFIG --verbose
223+
else
224+
echo "No phpunit available (vendor/bin/phpunit or phpunit.phar). Failing." >&2
225+
exit 1
226+
fi

0 commit comments

Comments
 (0)