Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,34 @@ 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

- name: Setup PHP
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
Expand Down Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 33 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion scripts/install-wpgraphql-for-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down