Soluto by asurion
Published in

Soluto by asurion

How To Easily Testing WordPress Plugins With Docker

Testing WordPress Plugins With Docker

Using the Template

  • Clone the repo.
  • Copy all the source code of your plugin to the src folder.
  • Modify test/bootstrap.php: change to require your plugin instead of my plugin (Look for the TODO at line 21).
  • Start writing tests for your plugin! You can either modify the basic tests under tests/tests-plugin-security-scanner.php or delete this file and start from scratch. The whole wordpress test SDK is available for you.

Plugin Security Scanner

Current WordPress Testing Tools

Template File Structure

  • bootstrap.php: As the name implies, this file is taking care of bootstrapping – loading WordPress SDK so it will be available for your code and your tests code, and loading your plugin code so you could test it.
  • tests-plugin-sample.php: This file contains the actual tests for your plugin – feel free to rename it.

The Dockerfile

ARG PHP_IMAGE_TAG
FROM php:$PHP_IMAGE_TAG
ARG WORDPRESS_DB_PASSWORD
ARG WORDPRESS_VERSION
RUN echo "http://dl-3.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories &&\
apk add --update --no-cache subversion mysql mysql-client git bash g++ make autoconf && \
set -ex;&& \
docker-php-ext-install mysqli pdo pdo_mysql pcntl \
&& php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/bin --filename=composer
&& docker-php-source extract \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& docker-php-source delete \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_handler=dbgp" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& rm -rf /tmp/*
WORKDIR /tmp
COPY ./bin/install-wp-tests.sh /tmp/install-wp-tests.sh .
RUN /tmp/install-wp-tests.sh wordpress_test root $WORDPRESS_DB_PASSWORD mysql $WORDPRESS_VERSION
COPY ./db-error.php /tmp/wordpress/wp-content/db-error.php .
WORKDIR /wordpress
COPY composer.json /wordpress
RUN composer install
COPY . /wordpress
CMD bin/install-db.sh wordpress_test root $WORDPRESS_DB_PASSWORD mysql

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Omer Levi Hevroni

Software Developer and Security Champion at Soluto, Spouse and Father. Opinions and posts are mine only and does not represent Soluto #appsec #devops #devsecops