diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 93feffd..680de5a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,11 +9,21 @@ on: jobs: test: runs-on: ubuntu-latest - + strategy: matrix: php-version: [8.2, 8.3, 8.4] + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: wordpress_test + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + steps: - uses: actions/checkout@v7 @@ -21,9 +31,12 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} - extensions: mbstring, intl + extensions: mbstring, intl, mysqli, pdo_mysql coverage: none + - name: Install system dependencies + run: sudo apt-get update && sudo apt-get install -y subversion + - name: Validate composer.json files run: | for plugin in community-listings contentful-tables graphql-shortcode-support; do @@ -52,6 +65,11 @@ jobs: - name: Run PHPStan run: make phpstan + - name: Run PHPUnit + env: + WP_TESTS_DIR: /tmp/wordpress-tests-lib + run: make test-integration DB_HOST=127.0.0.1 + - name: Build distribution packages run: make build diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6a2f35d..fa06eba 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -165,11 +165,13 @@ Run linting/static analysis for all sub-plugins: make test ``` -Run a sub-plugin's PHPUnit suite (requires a WordPress test environment — set up once, shared by all three sub-plugins): +Run the PHPUnit suites for all three sub-plugins (sets up the shared WordPress test environment once, then runs PHPUnit): ```bash -bash scripts/install-wp-tests.sh wordpress_test root '' localhost latest -bash scripts/install-wpgraphql-for-tests.sh -cd community-listings && WP_TESTS_DIR=/tmp/wordpress-tests-lib composer run phpunit +make test-integration + +# Or step-by-step: +make install-wp-test-env # Install the shared WordPress test suite + WPGraphQL (once) +make phpunit # Run PHPUnit for all 3 sub-plugins ``` ## 📤 Pull Request Process diff --git a/Makefile b/Makefile index 219cb75..5e0de74 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,20 @@ NC := \033[0m # No Color # Plugin directories PLUGINS := community-listings contentful-tables graphql-shortcode-support -.PHONY: help install install-dev clean test phpcs phpstan build release +# WordPress test suite database (override e.g. `make install-wp-test-env DB_PASS=...`) +DB_NAME ?= wordpress_test +DB_USER ?= root +DB_PASS ?= root +DB_HOST ?= 127.0.0.1 +WP_VERSION ?= latest + +# Fixed (not $TMPDIR-derived) so install-wp-tests.sh, install-wpgraphql-for-tests.sh, +# and each plugin's tests/bootstrap.php all agree on the same paths regardless of the +# platform's default temp dir (e.g. macOS's per-session /var/folders/... vs Linux's /tmp). +export WP_TESTS_DIR ?= /tmp/wordpress-tests-lib +export WP_CORE_DIR ?= /tmp/wordpress + +.PHONY: help install install-dev clean test phpcs phpstan build release install-wp-test-env phpunit test-integration help: ## Show this help message @echo "$(BLUE)Contentful WordPress Plugins - Development Commands$(NC)" @@ -78,6 +91,25 @@ phpstan: ## Run PHPStan static analysis on all plugins test: install-dev phpcs phpstan ## Run all quality assurance tests @echo "$(GREEN)✅ All tests passed!$(NC)" +install-wp-test-env: ## Install the shared WordPress test suite + WPGraphQL (one-time, shared across all plugins) + @echo "$(BLUE)Installing WordPress test suite...$(NC)" + @bash scripts/install-wp-tests.sh "$(DB_NAME)" "$(DB_USER)" "$(DB_PASS)" "$(DB_HOST)" "$(WP_VERSION)" + @bash scripts/install-wpgraphql-for-tests.sh + @echo "$(GREEN)✅ WordPress test environment ready!$(NC)" + +phpunit: ## Run PHPUnit suites for all plugins (requires install-wp-test-env first) + @echo "$(BLUE)Running PHPUnit on all plugins...$(NC)" + @status=0; \ + for plugin in $(PLUGINS); do \ + echo "Testing $$plugin..."; \ + (cd $$plugin && composer run phpunit) || status=1; \ + done; \ + exit $$status + @echo "$(GREEN)✅ PHPUnit completed!$(NC)" + +test-integration: install-dev install-wp-test-env phpunit ## Run PHPUnit suites incl. WordPress/WPGraphQL integration tests + @echo "$(GREEN)✅ Integration tests passed!$(NC)" + build: clean install ## Build production-ready plugins @echo "$(BLUE)Building production plugins...$(NC)" @mkdir -p dist diff --git a/README.md b/README.md index 5e92f73..9f3582a 100644 --- a/README.md +++ b/README.md @@ -203,10 +203,12 @@ Each sub-plugin has its own PHPUnit suite (`tests/Unit`, `tests/Integration`) co WPGraphQL registration behavior. They share one WordPress test environment, set up once: ```bash -bash scripts/install-wp-tests.sh wordpress_test root '' localhost latest -bash scripts/install-wpgraphql-for-tests.sh +# One-shot: install deps, set up the shared WP test env, run PHPUnit for all 3 plugins +make test-integration -cd community-listings && WP_TESTS_DIR=/tmp/wordpress-tests-lib composer run phpunit +# Or step-by-step: +make install-wp-test-env # Install the shared WordPress test suite + WPGraphQL (once) +make phpunit # Run PHPUnit for all 3 sub-plugins ``` ## 🤝 Contributing diff --git a/scripts/install-wpgraphql-for-tests.sh b/scripts/install-wpgraphql-for-tests.sh index 81ba7f4..146b250 100755 --- a/scripts/install-wpgraphql-for-tests.sh +++ b/scripts/install-wpgraphql-for-tests.sh @@ -75,9 +75,15 @@ if [ -d "$GRAPHQL_PLUGIN_DIR" ]; then if [[ "$FORCE_GRAPHQL_REINSTALL" == "true" ]] || [[ "$CI" == "true" ]] || [[ "$GITHUB_ACTIONS" == "true" ]] || [[ "$CONTINUOUS_INTEGRATION" == "true" ]]; then print_warning "Non-interactive mode: Automatically reinstalling WPGraphQL" REPLY="y" - else + elif [ -t 0 ]; then read -p "Do you want to reinstall WPGraphQL? (y/N): " -n 1 -r echo + else + # No TTY on stdin (e.g. invoked from `make`) and none of the CI flags above are + # set: `read` would hit EOF immediately and, under `set -e`, kill the script + # with no explanation. Default to keeping the existing install rather than that. + print_warning "Non-interactive shell with no CI flag set: keeping existing WPGraphQL install" + REPLY="n" fi if [[ ! $REPLY =~ ^[Yy]$ ]]; then