Example docker-compose.yml for mysql:
---
version: '3.9'
services:
# Integration Testing - Tests that run in phpunit with WordPress + MySQL
## Runner for phpunit
phpunit:
image: josh412/wp-phpunit
command:
- bash
## Wait to start until the database server for testing is ready.
depends_on:
- testwpdb
environment:
DATABASE_PASSWORD: examplepass
DATABASE_HOST: testwpdb
stdin_open: true
tty: true
volumes:
## Map this directory into the test plugin directory
- ./:/plugin
#Database for tests
testwpdb:
environment:
MYSQL_ROOT_PASSWORD: examplepass
image: mariadb:10.5.8
healthcheck:
test: "/usr/bin/mysql --user=wordpress --password=wordpress --execute \"SHOW DATABASES;\""
interval: 3s
timeout: 1s
retries: 5
Run docker-compose run phpunit
, wait for it to initialize completely, when prompt is displayed, run phpunit
or phpcs
(as appropriate).
You can set WordPress and PHP versions in two ways:
- Set
WORDPRESS_VERSION
and/ orPHP_IMAGE_TAG
environment variables. - Use a provided tag
You can see the full list of tags here. This is an example of using PHP 8.1 and WordPress 5.7:
---
version: '3.9'
services:
# Integration Testing - Tests that run in phpunit with WordPress + MySQL
## Runner for phpunit
phpunit:
image: josh412/wp-phpunit:php-8.1-wp-5.7
command:
- bash
## Wait to start until the database server for testing is ready.
depends_on:
- testwpdb
environment:
DATABASE_PASSWORD: examplepass
DATABASE_HOST: testwpdb
stdin_open: true
tty: true
volumes:
## Map this directory into the test plugin directory
- ./:/plugin
#Database for tests
testwpdb:
environment:
MYSQL_ROOT_PASSWORD: examplepass
image: mariadb:10.5.8
healthcheck:
test: "/usr/bin/mysql --user=wordpress --password=wordpress --execute \"SHOW DATABASES;\""
interval: 3s
timeout: 1s
retries: 5
Which version of WordPress to use. Must be a valid tag for WordPress image
Which version of PHP to use.
Database name to create for WordPress. (default: wordpress
)
Database user to connect from WordPress. (default: root
)
Database password to connect from WordPress.
Database host name to connect from WordPress. (default: database
)
Database port to connect from WordPress. (default: 3306
)
- Build
docker-compose -f docker-compose.test.yml build
- Test
docker-compose -f docker-compose.test.yml run phpunit
- Shows version numbers
Forked from yukihiko-shinoda/dockerfile-phpunit-wordpress-plugin.
View license information for the software contained in this image.
As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).
As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.