Added a Docker-based fresh WordPress integration test

This commit is contained in:
2026-05-31 13:15:43 +03:30
parent 2703e956da
commit 6419f82ea5
7 changed files with 422 additions and 4 deletions
+81
View File
@@ -0,0 +1,81 @@
#!/usr/bin/env bash
set -Eeuo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_NAME="${COMPOSE_PROJECT_NAME:-mahak-authenticate-bridge-test}"
WORDPRESS_PORT="${WORDPRESS_PORT:-8080}"
KEEP_TEST_ENV="${KEEP_TEST_ENV:-0}"
if docker info >/dev/null 2>&1; then
DOCKER=(docker)
elif command -v sudo >/dev/null 2>&1; then
DOCKER=(sudo docker)
else
echo "Docker is not available." >&2
exit 1
fi
COMPOSE=("${DOCKER[@]}" compose)
compose() {
WORDPRESS_PORT="$WORDPRESS_PORT" "${COMPOSE[@]}" \
-p "$PROJECT_NAME" \
-f "$SCRIPT_DIR/docker-compose.yml" \
"$@"
}
cleanup() {
if [[ "$KEEP_TEST_ENV" != "1" ]]; then
compose down --volumes --remove-orphans >/dev/null 2>&1 || true
fi
}
wait_for_wordpress_files() {
for _ in $(seq 1 90); do
if compose exec -T wordpress php -r 'exit(is_file("/var/www/html/wp-load.php") ? 0 : 1);' >/dev/null 2>&1; then
return 0
fi
sleep 1
done
echo "WordPress files were not ready in time." >&2
return 1
}
run_php_lint() {
compose exec -T wordpress sh -lc '
find /var/www/html/wp-content/plugins/mahak-authenticate-bridge \
-path "*/.git" -prune -o \
-name "*.php" -print \
| xargs -n1 php -l
'
}
trap cleanup EXIT
echo "Resetting test containers and volumes..."
compose down --volumes --remove-orphans
echo "Pulling Docker images..."
compose pull
echo "Starting fresh WordPress on http://127.0.0.1:${WORDPRESS_PORT} ..."
compose up -d
echo "Waiting for WordPress files..."
wait_for_wordpress_files
echo "Running PHP 7.4 syntax checks..."
run_php_lint
echo "Running authentication integration test in PHP 7.4..."
compose exec -T wordpress php /var/www/html/wp-content/plugins/mahak-authenticate-bridge/test/integration-authentication.php
echo "Integration test passed."
if [[ "$KEEP_TEST_ENV" == "1" ]]; then
echo "Test environment kept running. Clean it up with:"
echo " ${COMPOSE[*]} -p $PROJECT_NAME -f $SCRIPT_DIR/docker-compose.yml down --volumes --remove-orphans"
fi