├── .github └── workflows │ └── image.yml ├── Dockerfile ├── README.md ├── docker-entrypoint.sh └── wp-tests-config.php /.github/workflows/image.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'master' 7 | 8 | jobs: 9 | docker: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - 13 | name: Checkout 14 | uses: actions/checkout@v2 15 | - 16 | name: Set up QEMU 17 | uses: docker/setup-qemu-action@v1 18 | - 19 | name: Set up Docker Buildx 20 | uses: docker/setup-buildx-action@v1 21 | - 22 | name: Login to DockerHub 23 | uses: docker/login-action@v1 24 | with: 25 | username: ${{ secrets.DOCKERHUB_USERNAME }} 26 | password: ${{ secrets.DOCKERHUB_TOKEN }} 27 | - 28 | name: Build and push latest 29 | uses: docker/build-push-action@v2 30 | with: 31 | context: . 32 | platforms: linux/amd64,linux/arm64 33 | push: true 34 | tags: humanmade/plugin-tester:latest 35 | - 36 | name: Build and push 5.4 37 | uses: docker/build-push-action@v2 38 | with: 39 | context: . 40 | build-args: | 41 | WP_VERSION=5.4 42 | platforms: linux/amd64,linux/arm64 43 | push: true 44 | tags: humanmade/plugin-tester:wp-5.4 45 | - 46 | name: Build and push 5.5 47 | uses: docker/build-push-action@v2 48 | with: 49 | context: . 50 | build-args: | 51 | WP_VERSION=5.5 52 | platforms: linux/amd64,linux/arm64 53 | push: true 54 | tags: humanmade/plugin-tester:wp-5.5 55 | - 56 | name: Build and push 5.6 57 | uses: docker/build-push-action@v2 58 | with: 59 | context: . 60 | build-args: | 61 | WP_VERSION=5.6 62 | platforms: linux/amd64,linux/arm64 63 | push: true 64 | tags: humanmade/plugin-tester:wp-5.6 65 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.13 2 | 3 | ARG WP_VERSION=5.4 4 | 5 | RUN apk add -u --no-cache \ 6 | composer \ 7 | git \ 8 | imagemagick \ 9 | mysql \ 10 | mysql-client \ 11 | php7 \ 12 | php7-curl \ 13 | php7-dom \ 14 | php7-exif \ 15 | php7-mysqli \ 16 | php7-pecl-imagick \ 17 | php7-simplexml \ 18 | php7-tokenizer \ 19 | php7-xml \ 20 | php7-xmlwriter 21 | 22 | RUN apk add --no-cache php7-pear php7-dev gcc musl-dev make \ 23 | && pecl install pcov && echo extension=pcov.so > /etc/php7/conf.d/pcov.ini \ 24 | && apk del php7-pear php7-dev gcc musl-dev make 25 | 26 | RUN wget -nv -O /tmp/wordpress.tar.gz https://wordpress.org/wordpress-${WP_VERSION}.tar.gz \ 27 | && mkdir /wordpress \ 28 | && tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C /wordpress \ 29 | && rm /tmp/wordpress.tar.gz 30 | 31 | RUN wget -nv -O /tmp/wp-phpunit.tar.gz https://github.com/wp-phpunit/wp-phpunit/archive/${WP_VERSION}.0.tar.gz \ 32 | && mkdir /wp-phpunit \ 33 | && tar --strip-components=1 -zxmf /tmp/wp-phpunit.tar.gz -C /wp-phpunit \ 34 | && rm /tmp/wp-phpunit.tar.gz 35 | 36 | RUN mysql_install_db --user=mysql --ldata=/var/lib/mysql 37 | RUN sh -c 'mysqld_safe --datadir=/var/lib/mysql &' && sleep 4 && mysql -u root -e "CREATE DATABASE wordpress" 38 | 39 | ENV WP_DEVELOP_DIR=/wp-phpunit 40 | ENV WP_PHPUNIT__TESTS_CONFIG=/wp-tests-config.php 41 | 42 | VOLUME ["/code"] 43 | WORKDIR /code 44 | COPY ./docker-entrypoint.sh /entrypoint.sh 45 | COPY ./wp-tests-config.php /wp-tests-config.php 46 | RUN chmod 755 /entrypoint.sh 47 | ENTRYPOINT ["/entrypoint.sh"] 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # humanmade/plugin-tester 2 | 3 | [![Docker Pulls](https://img.shields.io/docker/pulls/humanmade/plugin-tester)](https://hub.docker.com/repository/docker/humanmade/plugin-tester) [![Docker Image Size (latest by date)](https://img.shields.io/docker/image-size/humanmade/plugin-tester)](https://hub.docker.com/repository/docker/humanmade/plugin-tester) 4 | 5 | Simple Docker image for running unit tests for WordPress plugins. 6 | 7 | To run the tests for your plugin, run this in your plugin directory: 8 | 9 | ```sh 10 | docker run --rm -v "$PWD:/code" humanmade/plugin-tester 11 | ``` 12 | 13 | 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.: 14 | 15 | ```sh 16 | docker run --rm -v "$PWD:/code" humanmade/plugin-tester --stop-on-error 17 | ``` 18 | 19 | ## Configuration 20 | 21 | To configure PHPUnit, place a `phpunit.xml.dist` in the plugin root. You can alternatively use the command line arguments for PHPUnit for simpler tests. 22 | 23 | Typically your `tests` directory in your plugin should include a `bootstrap.php` including at least the following: 24 | 25 | ```php 26 | /dev/null & 3 | 4 | retries=5 5 | status=1 6 | until [ $status -eq 0 ] || [ $retries -le 0 ]; do 7 | mysql -uroot 2>/dev/null 8 | status=$? 9 | retries=$((retries-1)) 10 | sleep 1 11 | done 12 | 13 | # Run https://github.com/krakjoe/pcov-clobber if installed. 14 | if [ -f /code/vendor/bin/pcov ]; then /code/vendor/bin/pcov clobber; fi 15 | 16 | /code/vendor/bin/phpunit "$@" 17 | -------------------------------------------------------------------------------- /wp-tests-config.php: -------------------------------------------------------------------------------- 1 |