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
38 changes: 8 additions & 30 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,12 @@ on:
pull_request:

jobs:
docker-latest:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push latest
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.ref == 'refs/heads/master' }}
tags: humanmade/plugin-tester:latest

docker-matrix:
runs-on: ubuntu-latest
strategy:
matrix:
wp_version: ['5.4', '5.5', '5.6', '5.7', '5.8', '5.9', '6.0', '6.1', '6.2', '6.3', '6.4', '6.5', '6.6', '6.7', '6.8']
wp_version: ['6.0', '6.1', '6.2', '6.3', '6.4', '6.5', '6.6', '6.7', '6.8']
php_version: ['8.0', '8.1', '8.2', '8.3']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about PHP 8.4?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thikn we can add in a follow up, wp is still 8.4 beta support I beleive

steps:
-
name: Checkout
Expand All @@ -56,13 +30,17 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push ${{ matrix.wp_version }}
name: Build and push WP ${{ matrix.wp_version }} PHP ${{ matrix.php_version }}
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile.php${{ matrix.php_version }}
build-args: |
WP_VERSION=${{ matrix.wp_version }}
platforms: linux/amd64,linux/arm64
push: ${{ github.ref == 'refs/heads/master' }}
tags: humanmade/plugin-tester:wp-${{ matrix.wp_version }}
tags: |
humanmade/plugin-tester:wp-${{ matrix.wp_version }}-php${{ matrix.php_version }}
${{ matrix.php_version == '8.0' && format('humanmade/plugin-tester:wp-{0}', matrix.wp_version) || '' }}
${{ matrix.php_version == '8.0' && matrix.wp_version == '6.8' && 'humanmade/plugin-tester:latest' || '' }}

37 changes: 20 additions & 17 deletions Dockerfile → Dockerfile.php8.0
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
FROM alpine:3.14

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot the "main" docker file can be deleted, let's jsut have one per PHP version

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the main Dockerfile as requested. Now using only PHP-specific Dockerfiles (Dockerfile.php8.0, Dockerfile.php8.1, Dockerfile.php8.2, Dockerfile.php8.3). The latest tag build uses Dockerfile.php8.3 with WordPress 6.8. Commit 51313b9

FROM public.ecr.aws/docker/library/alpine:3.16

ARG WP_VERSION=6.8
ARG WP_VERSION

RUN apk add -u --no-cache \
composer \
git \
imagemagick \
mysql \
mysql-client \
php7 \
php7-curl \
php7-dom \
php7-exif \
php7-mysqli \
php7-pecl-imagick \
php7-simplexml \
php7-tokenizer \
php7-xml \
php7-xmlwriter

RUN apk add --no-cache php7-pear php7-dev gcc musl-dev make \
&& pecl install pcov && echo extension=pcov.so > /etc/php7/conf.d/pcov.ini \
&& apk del php7-pear php7-dev gcc musl-dev make
php8 \
php8-curl \
php8-dom \
php8-exif \
php8-mysqli \
php8-pecl-imagick \
php8-simplexml \
php8-tokenizer \
php8-xml \
php8-xmlwriter

RUN apk add --no-cache php8-pear php8-dev gcc musl-dev make \
&& pecl8 install pcov && echo extension=pcov.so > /etc/php8/conf.d/pcov.ini \
&& apk del php8-pear php8-dev gcc musl-dev make

# Create php symlink to php8
RUN ln -sf /usr/bin/php8 /usr/bin/php

RUN wget -nv -O /tmp/wordpress.tar.gz https://wordpress.org/wordpress-${WP_VERSION}.tar.gz \
&& mkdir /wordpress \
Expand All @@ -44,4 +47,4 @@ WORKDIR /code
COPY ./docker-entrypoint.sh /entrypoint.sh
COPY ./wp-tests-config.php /wp-tests-config.php
RUN chmod 755 /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]
50 changes: 50 additions & 0 deletions Dockerfile.php8.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM public.ecr.aws/docker/library/alpine:3.19

ARG WP_VERSION

RUN apk add -u --no-cache \
composer \
git \
imagemagick \
mysql \
mysql-client \
php81 \
php81-curl \
php81-dom \
php81-exif \
php81-mysqli \
php81-pecl-imagick \
php81-simplexml \
php81-tokenizer \
php81-xml \
php81-xmlwriter

RUN apk add --no-cache php81-pear php81-dev gcc musl-dev make \
&& pecl81 install pcov && echo extension=pcov.so > /etc/php81/conf.d/pcov.ini \
&& apk del php81-pear php81-dev gcc musl-dev make

# Create php symlink to php81
RUN ln -sf /usr/bin/php81 /usr/bin/php

RUN wget -nv -O /tmp/wordpress.tar.gz https://wordpress.org/wordpress-${WP_VERSION}.tar.gz \
&& mkdir /wordpress \
&& tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C /wordpress \
&& rm /tmp/wordpress.tar.gz

RUN wget -nv -O /tmp/wp-phpunit.tar.gz https://github.com/wp-phpunit/wp-phpunit/archive/${WP_VERSION}.0.tar.gz \
&& mkdir /wp-phpunit \
&& tar --strip-components=1 -zxmf /tmp/wp-phpunit.tar.gz -C /wp-phpunit \
&& rm /tmp/wp-phpunit.tar.gz

RUN mysql_install_db --user=mysql --ldata=/var/lib/mysql
RUN sh -c 'mysqld_safe --datadir=/var/lib/mysql &' && sleep 4 && mysql -u root -e "CREATE DATABASE wordpress"

ENV WP_DEVELOP_DIR=/wp-phpunit
ENV WP_PHPUNIT__TESTS_CONFIG=/wp-tests-config.php

VOLUME ["/code"]
WORKDIR /code
COPY ./docker-entrypoint.sh /entrypoint.sh
COPY ./wp-tests-config.php /wp-tests-config.php
RUN chmod 755 /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
50 changes: 50 additions & 0 deletions Dockerfile.php8.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM public.ecr.aws/docker/library/alpine:3.19

ARG WP_VERSION

RUN apk add -u --no-cache \
composer \
git \
imagemagick \
mysql \
mysql-client \
php82 \
php82-curl \
php82-dom \
php82-exif \
php82-mysqli \
php82-pecl-imagick \
php82-simplexml \
php82-tokenizer \
php82-xml \
php82-xmlwriter

RUN apk add --no-cache php82-pear php82-dev gcc musl-dev make \
&& pecl82 install pcov && echo extension=pcov.so > /etc/php82/conf.d/pcov.ini \
&& apk del php82-pear php82-dev gcc musl-dev make

# Create php symlink to php82
RUN ln -sf /usr/bin/php82 /usr/bin/php

RUN wget -nv -O /tmp/wordpress.tar.gz https://wordpress.org/wordpress-${WP_VERSION}.tar.gz \
&& mkdir /wordpress \
&& tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C /wordpress \
&& rm /tmp/wordpress.tar.gz

RUN wget -nv -O /tmp/wp-phpunit.tar.gz https://github.com/wp-phpunit/wp-phpunit/archive/${WP_VERSION}.0.tar.gz \
&& mkdir /wp-phpunit \
&& tar --strip-components=1 -zxmf /tmp/wp-phpunit.tar.gz -C /wp-phpunit \
&& rm /tmp/wp-phpunit.tar.gz

RUN mysql_install_db --user=mysql --ldata=/var/lib/mysql
RUN sh -c 'mysqld_safe --datadir=/var/lib/mysql &' && sleep 4 && mysql -u root -e "CREATE DATABASE wordpress"

ENV WP_DEVELOP_DIR=/wp-phpunit
ENV WP_PHPUNIT__TESTS_CONFIG=/wp-tests-config.php

VOLUME ["/code"]
WORKDIR /code
COPY ./docker-entrypoint.sh /entrypoint.sh
COPY ./wp-tests-config.php /wp-tests-config.php
RUN chmod 755 /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
50 changes: 50 additions & 0 deletions Dockerfile.php8.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM public.ecr.aws/docker/library/alpine:3.19

ARG WP_VERSION

RUN apk add -u --no-cache \
composer \
git \
imagemagick \
mysql \
mysql-client \
php83 \
php83-curl \
php83-dom \
php83-exif \
php83-mysqli \
php83-pecl-imagick \
php83-simplexml \
php83-tokenizer \
php83-xml \
php83-xmlwriter

RUN apk add --no-cache php83-pear php83-dev gcc musl-dev make \
&& pecl83 install pcov && echo extension=pcov.so > /etc/php83/conf.d/pcov.ini \
&& apk del php83-pear php83-dev gcc musl-dev make

# Create php symlink to php83
RUN ln -sf /usr/bin/php83 /usr/bin/php

RUN wget -nv -O /tmp/wordpress.tar.gz https://wordpress.org/wordpress-${WP_VERSION}.tar.gz \
&& mkdir /wordpress \
&& tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C /wordpress \
&& rm /tmp/wordpress.tar.gz

RUN wget -nv -O /tmp/wp-phpunit.tar.gz https://github.com/wp-phpunit/wp-phpunit/archive/${WP_VERSION}.0.tar.gz \
&& mkdir /wp-phpunit \
&& tar --strip-components=1 -zxmf /tmp/wp-phpunit.tar.gz -C /wp-phpunit \
&& rm /tmp/wp-phpunit.tar.gz

RUN mysql_install_db --user=mysql --ldata=/var/lib/mysql
RUN sh -c 'mysqld_safe --datadir=/var/lib/mysql &' && sleep 4 && mysql -u root -e "CREATE DATABASE wordpress"

ENV WP_DEVELOP_DIR=/wp-phpunit
ENV WP_PHPUNIT__TESTS_CONFIG=/wp-tests-config.php

VOLUME ["/code"]
WORKDIR /code
COPY ./docker-entrypoint.sh /entrypoint.sh
COPY ./wp-tests-config.php /wp-tests-config.php
RUN chmod 755 /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,28 @@

Simple Docker image for running unit tests for WordPress plugins.

**Supports multiple PHP versions:** 8.0, 8.1, 8.2, 8.3

To run the tests for your plugin, run this in your plugin directory:

```sh
docker run --rm -v "$PWD:/code" humanmade/plugin-tester
```

You can also specify a specific WordPress and PHP version combination:

```sh
docker run --rm -v "$PWD:/code" humanmade/plugin-tester:wp-6.8-php8.3
```

Available tags follow the pattern `wp-{version}-php{version}`, e.g.:
- `humanmade/plugin-tester:wp-6.8-php8.3`
- `humanmade/plugin-tester:wp-6.7-php8.2`
- `humanmade/plugin-tester:wp-6.6-php8.1`
- etc.

The `latest` tag uses the newest WordPress version with PHP 8.3.

You will need `phpunit/phpunit` specified as a Composer dependency of your plugin. Additional arguments can be passed to PHPUnit on the CLI directly, e.g.:

```sh
Expand Down
Loading