Skip to content

Commit 9a53735

Browse files
osbreadriaandotcomclaude
authored
Automated browser tests (#12)
Co-authored-by: Adriaan van Rossum <1079135+adriaanvanrossum@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 540aeaf commit 9a53735

27 files changed

+7011
-685
lines changed

.github/docker/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ARG PHP_VERSION=8.4
2+
FROM dunglas/frankenphp:1.9-php${PHP_VERSION}
3+
4+
RUN install-php-extensions \
5+
bcmath \
6+
exif \
7+
gd \
8+
intl \
9+
mbstring \
10+
mysqli \
11+
opcache \
12+
pdo_mysql \
13+
zip \
14+
curl \
15+
xml \
16+
dom \
17+
simplexml \
18+
tokenizer \
19+
json \
20+
fileinfo \
21+
sockets \
22+
imagick

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Install pnpm
2222
uses: pnpm/action-setup@v4
2323
with:
24-
version: 9
24+
version: 10
2525

2626
- name: Install Node.js LTS
2727
uses: actions/setup-node@v4

.github/workflows/tests.yml

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
name: E2E Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
e2e:
9+
name: PHP ${{ matrix.php }} - WP ${{ matrix.wordpress }}
10+
runs-on: ubuntu-24.04
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
php: [ "8.2", "8.3", "8.4" ]
15+
wordpress: [ "6.7", "6.8" ]
16+
exclude:
17+
# Exclude older PHP versions with newer WordPress
18+
- php: "7.4"
19+
wordpress: "6.5.3"
20+
21+
services:
22+
mysql:
23+
image: mysql:8.0
24+
env:
25+
MYSQL_DATABASE: wordpress
26+
MYSQL_ROOT_PASSWORD: root
27+
ports: [ 3306:3306 ]
28+
options: >-
29+
--health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -proot"
30+
--health-interval=10s
31+
--health-timeout=5s
32+
--health-retries=5
33+
34+
env:
35+
WP_VERSION: ${{ matrix.wordpress }}
36+
WP_SITE_URL: http://localhost:8100
37+
WP_DB_NAME: wordpress
38+
WP_DB_USER: root
39+
WP_DB_PASS: root
40+
WP_DB_HOST: 127.0.0.1
41+
42+
steps:
43+
- name: Check MySQL tables
44+
run: |
45+
echo "Listing databases:"
46+
mysql -h 127.0.0.1 -uroot -proot -e "SHOW DATABASES;"
47+
48+
echo "Checking if 'wordpress' database has any tables:"
49+
mysql -h 127.0.0.1 -uroot -proot -D wordpress -e "SHOW TABLES;" || echo "No tables found (yet)."
50+
51+
- name: Checkout plugin
52+
uses: actions/checkout@v4
53+
with:
54+
persist-credentials: false
55+
56+
- name: Set up PHP
57+
uses: shivammathur/setup-php@v2
58+
with:
59+
# Note: Specified version is only for running tests,
60+
# as the WordPress PHP version is set inside the FrankenPHP Dockerfile.
61+
php-version: 8.4
62+
extensions: mysqli, zip, gd
63+
coverage: none
64+
tools: wp-cli
65+
66+
- name: Cache WordPress archive
67+
id: cache-wordpress
68+
uses: actions/cache@v3
69+
with:
70+
path: /tmp/wp
71+
key: wp-${{ matrix.wordpress }}
72+
73+
- name: Download WordPress
74+
if: steps.cache-wordpress.outputs.cache-hit != 'true'
75+
run: |
76+
mkdir -p /tmp/wp
77+
curl -O https://wordpress.org/wordpress-${WP_VERSION}.tar.gz
78+
tar -xzf wordpress-${WP_VERSION}.tar.gz --strip-components=1 -C /tmp/wp
79+
rm wordpress-${WP_VERSION}.tar.gz
80+
81+
- name: Set up Docker Buildx
82+
uses: docker/setup-buildx-action@v3
83+
84+
- name: Build FrankenPHP image (with cache)
85+
id: build
86+
uses: docker/build-push-action@v6
87+
env:
88+
DOCKER_BUILD_SUMMARY: false
89+
with:
90+
context: .
91+
file: .github/docker/Dockerfile
92+
tags: frankenphp-${{ matrix.php }}
93+
load: true
94+
build-args: |
95+
PHP_VERSION=${{ matrix.php }}
96+
cache-from: type=gha
97+
cache-to: type=gha,mode=max
98+
99+
- name: Start FrankenPHP server
100+
run: |
101+
docker run -d \
102+
--name frankenphp \
103+
--network host \
104+
-p 8100:8100 \
105+
-v /tmp/wp:/var/www/html \
106+
-v $GITHUB_WORKSPACE:/var/www/html/wp-content/plugins/simpleanalytics \
107+
-v $GITHUB_WORKSPACE/Caddyfile:/etc/frankenphp/Caddyfile \
108+
frankenphp-${{ matrix.php }}
109+
110+
- name: Wait for FrankenPHP to be ready
111+
run: |
112+
for i in $(seq 1 30); do
113+
curl -s -o /dev/null http://localhost:8100 && echo "Server is up" && exit 0
114+
echo "Waiting... ($i/30)"
115+
sleep 2
116+
done
117+
echo "Server did not start in time" && exit 1
118+
119+
- name: Verify MySQL is accepting connections
120+
run: |
121+
for i in $(seq 1 10); do
122+
mysql -h 127.0.0.1 -uroot -proot -e "SELECT 1" && echo "MySQL ready" && exit 0
123+
echo "Waiting for MySQL... ($i/10)"
124+
sleep 2
125+
done
126+
echo "MySQL not ready" && exit 1
127+
128+
- name: Install WordPress
129+
run: |
130+
rm -f /tmp/wp/wp-config.php
131+
wp config create \
132+
--dbname="$WP_DB_NAME" \
133+
--dbuser="$WP_DB_USER" \
134+
--dbpass="$WP_DB_PASS" \
135+
--dbhost="$WP_DB_HOST" \
136+
--path=/tmp/wp \
137+
--skip-check
138+
wp config set DISABLE_WP_CRON true --raw --path=/tmp/wp
139+
wp core install \
140+
--url="${WP_SITE_URL}" \
141+
--title="Test Site" \
142+
--admin_user=admin \
143+
--admin_password=admin \
144+
--admin_email=test@example.com \
145+
--path=/tmp/wp \
146+
--skip-email \
147+
--allow-root
148+
wp user create author author@local.test --role=author --user_pass=author --path=/tmp/wp --allow-root
149+
wp user create editor editor@local.test --role=editor --user_pass=editor --path=/tmp/wp --allow-root
150+
wp user create subscriber subscriber@local.test --role=subscriber --user_pass=subscriber --path=/tmp/wp --allow-root
151+
152+
- name: Show current config values
153+
run: wp config list --path=/tmp/wp --allow-root
154+
155+
- name: Warm up WordPress
156+
run: |
157+
curl -s -o /dev/null -w "wp-login.php: HTTP %{http_code} in %{time_total}s\n" http://localhost:8100/wp-login.php
158+
curl -s -o /dev/null -w "homepage: HTTP %{http_code} in %{time_total}s\n" http://localhost:8100/
159+
160+
- name: Install pnpm
161+
uses: pnpm/action-setup@v4
162+
with:
163+
version: 10
164+
165+
- name: Setup Node
166+
uses: actions/setup-node@v4
167+
with:
168+
node-version: lts/*
169+
cache: "pnpm"
170+
171+
- name: Install pnpm dependencies
172+
run: pnpm install
173+
174+
- name: Install Playwright Browsers
175+
run: npx playwright install --with-deps
176+
177+
- name: Cache composer dependencies
178+
uses: actions/cache@v3
179+
with:
180+
path: vendor
181+
key: composer-${{ hashFiles('composer.lock') }}
182+
183+
- name: Run composer install
184+
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
185+
186+
- name: Run Pest tests
187+
run: ./vendor/bin/pest -v --ci --bail --colors=always
188+
189+
- name: Upload test results
190+
if: always()
191+
uses: actions/upload-artifact@v4
192+
with:
193+
name: test-results-php${{ matrix.php }}-wp${{ matrix.wordpress }}
194+
path: tests/Browser/Screenshots
195+
retention-days: 30
196+
197+
- name: Show FrankenPHP logs
198+
if: always()
199+
run: |
200+
echo "=== FrankenPHP logs ==="
201+
docker logs frankenphp || echo "No logs found"

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
.svn
2-
node*
3-
vendor*
42
build
3+
vendor/
4+
node_modules/
5+
.phpunit.result.cache
6+
var
7+
drivers
8+
driver

Caddyfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
local_certs
3+
auto_https off
4+
frankenphp
5+
}
6+
7+
:8100 {
8+
@static {
9+
file
10+
path *.avif *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.woff2 *.gpx
11+
}
12+
header @static Cache-Control max-age=5184000
13+
root * /var/www/html/
14+
encode br zstd gzip
15+
php_server
16+
log {
17+
format console
18+
}
19+
}

composer.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
{
22
"require-dev": {
3-
"rector/rector": "^1.2"
3+
"rector/rector": "^1.2",
4+
"pestphp/pest": "^4.1",
5+
"pestphp/pest-plugin-browser": "^4.1",
6+
"symfony/var-dumper": "^7.3"
7+
},
8+
"autoload": {
9+
"psr-4": {
10+
"Tests\\": "tests/"
11+
}
12+
},
13+
"config": {
14+
"allow-plugins": {
15+
"pestphp/pest-plugin": true
16+
}
417
}
518
}

0 commit comments

Comments
 (0)