The reload container (docker/web-dev/live.js, browser-sync) now publishes the site's port itself, so the page's socket can connect
(the old proxy ws option moved it to an unpublished port: the tab never followed). The IDE tells it each saved file (POST /__jumphp/notify),
so it works without file events (Docker Desktop also polls); CSS is injected without a reload, anything else reloads once.
Status bar item Live: N (browser tabs connected), open the site at the live-reload address, turn it off ('live': 'off' in web.json).
bin/jumphp web:live, LiveReload (IDE) + tests, end-to-end test with headless Chrome on a Symfony site, docs, 14 languages.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
126 lines
6.3 KiB
Shell
126 lines
6.3 KiB
Shell
#!/usr/bin/env bash
|
|
# Tests of tools/web.sh's PHP version and Docker setup functions (no Docker needed: the resolver is stubbed):
|
|
# bash tools/tests/web.test.sh (WEB_TEST_DOCKER=1: also the real resolver, tools/web-php.php in composer:2)
|
|
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
WEB_SH_LIB=1 . "$HERE/../web.sh"
|
|
set +e -uo pipefail
|
|
fails=0
|
|
check() { if [ "$2" == "$3" ]; then echo "ok $1"; else echo "FAIL $1: expected [$3], got [$2]"; fails=$((fails + 1)); fi; }
|
|
say() { :; }
|
|
tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
|
|
|
|
# .jumphp/web.json: keys written, read, removed; the others kept
|
|
d="$tmp/site"; mkdir -p "$d/.jumphp"
|
|
printf '{\n "kind": "symfony",\n "local_php": "/opt/php/bin/php"\n}\n' > "$d/.jumphp/web.json"
|
|
web_json_set "$d" php 8.3
|
|
check 'web.json: key added' "$(web_json_get "$d" php)" 8.3
|
|
check 'web.json: others kept' "$(web_json_get "$d" kind)/$(web_json_get "$d" local_php)" symfony//opt/php/bin/php
|
|
web_json_set "$d" php 8.5
|
|
check 'web.json: key replaced' "$(cat "$d/.jumphp/web.json")" '{"kind": "symfony", "local_php": "/opt/php/bin/php", "php": "8.5"}'
|
|
check 'web.json: "php" is not local_php' "$(web_json_get "$d" php)" 8.5
|
|
web_json_set "$d" php ""
|
|
check 'web.json: key removed' "$(cat "$d/.jumphp/web.json")" '{"kind": "symfony", "local_php": "/opt/php/bin/php"}'
|
|
rm -f "$d/.jumphp/web.json"; web_json_set "$d" db mariadb
|
|
check 'web.json: made' "$(cat "$d/.jumphp/web.json")" '{"db": "mariadb"}'
|
|
|
|
# versions offered
|
|
offered 8.4; check 'offered 8.4' "$?" 0
|
|
offered 8.6; check 'not offered 8.6' "$?" 1
|
|
offered 8; check 'not offered 8' "$?" 1
|
|
check 'image of a version' "$(web_image 8.5)" jumphp/web:php8.5
|
|
|
|
# the setup
|
|
check 'setup: jumphp by default' "$(setup_of "$d")" jumphp
|
|
mkdir -p "$d/frankenphp"; echo 'services: {php: {build: .}}' > "$d/compose.yaml"
|
|
printf '#syntax=docker/dockerfile:1\n\n# Versions\nFROM dunglas/frankenphp:1-php8.5 AS frankenphp_upstream\nFROM frankenphp_upstream AS base\n' > "$d/Dockerfile"
|
|
check 'setup: symfony-docker files' "$(setup_of "$d")" dunglas
|
|
web_json_set "$d" docker jumphp
|
|
check 'setup: web.json wins' "$(setup_of "$d")" jumphp
|
|
web_json_set "$d" docker ""
|
|
|
|
# the PHP: web.json, symfony-docker's Dockerfile, what Composer needs (stubbed resolver, cached)
|
|
check 'php: Dockerfile of symfony-docker' "$(php_of "$d")" 8.5
|
|
dunglas_set_php "$d" 8.3
|
|
check 'php: Dockerfile rewritten' "$(sed -n 4p "$d/Dockerfile")" 'FROM dunglas/frankenphp:1-php8.3 AS frankenphp_upstream'
|
|
check 'php: read again' "$(php_of "$d")" 8.3
|
|
web_json_set "$d" php 8.4
|
|
check 'php: web.json wins' "$(php_info "$d")" "$(printf '8.4\tweb.json: chosen for this project')"
|
|
web_json_set "$d" php ""; rm -rf "$d/frankenphp" "$d/Dockerfile" "$d/compose.yaml"
|
|
echo '{"require": {"php": ">=8.2"}}' > "$d/composer.json"
|
|
calls="$tmp/calls"; : > "$calls"
|
|
resolver() { echo x >> "$calls"; printf '8.5\tcomposer: stub\n'; }
|
|
WEB_PHP_RESOLVER=resolver
|
|
check 'php: what Composer needs' "$(php_of "$d")" 8.5
|
|
php_of "$d" >/dev/null
|
|
check 'php: cached until composer files change' "$(wc -l < "$calls" | tr -d ' ')" 1
|
|
echo '{"require": {"php": ">=8.3"}}' > "$d/composer.json"
|
|
php_of "$d" >/dev/null
|
|
check 'php: resolved again after a change' "$(wc -l < "$calls" | tr -d ' ')" 2
|
|
resolver() { echo 'garbage'; }; rm -f "$d/.jumphp/php.auto"
|
|
check 'php: a failed resolver gives the default' "$(php_of "$d")" "$WEB_PHP_DEFAULT"
|
|
rm -f "$d/composer.json"
|
|
check 'php: no composer.json, the default' "$(php_of "$d")" "$WEB_PHP_DEFAULT"
|
|
unset WEB_PHP_RESOLVER
|
|
|
|
# an own compose stack: the image tag of its PHP service
|
|
o="$tmp/own"; mkdir -p "$o"
|
|
cat > "$o/compose.yaml" <<'YAML'
|
|
services:
|
|
db:
|
|
image: mysql:8.0
|
|
php:
|
|
image: php:8.3.12-fpm-alpine
|
|
volumes: [".:/app"]
|
|
web:
|
|
image: nginx:1.27
|
|
YAML
|
|
web_json_set "$o" docker compose; web_json_set "$o" service php
|
|
check 'own: setup' "$(setup_of "$o")" compose
|
|
check 'own: file' "$(own_file "$o")" compose.yaml
|
|
check 'own: php from its image' "$(php_info "$o")" "$(printf '\tcompose: the image of the service php')"
|
|
own_set_php "$o" 8.5
|
|
check 'own: php image retagged' "$(grep -c 'image: php:8.5-fpm-alpine' "$o/compose.yaml")" 1
|
|
check 'own: other images kept' "$(grep -c 'mysql:8.0\|nginx:1.27' "$o/compose.yaml")" 2
|
|
web_json_set "$o" service app
|
|
cat > "$o/compose.yaml" <<'YAML'
|
|
services:
|
|
app:
|
|
build: .
|
|
YAML
|
|
printf 'FROM php:8.2-cli\nRUN true\n' > "$o/Dockerfile"
|
|
own_set_php "$o" 8.4
|
|
check 'own: Dockerfile FROM' "$(head -1 "$o/Dockerfile")" 'FROM php:8.4-cli'
|
|
|
|
# the console program
|
|
mkdir -p "$o/bin"; : > "$o/artisan"
|
|
check 'console: artisan' "$(console_tool "$o")" artisan
|
|
: > "$o/bin/console"
|
|
check 'console: bin/console' "$(console_tool "$o")" bin/console
|
|
|
|
# live reload: the reload container publishes the site's port itself (the page's socket connects there), live.js is copied,
|
|
# the port is told to the IDE (web.json live_port), polling forced by JUMPHP_LIVE_POLL, "live": "off" removes it all
|
|
l="$tmp/live"; mkdir -p "$l"
|
|
export JUMPHP_LIVE_POLL=1
|
|
check 'live: polling forced on' "$(live_poll)" 1
|
|
check 'live: polling forced off' "$(JUMPHP_LIVE_POLL=0 live_poll)" 0
|
|
compose_file "$l" symfony ./public 8200 sqlite "" 8.4 >/dev/null 2>&1
|
|
check 'live: reload service' "$(grep -c '^ reload:' "$l/.jumphp/compose.yaml")" 1
|
|
check 'live: port published as itself' "$(grep -c '127.0.0.1:8200:8200' "$l/.jumphp/compose.yaml")" 1
|
|
check 'live: poll env' "$(grep -c 'JUMPHP_LIVE_POLL: "1"' "$l/.jumphp/compose.yaml")" 1
|
|
check 'live: live.js copied' "$(cmp -s "$l/.jumphp/live.js" "$HERE/../../docker/web-dev/live.js" && echo same)" same
|
|
check 'live: port in web.json' "$(web_json_get "$l" live_port)" 8200
|
|
check 'live: no old bs-config' "$([ -e "$l/.jumphp/bs-config.js" ] && echo yes || echo no)" no
|
|
web_json_set "$l" live off
|
|
compose_file "$l" symfony ./public 8200 sqlite "" 8.4 >/dev/null 2>&1
|
|
check 'live off: no reload service' "$(grep -c '^ reload:' "$l/.jumphp/compose.yaml")" 0
|
|
check 'live off: the site on its own port' "$(grep -c '127.0.0.1:8200:8080' "$l/.jumphp/compose.yaml")" 1
|
|
unset JUMPHP_LIVE_POLL
|
|
|
|
if [ "${WEB_TEST_DOCKER:-}" = 1 ]; then
|
|
r="$tmp/real"; mkdir -p "$r"
|
|
echo '{"require": {"php": ">=8.2"}}' > "$r/composer.json"
|
|
echo '{"packages": [{"name": "a/b", "require": {"php": ">=8.1 <8.4"}}], "packages-dev": []}' > "$r/composer.lock"
|
|
check 'real resolver: the lock limits' "$(php_of "$r")" 8.3
|
|
fi
|
|
|
|
[ "$fails" = 0 ] && echo "all passed" || { echo "$fails failed"; exit 1; }
|