Skip to content

Commit f3e6720

Browse files
committed
wip
1 parent 45260dd commit f3e6720

8 files changed

Lines changed: 84 additions & 203 deletions

File tree

.github/workflows/tests.yml

Lines changed: 14 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,8 @@ jobs:
1616
matrix:
1717
php: ["8.2", "8.3", "8.4"]
1818
wordpress: ["6.7", "6.8"]
19-
exclude:
20-
# Exclude older PHP versions with newer WordPress
21-
- php: "7.4"
22-
wordpress: "6.5.3"
23-
24-
services:
25-
mysql:
26-
image: mysql:8.0
27-
env:
28-
MYSQL_DATABASE: wordpress
29-
MYSQL_ROOT_PASSWORD: root
30-
ports: [3306:3306]
31-
options: >-
32-
--health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -proot"
33-
--health-interval=10s
34-
--health-timeout=5s
35-
--health-retries=5
36-
37-
env:
38-
WP_VERSION: ${{ matrix.wordpress }}
39-
WP_SITE_URL: http://localhost:8100
40-
WP_DB_NAME: wordpress
41-
WP_DB_USER: root
42-
WP_DB_PASS: root
43-
WP_DB_HOST: 127.0.0.1
4419

4520
steps:
46-
- name: Check MySQL tables
47-
run: |
48-
echo "Listing databases:"
49-
mysql -h 127.0.0.1 -uroot -proot -e "SHOW DATABASES;"
50-
51-
echo "Checking if 'wordpress' database has any tables:"
52-
mysql -h 127.0.0.1 -uroot -proot -D wordpress -e "SHOW TABLES;" || echo "No tables found (yet)."
53-
5421
- name: Checkout plugin
5522
uses: actions/checkout@v6
5623
with:
@@ -59,106 +26,10 @@ jobs:
5926
- name: Set up PHP
6027
uses: shivammathur/setup-php@v2
6128
with:
62-
# Note: Specified version is only for running tests,
63-
# as the WordPress PHP version is set inside the FrankenPHP Dockerfile.
29+
# Host PHP is used only to run Pest; WordPress PHP is set via WP_ENV_PHP_VERSION below.
6430
php-version: 8.4
6531
extensions: mysqli, zip, gd
6632
coverage: none
67-
tools: wp-cli
68-
69-
- name: Cache WordPress archive
70-
id: cache-wordpress
71-
uses: actions/cache@v5
72-
with:
73-
path: /tmp/wp
74-
key: wp-${{ matrix.wordpress }}
75-
76-
- name: Download WordPress
77-
if: steps.cache-wordpress.outputs.cache-hit != 'true'
78-
run: |
79-
mkdir -p /tmp/wp
80-
curl -O https://wordpress.org/wordpress-${WP_VERSION}.tar.gz
81-
tar -xzf wordpress-${WP_VERSION}.tar.gz --strip-components=1 -C /tmp/wp
82-
rm wordpress-${WP_VERSION}.tar.gz
83-
84-
- name: Set up Docker Buildx
85-
uses: docker/setup-buildx-action@v4
86-
87-
- name: Build FrankenPHP image (with cache)
88-
id: build
89-
uses: docker/build-push-action@v7
90-
env:
91-
DOCKER_BUILD_SUMMARY: false
92-
with:
93-
context: .
94-
file: .github/docker/Dockerfile
95-
tags: frankenphp-${{ matrix.php }}
96-
load: true
97-
build-args: |
98-
PHP_VERSION=${{ matrix.php }}
99-
cache-from: type=gha
100-
cache-to: type=gha,mode=max
101-
102-
- name: Start FrankenPHP server
103-
run: |
104-
docker run -d \
105-
--name frankenphp \
106-
--network host \
107-
-p 8100:8100 \
108-
-v /tmp/wp:/var/www/html \
109-
-v $GITHUB_WORKSPACE:/var/www/html/wp-content/plugins/simpleanalytics \
110-
-v $GITHUB_WORKSPACE/Caddyfile:/etc/frankenphp/Caddyfile \
111-
frankenphp-${{ matrix.php }}
112-
113-
- name: Wait for FrankenPHP to be ready
114-
run: |
115-
for i in $(seq 1 30); do
116-
curl -s -o /dev/null http://localhost:8100 && echo "Server is up" && exit 0
117-
echo "Waiting... ($i/30)"
118-
sleep 2
119-
done
120-
echo "Server did not start in time" && exit 1
121-
122-
- name: Verify MySQL is accepting connections
123-
run: |
124-
for i in $(seq 1 10); do
125-
mysql -h 127.0.0.1 -uroot -proot -e "SELECT 1" && echo "MySQL ready" && exit 0
126-
echo "Waiting for MySQL... ($i/10)"
127-
sleep 2
128-
done
129-
echo "MySQL not ready" && exit 1
130-
131-
- name: Install WordPress
132-
run: |
133-
rm -f /tmp/wp/wp-config.php
134-
wp config create \
135-
--dbname="$WP_DB_NAME" \
136-
--dbuser="$WP_DB_USER" \
137-
--dbpass="$WP_DB_PASS" \
138-
--dbhost="$WP_DB_HOST" \
139-
--path=/tmp/wp \
140-
--skip-check
141-
wp config set DISABLE_WP_CRON true --raw --path=/tmp/wp
142-
wp core install \
143-
--url="${WP_SITE_URL}" \
144-
--title="Test Site" \
145-
--admin_user=admin \
146-
--admin_password=admin \
147-
--admin_email=test@example.com \
148-
--path=/tmp/wp \
149-
--skip-email \
150-
--allow-root
151-
wp user create author author@local.test --role=author --user_pass=author --path=/tmp/wp --allow-root
152-
wp user create editor editor@local.test --role=editor --user_pass=editor --path=/tmp/wp --allow-root
153-
wp user create subscriber subscriber@local.test --role=subscriber --user_pass=subscriber --path=/tmp/wp --allow-root
154-
155-
- name: Show current config values
156-
run: wp config list --path=/tmp/wp --allow-root
157-
158-
- name: Warm up WordPress
159-
run: |
160-
curl -s -o /dev/null -w "wp-login.php: HTTP %{http_code} in %{time_total}s\n" http://localhost:8100/wp-login.php
161-
curl -s -o /dev/null -w "homepage: HTTP %{http_code} in %{time_total}s\n" http://localhost:8100/
16233

16334
- name: Install pnpm
16435
uses: pnpm/action-setup@v5
@@ -174,8 +45,17 @@ jobs:
17445
- name: Install pnpm dependencies
17546
run: pnpm install
17647

177-
- name: Install Playwright Browsers
178-
run: npx playwright install --with-deps
48+
- name: Set WordPress version override
49+
run: |
50+
echo '{"core": "https://wordpress.org/wordpress-${{ matrix.wordpress }}.zip"}' > .wp-env.override.json
51+
52+
- name: Start wp-env
53+
run: pnpm exec wp-env start
54+
env:
55+
WP_ENV_PHP_VERSION: ${{ matrix.php }}
56+
57+
- name: Install Playwright browsers
58+
run: pnpm run tests:install
17959

18060
- name: Cache composer dependencies
18161
uses: actions/cache@v5
@@ -197,8 +77,6 @@ jobs:
19777
path: tests/Browser/Screenshots
19878
retention-days: 30
19979

200-
- name: Show FrankenPHP logs
80+
- name: Show wp-env logs
20181
if: always()
202-
run: |
203-
echo "=== FrankenPHP logs ==="
204-
docker logs frankenphp || echo "No logs found"
82+
run: pnpm exec wp-env logs --no-follow 2>&1 | tail -200 || true

.wp-env.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"plugins": ["."],
3+
"config": {
4+
"DISABLE_WP_CRON": true
5+
},
6+
"lifecycleScripts": {
7+
"afterStart": "bash bin/wp-env-setup.sh"
8+
}
9+
}

bin/wp-env-setup.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# Runs after `wp-env start` to set up test users and admin password.
3+
# Safe to re-run: user creation failures (already exists) are ignored.
4+
set -e
5+
6+
WP_ENV="./node_modules/.bin/wp-env"
7+
8+
echo "Setting admin password..."
9+
$WP_ENV run cli wp user update 1 --user_pass=admin --allow-root
10+
11+
echo "Creating test users..."
12+
$WP_ENV run cli wp user create author author@local.test --role=author --user_pass=author --allow-root 2>/dev/null || true
13+
$WP_ENV run cli wp user create editor editor@local.test --role=editor --user_pass=editor --allow-root 2>/dev/null || true
14+
$WP_ENV run cli wp user create subscriber subscriber@local.test --role=subscriber --user_pass=subscriber --allow-root 2>/dev/null || true
15+
16+
echo "wp-env setup complete."

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
"scripts": {
44
"dev": "tailwindcss -i resources/css/settings.css -o build/css/settings.css --watch",
55
"build": "tailwindcss build -i resources/css/settings.css -o build/css/settings.css",
6+
"wp-env": "wp-env",
67
"tests:install": "playwright install --with-deps chromium",
78
"tests": "playwright test"
89
},
910
"devDependencies": {
1011
"@tailwindcss/forms": "^0.5.11",
1112
"@types/node": "^22.19.17",
13+
"@wordpress/env": "^10.19.0",
1214
"playwright": "^1.59.1",
1315
"tailwindcss": "^3.4.19"
1416
}

tests/Browser/BrowserTestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ protected static function getKernelClass(): string
1818

1919
protected function myBrowser(): PantherBrowser
2020
{
21-
return $this->pantherBrowser(['external_base_uri' => 'http://localhost:8100']);
21+
return $this->pantherBrowser(['external_base_uri' => 'http://localhost:8888']);
2222
}
2323

2424
protected function asUser($login, $password)
2525
{
2626
return $this->myBrowser()
27-
->visit('http://localhost:8100/wp-admin')
27+
->visit('http://localhost:8888/wp-admin')
2828
->fillField('user_login', $login)
2929
->fillField('user_pass', $password)
3030
->click('wp-submit')
31-
->assertOn('http://localhost:8100/wp-admin/');
31+
->assertOn('http://localhost:8888/wp-admin/');
3232
}
3333

3434
protected function asAdmin()

0 commit comments

Comments
 (0)