Skip to content
Draft
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
33 changes: 10 additions & 23 deletions .github/workflows/php-cs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: PHP Code Styles

env:
COMPOSER_VER: "2.7.9"
PHP_VER: "8.1"

on:
Expand All @@ -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
38 changes: 38 additions & 0 deletions .github/workflows/wp-integration-tests.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 8 additions & 7 deletions .github/workflows/wp-unit-tests-docker.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit Tests (Dockerfile)
name: Unit Tests

on:
push:
Expand All @@ -10,7 +10,7 @@ permissions: {}

jobs:
phpunit:
name: PHP Unit ${{ matrix.php-version }} / Ramsey ${{ matrix.ramsey-version }}
name: Unit Tests PHP ${{ matrix.php-version }} / Ramsey ${{ matrix.ramsey-version }}
runs-on: ubuntu-latest

strategy:
Expand All @@ -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 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:phpunit
120 changes: 0 additions & 120 deletions .github/workflows/wp-unit-tests.yml

This file was deleted.

10 changes: 3 additions & 7 deletions Dockerfile.phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand All @@ -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; \
Expand Down
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +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/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)
[![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)

<!-- TOC -->
* [Why wpConnection?](#why-wpconnection)
Expand Down Expand Up @@ -93,9 +93,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
Expand All @@ -106,11 +106,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 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
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.integration
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.
Loading
Loading