From d307d2726ea543ac6019c203e855ff2049fc5494 Mon Sep 17 00:00:00 2001 From: Igor Tron Date: Sun, 26 Apr 2026 09:43:24 +0400 Subject: [PATCH 1/5] Fix unit test dependency install in CI --- .github/workflows/wp-unit-tests.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/wp-unit-tests.yml b/.github/workflows/wp-unit-tests.yml index 4781bf2..fde6e8d 100644 --- a/.github/workflows/wp-unit-tests.yml +++ b/.github/workflows/wp-unit-tests.yml @@ -1,8 +1,5 @@ name: Unit Tests -env: - COMPOSER_VER: "2.7.9" - on: push: branches: [ "master", "main", "dev" ] @@ -44,10 +41,8 @@ jobs: php-version: ${{ matrix.php-version }} coverage: none - - uses: php-actions/composer@v6 - with: - php_version: ${{ matrix.php-version }} - version: ${{ env.COMPOSER_VER }} + - name: Install PHP Dependencies + uses: ramsey/composer-install@v2 - name: Select Ramsey Collection version run: | From 37c76171210a11bf5ee591acb44a79deb47ece3a Mon Sep 17 00:00:00 2001 From: Igor Tron Date: Sun, 26 Apr 2026 09:45:12 +0400 Subject: [PATCH 2/5] Fix WPStorage indentation for PHPCS --- src/WPStorage.php | 64 +++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/WPStorage.php b/src/WPStorage.php index 149f3b0..b6c14e3 100644 --- a/src/WPStorage.php +++ b/src/WPStorage.php @@ -51,38 +51,38 @@ private function init() $this->install(); } - private function install() - { - Database::install_table( - $this->get_connections_table(), - " - `ID` bigint(20) unsigned NOT NULL auto_increment, - `relation` varchar(255) NOT NULL, - `from` bigint(20) unsigned NOT NULL, - `to` bigint(20) unsigned NOT NULL, - `order` bigint(20) unsigned NULL default '0', - `title` varchar(63) NULL default '', - PRIMARY KEY (`ID`), - KEY `from` (`from`), - KEY `to` (`to`), - KEY `order` (`order`), - KEY `relation` (`relation`) - " - ); - - Database::install_table( - $this->get_meta_table(), - " - `meta_id` bigint(20) unsigned NOT NULL auto_increment, - `connection_id` bigint(20) unsigned NOT NULL default '0', - `meta_key` varchar(255) NOT NULL, - `meta_value` longtext NOT NULL, - PRIMARY KEY (`meta_id`), - KEY `connection_id` (`connection_id`), - KEY `meta_key` (`meta_key`) - " - ); - } + private function install() + { + Database::install_table( + $this->get_connections_table(), + " + `ID` bigint(20) unsigned NOT NULL auto_increment, + `relation` varchar(255) NOT NULL, + `from` bigint(20) unsigned NOT NULL, + `to` bigint(20) unsigned NOT NULL, + `order` bigint(20) unsigned NULL default '0', + `title` varchar(63) NULL default '', + PRIMARY KEY (`ID`), + KEY `from` (`from`), + KEY `to` (`to`), + KEY `order` (`order`), + KEY `relation` (`relation`) + " + ); + + Database::install_table( + $this->get_meta_table(), + " + `meta_id` bigint(20) unsigned NOT NULL auto_increment, + `connection_id` bigint(20) unsigned NOT NULL default '0', + `meta_key` varchar(255) NOT NULL, + `meta_value` longtext NOT NULL, + PRIMARY KEY (`meta_id`), + KEY `connection_id` (`connection_id`), + KEY `meta_key` (`meta_key`) + " + ); + } /** From e67c7c0c60cc1c0774665e8bca6d6e1f1ca9cb78 Mon Sep 17 00:00:00 2001 From: Igor Tron Date: Sun, 26 Apr 2026 10:05:09 +0400 Subject: [PATCH 3/5] Move CI checks to Docker workflow --- .github/workflows/php-cs.yml | 33 ++--- .github/workflows/wp-unit-tests-docker.yml | 15 +- .github/workflows/wp-unit-tests.yml | 115 ---------------- Dockerfile.phpunit | 10 +- docker/phpunit-entrypoint.sh | 153 +++++++++++++-------- 5 files changed, 113 insertions(+), 213 deletions(-) delete mode 100644 .github/workflows/wp-unit-tests.yml diff --git a/.github/workflows/php-cs.yml b/.github/workflows/php-cs.yml index 3fc5f33..533c9b9 100644 --- a/.github/workflows/php-cs.yml +++ b/.github/workflows/php-cs.yml @@ -1,7 +1,6 @@ name: PHP Code Styles env: - COMPOSER_VER: "2.7.9" PHP_VER: "8.1" on: @@ -14,29 +13,17 @@ jobs: php-cs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Cache Composer dependencies - uses: actions/cache@v3 - with: - path: /tmp/composer-cache - key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} + - uses: actions/checkout@v4 - - uses: php-actions/composer@v6 - with: - php_version: ${{ env.PHP_VER }} - version: ${{ env.COMPOSER_VER }} - - - name: Get PHPCS Cache - id: phpcs-cache + - name: Build CI image run: | - echo "file=.phpcs.cache" >> $GITHUB_OUTPUT - - - uses: actions/cache@v3 - with: - path: ${{ steps.phpcs-cache.outputs.file }} - key: ${{ runner.os }}-phpcs-${{ hashFiles('**/.phpcs.cache') }} - restore-keys: | - ${{ runner.os }}-phpcs- + docker build \ + --build-arg PHP_VERSION=${{ env.PHP_VER }} \ + -t wpconnections-ci:${{ env.PHP_VER }} \ + -f Dockerfile.phpunit . - name: Run PHPCS - run: composer run phpcs + run: | + docker run --rm -v "$PWD:/srv/web" \ + wpconnections-ci:${{ env.PHP_VER }} \ + cs:phpcs diff --git a/.github/workflows/wp-unit-tests-docker.yml b/.github/workflows/wp-unit-tests-docker.yml index 990db28..a1fae5d 100644 --- a/.github/workflows/wp-unit-tests-docker.yml +++ b/.github/workflows/wp-unit-tests-docker.yml @@ -1,4 +1,4 @@ -name: Unit Tests (Dockerfile) +name: Unit Tests on: push: @@ -10,7 +10,7 @@ permissions: {} jobs: phpunit: - name: PHP Unit ${{ matrix.php-version }} / Ramsey ${{ matrix.ramsey-version }} + name: PHP + WP Unit ${{ matrix.php-version }} / Ramsey ${{ matrix.ramsey-version }} runs-on: ubuntu-latest strategy: @@ -23,15 +23,16 @@ jobs: - name: Check out the source code uses: actions/checkout@v4 - - name: Build PHPUnit image + - name: Build CI image run: | docker build \ --build-arg PHP_VERSION=${{ matrix.php-version }} \ - -t wpconnections-phpunit:${{ matrix.php-version }} \ + -t wpconnections-ci:${{ matrix.php-version }} \ -f Dockerfile.phpunit . - - name: Run all tests + - name: Run PHP and WordPress unit tests run: | docker run --rm -v "$PWD:/srv/web" \ - wpconnections-phpunit:${{ matrix.php-version }} \ - sh -lc 'git config --global --add safe.directory "*" && composer update ramsey/collection --with "ramsey/collection:${{ matrix.ramsey-version }}" --prefer-dist --no-interaction && composer run phpunit && vendor/bin/phpunit -c php-wp-unit.xml' + -e RAMSEY_VERSION='${{ matrix.ramsey-version }}' \ + wpconnections-ci:${{ matrix.php-version }} \ + test:all diff --git a/.github/workflows/wp-unit-tests.yml b/.github/workflows/wp-unit-tests.yml deleted file mode 100644 index fde6e8d..0000000 --- a/.github/workflows/wp-unit-tests.yml +++ /dev/null @@ -1,115 +0,0 @@ -name: Unit Tests - -on: - push: - branches: [ "master", "main", "dev" ] - pull_request: - types: [synchronize, opened, reopened] - -permissions: {} - -jobs: - phpunit: - name: PHP Unit ${{ matrix.php-version }} / Ramsey ${{ matrix.ramsey-version }} - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - php-version: [ 8.1, 8.2, 8.3, 8.4 ] - ramsey-version: [ "^1", "^2" ] - - services: - mysql: - image: mariadb:latest - ports: - - '3306:3306' - env: - MYSQL_ROOT_PASSWORD: wordpress - MARIADB_INITDB_SKIP_TZINFO: 1 - MYSQL_USER: wordpress - MYSQL_PASSWORD: wordpress - MYSQL_DATABASE: wordpress_test - - steps: - - name: Check out the source code - uses: actions/checkout@v3 - - - uses: shivammathur/setup-php@v2 - name: Set up PHP - with: - php-version: ${{ matrix.php-version }} - coverage: none - - - name: Install PHP Dependencies - uses: ramsey/composer-install@v2 - - - name: Select Ramsey Collection version - run: | - composer update ramsey/collection \ - --with "ramsey/collection:${{ matrix.ramsey-version }}" \ - --prefer-dist \ - --no-interaction - - - name: Run UnitTests - run: composer run phpunit - - wp-unit: - name: WP Unit ${{ matrix.php-version }} / Ramsey ${{ matrix.ramsey-version }} - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - php-version: [ 8.1, 8.2, 8.3, 8.4 ] - ramsey-version: [ "^1", "^2" ] - - services: - mysql: - image: mariadb:latest - ports: - - '3306:3306' - env: - MYSQL_ROOT_PASSWORD: wordpress - MARIADB_INITDB_SKIP_TZINFO: 1 - MYSQL_USER: wordpress - MYSQL_PASSWORD: wordpress - MYSQL_DATABASE: wordpress_test - - steps: - - name: Check out the source code - uses: actions/checkout@v3 - - - uses: shivammathur/setup-php@v2 - name: Set up PHP - with: - php-version: ${{ matrix.php-version }} - coverage: none - - - name: Install PHP Dependencies - uses: ramsey/composer-install@v2 - - - name: Select Ramsey Collection version - run: | - composer update ramsey/collection \ - --with "ramsey/collection:${{ matrix.ramsey-version }}" \ - --prefer-dist \ - --no-interaction - - - name: Install Subversion - run: sudo apt-get update && sudo apt-get install -y subversion - - - name: Set up WordPress and WordPress Test Library - uses: sjinks/setup-wordpress-test-library@master - with: - version: latest - - - name: Verify MariaDB connection - run: | - while ! mysqladmin ping -h 127.0.0.1 -P ${{ job.services.mysql.ports[3306] }} --silent; do - sleep 1 - done - timeout-minutes: 1 - - - name: Run - run: vendor/bin/phpunit -c php-wp-unit.xml diff --git a/Dockerfile.phpunit b/Dockerfile.phpunit index dda1e9a..5985634 100644 --- a/Dockerfile.phpunit +++ b/Dockerfile.phpunit @@ -18,8 +18,7 @@ ENV COMPOSER_ALLOW_SUPERUSER=1 \ MYSQL_SOCKET=/run/mysqld/mysqld.sock \ DB_HOST=127.0.0.1 \ DB_NAME=wordpress_test \ - DB_USER=wordpress \ - DB_PASSWORD=wordpress + DB_USER=wordpress RUN set -eux; \ apt-get update; \ @@ -41,21 +40,18 @@ RUN set -eux; \ # Provide composer inside the image COPY --from=composer:2 /usr/bin/composer /usr/bin/composer -# Pre-install WordPress core and the WordPress test library so the container -# is fully self-contained when executing the WordPress PHPUnit suite. +# Pre-install the WordPress test library so the container is self-contained +# when executing the WordPress PHPUnit suite. RUN set -eux; \ rm -rf "${WP_DEVELOP_DIR}"; \ mkdir -p "${WP_DEVELOP_DIR}"; \ if [ "${WP_VERSION}" = "latest" ]; then \ - WP_TARBALL_URL="https://wordpress.org/latest.tar.gz"; \ WP_TESTS_ARCHIVE="https://github.com/WordPress/wordpress-develop/archive/refs/heads/master.tar.gz"; \ WP_TESTS_REF="master"; \ else \ - WP_TARBALL_URL="https://wordpress.org/wordpress-${WP_VERSION}.tar.gz"; \ WP_TESTS_ARCHIVE="https://github.com/WordPress/wordpress-develop/archive/refs/tags/${WP_VERSION}.tar.gz"; \ WP_TESTS_REF="${WP_VERSION}"; \ fi; \ - curl -fsSL "$WP_TESTS_ARCHIVE" -o /tmp/wordpress-develop.tar.gz; \ tar -xzf /tmp/wordpress-develop.tar.gz -C "${WP_DEVELOP_DIR}" --strip-components=1; \ rm /tmp/wordpress-develop.tar.gz; \ diff --git a/docker/phpunit-entrypoint.sh b/docker/phpunit-entrypoint.sh index 4015cde..a9ebd91 100755 --- a/docker/phpunit-entrypoint.sh +++ b/docker/phpunit-entrypoint.sh @@ -10,98 +10,118 @@ WP_DEVELOP_DIR="${WP_DEVELOP_DIR:-/opt/wordpress-develop}" WP_TESTS_DIR="${WP_TESTS_DIR:-/opt/wordpress-develop/tests/phpunit}" MYSQL_SOCKET="${MYSQL_SOCKET:-/run/mysqld/mysqld.sock}" MYSQL_DATA_DIR="${MYSQL_DATA_DIR:-/tmp/mysql-data}" +RAMSEY_VERSION="${RAMSEY_VERSION:-}" CONFIG_SAMPLE="${WP_DEVELOP_DIR}/wp-tests-config-sample.php" CONFIG_FILE="${WP_DEVELOP_DIR}/wp-tests-config.php" MYSQL_RUNTIME_USER="${MYSQL_RUNTIME_USER:-$(id -un 2>/dev/null || echo root)}" MYSQL_RUN_DIR="$(dirname "${MYSQL_SOCKET}")" +MYSQLD_PID="" +WP_ENV_READY=0 -mkdir -p "${MYSQL_RUN_DIR}" "${MYSQL_DATA_DIR}" - -if [ "$(id -u)" -eq 0 ]; then - chown -R "${MYSQL_RUNTIME_USER}" "${MYSQL_RUN_DIR}" "${MYSQL_DATA_DIR}" -fi - -if [ ! -d "${MYSQL_DATA_DIR}/mysql" ]; then - mariadb-install-db \ - --user="${MYSQL_RUNTIME_USER}" \ - --datadir="${MYSQL_DATA_DIR}" \ - --skip-test-db \ - --auth-root-authentication-method=normal >/dev/null -fi - -mariadbd \ - --user="${MYSQL_RUNTIME_USER}" \ - --datadir="${MYSQL_DATA_DIR}" \ - --socket="${MYSQL_SOCKET}" \ - --bind-address=127.0.0.1 \ - --skip-networking=0 & -MYSQLD_PID=$! +WORKDIR="/srv/web" cleanup() { - if kill -0 "${MYSQLD_PID}" >/dev/null 2>&1; then + if [ -n "${MYSQLD_PID}" ] && kill -0 "${MYSQLD_PID}" >/dev/null 2>&1; then mysqladmin --protocol=socket --socket="${MYSQL_SOCKET}" -uroot shutdown >/dev/null 2>&1 || true wait "${MYSQLD_PID}" >/dev/null 2>&1 || true fi } trap cleanup EXIT -MYSQL_READY=0 -for _ in $(seq 1 30); do - if mysqladmin --protocol=socket --socket="${MYSQL_SOCKET}" -uroot ping >/dev/null 2>&1; then - MYSQL_READY=1 - break +cd "$WORKDIR" +git config --global --add safe.directory "*" >/dev/null 2>&1 || true + +log_section() { + echo + echo "========================================" + echo ">>> $1" + echo "========================================" +} + +start_database() { + log_section "MariaDB" + + mkdir -p "${MYSQL_RUN_DIR}" "${MYSQL_DATA_DIR}" + + if [ "$(id -u)" -eq 0 ]; then + chown -R "${MYSQL_RUNTIME_USER}" "${MYSQL_RUN_DIR}" "${MYSQL_DATA_DIR}" fi - sleep 1 -done -if [ "${MYSQL_READY}" -ne 1 ]; then - echo "Timed out waiting for MariaDB to accept connections" >&2 - exit 1 -fi + if [ ! -d "${MYSQL_DATA_DIR}/mysql" ]; then + mariadb-install-db \ + --user="${MYSQL_RUNTIME_USER}" \ + --datadir="${MYSQL_DATA_DIR}" \ + --skip-test-db \ + --auth-root-authentication-method=normal >/dev/null + fi + + mariadbd \ + --user="${MYSQL_RUNTIME_USER}" \ + --datadir="${MYSQL_DATA_DIR}" \ + --socket="${MYSQL_SOCKET}" \ + --bind-address=127.0.0.1 \ + --skip-networking=0 & + MYSQLD_PID=$! + + local mysql_ready=0 + for _ in $(seq 1 30); do + if mysqladmin --protocol=socket --socket="${MYSQL_SOCKET}" -uroot ping >/dev/null 2>&1; then + mysql_ready=1 + break + fi + sleep 1 + done + + if [ "${mysql_ready}" -ne 1 ]; then + echo "Timed out waiting for MariaDB to accept connections" >&2 + exit 1 + fi -mysql --protocol=socket --socket="${MYSQL_SOCKET}" -uroot <&2 - if [ -f "${CONFIG_SAMPLE}" ]; then - cp "${CONFIG_SAMPLE}" "${CONFIG_FILE}" - else - echo "Sample config not found at ${CONFIG_SAMPLE}" >&2 - exit 1 +prepare_wp_tests() { + if [ "${WP_ENV_READY}" -eq 1 ]; then + return fi -fi - -sed -i "s/youremptytestdbnamehere/${DB_NAME}/" "${CONFIG_FILE}" -sed -i "s/yourusernamehere/${DB_USER}/" "${CONFIG_FILE}" -sed -i "s/yourpasswordhere/${DB_PASSWORD}/" "${CONFIG_FILE}" -sed -i "s|localhost|${DB_HOST}|1" "${CONFIG_FILE}" -sed -i "s|dirname( __FILE__ ) . '/../../'|'${WP_CORE_DIR}/'|" "${CONFIG_FILE}" -export WP_TESTS_DIR DB_HOST DB_NAME DB_USER DB_PASSWORD + start_database -# ==== Here and below is a universal "command dispatcher" ==== + if [ ! -f "${CONFIG_FILE}" ]; then + echo "wp-tests-config.php missing; recreating from sample" >&2 + if [ -f "${CONFIG_SAMPLE}" ]; then + cp "${CONFIG_SAMPLE}" "${CONFIG_FILE}" + else + echo "Sample config not found at ${CONFIG_SAMPLE}" >&2 + exit 1 + fi + fi -WORKDIR="/srv/web" -cd "$WORKDIR" + sed -i "s/youremptytestdbnamehere/${DB_NAME}/" "${CONFIG_FILE}" + sed -i "s/yourusernamehere/${DB_USER}/" "${CONFIG_FILE}" + sed -i "s/yourpasswordhere/${DB_PASSWORD}/" "${CONFIG_FILE}" + sed -i "s|localhost|${DB_HOST}|1" "${CONFIG_FILE}" + sed -i "s|dirname( __FILE__ ) . '/../../'|'${WP_CORE_DIR}/'|" "${CONFIG_FILE}" -log_section() { - echo - echo "========================================" - echo ">>> $1" - echo "========================================" + export WP_TESTS_DIR DB_HOST DB_NAME DB_USER DB_PASSWORD + WP_ENV_READY=1 } run_composer_install() { - log_section "Composer install" + log_section "Composer dependencies" if [ -f composer.json ]; then - # Skip if vendor/ already exists. - if [ -d vendor ]; then + if [ -n "${RAMSEY_VERSION}" ]; then + composer update ramsey/collection \ + --with "ramsey/collection:${RAMSEY_VERSION}" \ + --prefer-dist \ + --no-interaction + elif [ -d vendor ]; then echo "vendor/ already exists, skipping composer install" else composer install --no-interaction --prefer-dist @@ -118,10 +138,15 @@ run_phpunit() { run_wpunit() { log_section "WordPress Unit tests (php-wp-unit.xml)" + prepare_wp_tests vendor/bin/phpunit -c php-wp-unit.xml "$@" } -# Collect exit codes of both suites +run_phpcs() { + log_section "PHP CodeSniffer" + composer run phpcs +} + run_all_tests() { local phpunit_exit=0 local wpunit_exit=0 @@ -161,6 +186,12 @@ case "$CMD" in run_wpunit "$@" ;; + cs:phpcs|phpcs) + shift + run_composer_install + run_phpcs + ;; + composer-install) shift run_composer_install From 5f3191f4fee93be60de886efc674fbbc69f3e8c2 Mon Sep 17 00:00:00 2001 From: Igor Tron Date: Sun, 26 Apr 2026 10:36:31 +0400 Subject: [PATCH 4/5] Use Docker CI entrypoint for local checks --- README.md | 22 +++++++++++++--------- makefile | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1fe773f..17b7e2a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # WP Connections: post-to-post connections for WordPress -[![PHP CS](https://github.com/hokoo/wpConnections/actions/workflows/php-cs.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/phpunit.yml) -[![PHP WordPress Unit Tests](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests.yml) -[![Dockerfile Unit Tests](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests-docker.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests-docker.yml) +[![PHP CS](https://github.com/hokoo/wpConnections/actions/workflows/php-cs.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/php-cs.yml) +[![Unit Tests](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests-docker.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests-docker.yml) * [Why wpConnection?](#why-wpconnection) @@ -93,9 +92,9 @@ Since you have initialized new client, its REST API endpoints are available. 2. Make sure you have `make` installed in your system. If not, run `sudo apt install make`. 3. Make sure you have installed Docker Desktop with configured WSL2 support if you are using Windows. 4. Add `127.0.0.1 wpconnections.local` to the hosts file (on the host machine). -5. Run folowing command in the root directory to install the project: +5. Run the following command in the root directory to install the project: ```bash -bash ./local-dev/init.sh && make tests.init && make docker.up && make dev.install +bash ./local-dev/init.sh && make docker.up && make dev.install ``` ### Running the test suites @@ -106,11 +105,16 @@ The project ships with a dedicated `Dockerfile.phpunit` image that bundles Compo make tests.run ``` -Behind the scenes this calls `docker compose` with the `phpunit` service defined in `local-dev/docker-compose.yml`. The service no longer depends on any other containers—the entrypoint spins up MariaDB and configures the WordPress test library on demand—so these commands can be executed anywhere Docker is available. You can also run the individual commands manually, for example: +Behind the scenes this calls the `phpunit` service defined in `local-dev/docker-compose.yml` and uses the same entrypoint commands as GitHub Actions. The service no longer depends on any other containers: the entrypoint installs Composer dependencies when needed, spins up MariaDB only for WordPress unit tests, and configures the WordPress test library on demand. + +You can also run individual checks from the project root: ```bash -docker compose -f local-dev/docker-compose.yml run --rm phpunit composer run phpunit -docker compose -f local-dev/docker-compose.yml run --rm phpunit vendor/bin/phpunit -c php-wp-unit.xml +make tests.phpunit +make tests.wpunit +make lint.phpcs ``` -The same Dockerfile is also used by the optional GitHub Actions workflow defined in `.github/workflows/wp-unit-tests-docker.yml`, allowing you to compare its output against the long-standing `wp-unit-tests.yml` pipeline before switching over entirely. You can pin WordPress to a specific release by passing `--build-arg WP_VERSION=6.5.2` (or any other version number) when building the image. +`make tests.init` is only needed for direct, non-Docker WordPress PHPUnit runs that rely on a local `wordpress-develop` checkout. The default local and CI paths use `Dockerfile.phpunit`. + +The same Dockerfile is used by GitHub Actions workflows for unit tests and PHP code style checks. You can pin WordPress to a specific release by passing `--build-arg WP_VERSION=6.5.2` (or any other version number) when building the image. diff --git a/makefile b/makefile index c80e4c6..3ba000c 100644 --- a/makefile +++ b/makefile @@ -1,9 +1,19 @@ +.PHONY: tests.init tests.run tests.phpunit tests.wpunit dev.install docker.up docker.down docker.build.php php.connect php.log lint.phpcs lint.phpcs.fix + tests.init: cd ./local-dev/ && bash ./tests-init.sh tests.run: cd ./local-dev/ && \ - docker-compose -p wpconnections run --rm phpunit sh -c 'vendor/bin/phpunit -c phpunit.xml && vendor/bin/phpunit -c php-wp-unit.xml' + docker-compose -p wpconnections run --rm phpunit test:all + +tests.phpunit: + cd ./local-dev/ && \ + docker-compose -p wpconnections run --rm phpunit test:phpunit + +tests.wpunit: + cd ./local-dev/ && \ + docker-compose -p wpconnections run --rm phpunit test:wpunit dev.install: cd ./local-dev/ && \ @@ -31,7 +41,7 @@ php.log: lint.phpcs: cd ./local-dev/ && \ - docker-compose -p wpconnections exec php sh -c 'composer run phpcs' + docker-compose -p wpconnections run --rm phpunit cs:phpcs lint.phpcs.fix: cd ./local-dev/ && \ From d59a4f363c9e9835fc409f2f6921890b4515e203 Mon Sep 17 00:00:00 2001 From: Igor Tron Date: Sun, 26 Apr 2026 10:43:53 +0400 Subject: [PATCH 5/5] Split CI unit and integration checks --- .github/workflows/wp-integration-tests.yml | 38 ++++++++++++++++++++++ .github/workflows/wp-unit-tests-docker.yml | 6 ++-- README.md | 5 +-- docker/phpunit-entrypoint.sh | 12 +++---- makefile | 8 +++-- 5 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/wp-integration-tests.yml diff --git a/.github/workflows/wp-integration-tests.yml b/.github/workflows/wp-integration-tests.yml new file mode 100644 index 0000000..1824788 --- /dev/null +++ b/.github/workflows/wp-integration-tests.yml @@ -0,0 +1,38 @@ +name: WP Integration Tests + +on: + push: + branches: [ "master", "main", "dev" ] + pull_request: + types: [synchronize, opened, reopened] + +permissions: {} + +jobs: + wp-integration: + name: WP Integration Tests PHP ${{ matrix.php-version }} / Ramsey ${{ matrix.ramsey-version }} + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + php-version: [ 8.1, 8.2, 8.3, 8.4 ] + ramsey-version: [ "^1", "^2" ] + + steps: + - name: Check out the source code + uses: actions/checkout@v4 + + - name: Build CI image + run: | + docker build \ + --build-arg PHP_VERSION=${{ matrix.php-version }} \ + -t wpconnections-ci:${{ matrix.php-version }} \ + -f Dockerfile.phpunit . + + - name: Run WP integration tests + run: | + docker run --rm -v "$PWD:/srv/web" \ + -e RAMSEY_VERSION='${{ matrix.ramsey-version }}' \ + wpconnections-ci:${{ matrix.php-version }} \ + test:integration diff --git a/.github/workflows/wp-unit-tests-docker.yml b/.github/workflows/wp-unit-tests-docker.yml index a1fae5d..bda9bb9 100644 --- a/.github/workflows/wp-unit-tests-docker.yml +++ b/.github/workflows/wp-unit-tests-docker.yml @@ -10,7 +10,7 @@ permissions: {} jobs: phpunit: - name: PHP + WP Unit ${{ matrix.php-version }} / Ramsey ${{ matrix.ramsey-version }} + name: Unit Tests PHP ${{ matrix.php-version }} / Ramsey ${{ matrix.ramsey-version }} runs-on: ubuntu-latest strategy: @@ -30,9 +30,9 @@ jobs: -t wpconnections-ci:${{ matrix.php-version }} \ -f Dockerfile.phpunit . - - name: Run PHP and WordPress unit tests + - name: Run unit tests run: | docker run --rm -v "$PWD:/srv/web" \ -e RAMSEY_VERSION='${{ matrix.ramsey-version }}' \ wpconnections-ci:${{ matrix.php-version }} \ - test:all + test:phpunit diff --git a/README.md b/README.md index 17b7e2a..2121a1b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # WP Connections: post-to-post connections for WordPress [![PHP CS](https://github.com/hokoo/wpConnections/actions/workflows/php-cs.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/php-cs.yml) [![Unit Tests](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests-docker.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests-docker.yml) +[![WP Integration Tests](https://github.com/hokoo/wpConnections/actions/workflows/wp-integration-tests.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/wp-integration-tests.yml) * [Why wpConnection?](#why-wpconnection) @@ -105,13 +106,13 @@ The project ships with a dedicated `Dockerfile.phpunit` image that bundles Compo make tests.run ``` -Behind the scenes this calls the `phpunit` service defined in `local-dev/docker-compose.yml` and uses the same entrypoint commands as GitHub Actions. The service no longer depends on any other containers: the entrypoint installs Composer dependencies when needed, spins up MariaDB only for WordPress unit tests, and configures the WordPress test library on demand. +Behind the scenes this calls the `phpunit` service defined in `local-dev/docker-compose.yml` and aggregates the same entrypoint checks that GitHub Actions runs separately. The service no longer depends on any other containers: the entrypoint installs Composer dependencies when needed, spins up MariaDB only for WP integration tests, and configures the WordPress test library on demand. You can also run individual checks from the project root: ```bash make tests.phpunit -make tests.wpunit +make tests.integration make lint.phpcs ``` diff --git a/docker/phpunit-entrypoint.sh b/docker/phpunit-entrypoint.sh index a9ebd91..346694d 100755 --- a/docker/phpunit-entrypoint.sh +++ b/docker/phpunit-entrypoint.sh @@ -136,8 +136,8 @@ run_phpunit() { vendor/bin/phpunit -c phpunit.xml "$@" } -run_wpunit() { - log_section "WordPress Unit tests (php-wp-unit.xml)" +run_wp_integration() { + log_section "WP Integration tests (php-wp-unit.xml)" prepare_wp_tests vendor/bin/phpunit -c php-wp-unit.xml "$@" } @@ -154,13 +154,13 @@ run_all_tests() { run_composer_install run_phpunit "$@" || phpunit_exit=$? - run_wpunit "$@" || wpunit_exit=$? + run_wp_integration "$@" || wpunit_exit=$? if [ "$phpunit_exit" -ne 0 ] || [ "$wpunit_exit" -ne 0 ]; then echo echo "One or more test suites failed:" echo " PHP Unit exit code: $phpunit_exit" - echo " WP Unit exit code: $wpunit_exit" + echo " WP Integration exit code: $wpunit_exit" # If needed to distinguish, we could return, for example, the first non-zero exit 1 fi @@ -180,10 +180,10 @@ case "$CMD" in run_phpunit "$@" ;; - test:wpunit) + test:integration|test:wp-integration|test:wpunit) shift run_composer_install - run_wpunit "$@" + run_wp_integration "$@" ;; cs:phpcs|phpcs) diff --git a/makefile b/makefile index 3ba000c..2bc238b 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -.PHONY: tests.init tests.run tests.phpunit tests.wpunit dev.install docker.up docker.down docker.build.php php.connect php.log lint.phpcs lint.phpcs.fix +.PHONY: tests.init tests.run tests.phpunit tests.integration tests.wpunit dev.install docker.up docker.down docker.build.php php.connect php.log lint.phpcs lint.phpcs.fix tests.init: cd ./local-dev/ && bash ./tests-init.sh @@ -11,9 +11,11 @@ tests.phpunit: cd ./local-dev/ && \ docker-compose -p wpconnections run --rm phpunit test:phpunit -tests.wpunit: +tests.integration: cd ./local-dev/ && \ - docker-compose -p wpconnections run --rm phpunit test:wpunit + docker-compose -p wpconnections run --rm phpunit test:integration + +tests.wpunit: tests.integration dev.install: cd ./local-dev/ && \