Skip to content

Commit

Permalink
Run tests via docker image
Browse files Browse the repository at this point in the history
Rather than needing to install PHP, all modules, imagemagick, and S3 APis locally, docker would be much metter suited to running out tests. This way we can run an S3 replacement (minio) instead of requiring a live integration with S3. This is better for performance and isolation of tests. It also means we have a clearly defined, consistent envirinment for tests for PHP configuration.
  • Loading branch information
joehoyle committed Apr 29, 2020
1 parent c89b5c6 commit 8055887
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 13 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
"require": {
"composer/installers": "~1.0",
"aws/aws-sdk-php": "~3.18"
}
},
"require-dev": {
"phpunit/phpunit": "7.5"
}
}
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
>
<testsuites>
<!-- Default test suite to run all tests -->
<testsuite>
<testsuite name="S3_Uploads">
<directory prefix="test-" suffix=".php">tests</directory>
</testsuite>
</testsuites>
Expand Down
16 changes: 5 additions & 11 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,18 @@
* @subpackage JSON API
*/

// Support for:
// 1. `WP_DEVELOP_DIR` environment variable
// 2. Plugin installed inside of WordPress.org developer checkout
// 3. Tests checked out to /tmp
if ( false !== getenv( 'WP_DEVELOP_DIR' ) ) {
$test_root = getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit';
} else if ( file_exists( '../../../../tests/phpunit/includes/bootstrap.php' ) ) {
$test_root = '../../../../tests/phpunit';
} else if ( file_exists( '/tmp/wordpress-tests-lib/includes/bootstrap.php' ) ) {
$test_root = '/tmp/wordpress-tests-lib';
}
$test_root = '/wordpress-testing-framework';

require $test_root . '/includes/functions.php';

function _manually_load_plugin() {
require dirname( __FILE__ ) . '/../s3-uploads.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
tests_add_filter( 's3_uploads_s3_client_params', function ( array $params ) : array {
$params['endpoint'] = 'http://172.17.0.2:9000';
return $params;
} );

if ( getenv( 'S3_UPLOADS_BUCKET' ) ) {
define( 'S3_UPLOADS_BUCKET', getenv( 'S3_UPLOADS_BUCKET' ) );
Expand Down
Binary file modified tests/data/gdpr.pdf
Binary file not shown.
54 changes: 54 additions & 0 deletions tests/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM alpine:3.11

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

RUN apk add minio minio-client --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing

ENV MINIO_ACCESS_KEY AWSACCESSKEY
ENV MINIO_SECRET_KEY AWSSECRETKEY

ENV S3_UPLOADS_KEY AWSACCESSKEY
ENV S3_UPLOADS_SECRET AWSSECRETKEY
ENV S3_UPLOADS_REGION us-east-1
ENV S3_UPLOADS_BUCKET tests

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

RUN mkdir /wordpress-testing-framework && cd /wordpress-testing-framework \
&& svn co --quiet https://develop.svn.wordpress.org/trunk/tests/phpunit/includes/ \
&& wget -nv -O wp-tests-config.php https://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php \
&& sed -i "s:dirname( __FILE__ ) . '/src/':'/wordpress/':" wp-tests-config.php \
&& sed -i "s/youremptytestdbnamehere/wordpress/" wp-tests-config.php \
&& sed -i "s/yourusernamehere/root/" wp-tests-config.php \
&& sed -i "s/yourpasswordhere//" wp-tests-config.php

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

RUN sh -c '/usr/bin/minio server /data &' && sleep 4 \
&& mcli config host add local http://172.17.0.2:9000 AWSACCESSKEY AWSSECRETKEY \
&& mcli mb local/tests \
&& mcli policy set public local/tests

ENV WP_DEVELOP_DIR=/wordpress-testing-framework/

VOLUME ["/code"]
WORKDIR /code
COPY ./docker-entrypoint.sh /entrypoint.sh
RUN chmod 755 /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
5 changes: 5 additions & 0 deletions tests/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
mysqld_safe --datadir=/var/lib/mysql &>/dev/null &
/usr/bin/minio server /data &>/dev/null &
sleep 1
/code/vendor/bin/phpunit "$@"

0 comments on commit 8055887

Please sign in to comment.