Add WooCommerce version selection to Docker PHP test suite (https://github.com/woocommerce/woocommerce-admin/pull/6119)

* Add WooCommerce version selection

The WC_VERSION environment variable is added to the docker-compose config. If the variable is not set on the shell, it defaults to the minimum supported version (4.5.0)

The ENTRYPOINT is changed to automatically re-install the test suite when the version number is changed.

* Add documentation

* Add versioning to force image rebuild
This commit is contained in:
Adrian Duffell 2021-02-01 12:26:27 +08:00 committed by GitHub
parent 242bdb475d
commit d94a9551d2
3 changed files with 40 additions and 3 deletions

View File

@ -3,11 +3,13 @@ version: "3"
services:
phpunit:
build: "."
image: wc-admin-php-test-suite-phpunit:1.1.0
volumes:
- "test-suite:/tmp"
- "../../:/app"
environment:
- WC_CORE_DIR=/tmp/wordpress/wp-content/plugins/woocommerce
- WC_VERSION=${WC_VERSION:-4.5.0}
- DB_USER=root
- DB_PASS=password
- DB_NAME=wordpress_test

View File

@ -5,12 +5,35 @@ until mysqladmin ping -h"$DB_HOST" --silent; do
>&2 echo "MySQL is unavailable - sleeping"
sleep 2
done
>&2 echo "MySQL is up - executing tests"
# Function to install the test suite.
function install {
# Delete previous state.
rm -f /tmp/.INSTALLED_WC_VERSION
# Run the install script.
bin/install-wp-tests.sh $DB_NAME $DB_USER $DB_PASS $DB_HOST latest true
# Remember the installed WooCommerce version.
echo "$WC_VERSION" > /tmp/.INSTALLED_WC_VERSION
}
# Run the install script if the installed WooCommerce version is unknown.
if [ ! -f /tmp/.INSTALLED_WC_VERSION ]; then
install
else
# Run the install script if the WooCommerce version has changed.
INSTALLED_WC_VERSION=`cat /tmp/.INSTALLED_WC_VERSION`
if [ "$WC_VERSION" != "$INSTALLED_WC_VERSION" ]; then
install
fi
fi
# Run the install script if the WordPress directory is not found.
if [ ! -d /tmp/wordpress-tests-lib ]; then
bin/install-wp-tests.sh $DB_NAME $DB_USER $DB_PASS $DB_HOST latest true
install
fi
exec phpunit "$@"

View File

@ -15,7 +15,7 @@ This runs the the `phpunit` container with `docker-compose -f run --rm phpunit`.
## Re-install Test Suite
Re-installation is useful to update WordPress and WooCommerce to the latest versions. To do this, remove the existing `test-suite` volume using Docker. For example:
Re-installation is useful to update WordPress to the latest version. To do this, remove the existing `test-suite` volume using Docker. For example:
```shell
docker volume rm -f wc-admin-php-test-suite_test-suite
@ -30,3 +30,15 @@ PHPUnit flags can be passed to the npm script. To limit testing to a single test
```shell
npm run test:php -- --filter=<name of test>
```
## Selecting the WooCommerce Version
By default, the minimum supported version of WooCommerce is used to build the test suite. This can be overridden with an environment variable.
```shell
WC_VERSION=4.9.0 npm run test:php
```
## Development
When comitting changes to the `Dockerfile` or `entrypoint.sh` files, bump the `wc-admin-php-test-suite-phpunit` image tag version in `docker-composer.xml`. This will result in an image rebuild automatically upon next use, enabling the changes to be applied for all users.