Skip to content

Commit 7073a55

Browse files
osbreclaude
andcommitted
Add local test environment via docker-compose + Makefile
docker-compose.yml mirrors the CI setup: MySQL 8 + FrankenPHP on a shared named network. wp-cli runs in a container on that network so DB_HOST=mysql works consistently. Makefile exposes three targets: make test-env — first-time setup (downloads WP, starts stack) make test — run the suite make test-reset — tear down and start completely fresh Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9c038d9 commit 7073a55

3 files changed

Lines changed: 91 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ node_modules/
66
var
77
drivers
88
driver
9+
tmp/

Makefile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
WP_VERSION ?= 6.8
2+
WP_URL = http://localhost:8100
3+
WP_PATH = /var/www/html
4+
NETWORK = simpleanalytics-wptest
5+
WP_CLI = docker run --rm --network $(NETWORK) -v $(PWD)/tmp/wp:$(WP_PATH) wordpress:cli
6+
7+
.PHONY: test-env test test-reset _wp-install
8+
9+
## Start containers + install WordPress (idempotent)
10+
test-env: tmp/wp/wp-login.php
11+
docker compose up -d --build --wait
12+
$(MAKE) _wp-install
13+
14+
## Run the test suite
15+
test:
16+
./vendor/bin/phpunit --colors=always
17+
18+
## Tear everything down and start fresh
19+
test-reset:
20+
docker compose down -v
21+
rm -rf tmp/wp
22+
$(MAKE) test-env
23+
24+
# ── internals ──────────────────────────────────────────────────────────────────
25+
26+
tmp/wp/wp-login.php:
27+
mkdir -p tmp/wp
28+
curl -s -O https://wordpress.org/wordpress-$(WP_VERSION).tar.gz
29+
tar -xzf wordpress-$(WP_VERSION).tar.gz --strip-components=1 -C tmp/wp
30+
rm -f wordpress-$(WP_VERSION).tar.gz
31+
32+
_wp-install:
33+
rm -f tmp/wp/wp-config.php
34+
$(WP_CLI) wp config create \
35+
--dbname=wordpress --dbuser=root --dbpass=root \
36+
--dbhost=mysql --path=$(WP_PATH) --skip-check
37+
$(WP_CLI) wp core install \
38+
--url=$(WP_URL) --title="Test Site" \
39+
--admin_user=admin --admin_password=admin \
40+
--admin_email=test@example.com \
41+
--path=$(WP_PATH) --skip-email --allow-root
42+
$(WP_CLI) wp user create author author@local.test \
43+
--role=author --user_pass=author --path=$(WP_PATH) --allow-root
44+
$(WP_CLI) wp user create editor editor@local.test \
45+
--role=editor --user_pass=editor --path=$(WP_PATH) --allow-root
46+
$(WP_CLI) wp user create subscriber subscriber@local.test \
47+
--role=subscriber --user_pass=subscriber --path=$(WP_PATH) --allow-root

docker-compose.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
services:
2+
mysql:
3+
image: mysql:8.0
4+
environment:
5+
MYSQL_DATABASE: wordpress
6+
MYSQL_ROOT_PASSWORD: root
7+
ports:
8+
- "3306:3306"
9+
healthcheck:
10+
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-proot"]
11+
interval: 5s
12+
timeout: 3s
13+
retries: 10
14+
networks:
15+
- wptest
16+
17+
frankenphp:
18+
build:
19+
context: .
20+
dockerfile: .github/docker/Dockerfile
21+
args:
22+
PHP_VERSION: 8.4
23+
ports:
24+
- "8100:8100"
25+
volumes:
26+
- ./tmp/wp:/var/www/html
27+
- .:/var/www/html/wp-content/plugins/simpleanalytics
28+
- ./Caddyfile:/etc/frankenphp/Caddyfile
29+
depends_on:
30+
mysql:
31+
condition: service_healthy
32+
healthcheck:
33+
test: ["CMD", "curl", "-sf", "http://localhost:8100"]
34+
interval: 5s
35+
timeout: 3s
36+
retries: 20
37+
start_period: 10s
38+
networks:
39+
- wptest
40+
41+
networks:
42+
wptest:
43+
name: simpleanalytics-wptest

0 commit comments

Comments
 (0)