Vectorface / dunit

Test code against multiple versions of PHP with the help of docker
MIT License
248 stars 12 forks source link

DUnit

DUnit (dee-unit) makes your life easier by allowing you to test your PHP code against multiple Docker containers. This allows for testing your code against different versions of PHP or against different PHP configurations. By default, DUnit can perform a syntax check against your whole repository and run a PHPUnit test suite.

Default Containers

DUnit includes preconfigured containers for the following PHP versions:

and has the following native extensions installed:

Installation

Simply run the following composer command:

$ composer require vectorface/dunit --dev

It is highly recommended to copy the example config to your project root to control the default behaviour of the dunit command.

$ cp ./vendor/vectorface/dunit/dunitconfig.example ./.dunitconfig

And edit the file .dunitconfig to suit your tastes.

Usage

# run PHP syntax checks and your test suite against all supported version of PHP
$ ./vendor/bin/dunit

# show the help documentation
$ ./vendor/bin/dunit -h

# specify a custom configuration file
$ ./vendor/bin/dunit -c "path/.dunitconf"

# explictly specify which containers to use
$ ./vendor/bin/dunit -i "vectorface/php5.3 vectorface/php5.4"

Configuration

There are three ways to customize the dunit command:

Environment variables

The following environment variables can be set to configure dunit.

Examples:

Run dunit for versions 5.3 and 5.4 of PHP and skip the syntax check:

$ DUNIT_IMAGES="vectorface/php5.3 vectorface/php5.4" DUNIT_PHPSYNTAX=false ./vendor/bin/dunit

Local config file (.dunitconfig)

The dunit script will check for the presence of a local file named .dunitconfig. An example config file can be copied from the composer package:

$ cp ./vendor/vectorface/dunit/dunitconfig.example ./.dunitconfig

The environment variables specified by the config file will override any variables passed directly to the script.

Script flags

The dunit script can also take a number of flags. These flags will always override conflicting environment variable settings.

Examples:

Run dunit for versions 5.3 and 5.4 of PHP.

$ ./vendor/bin/dunit -i "vectorface/php5.3 vectorface/php5.4"

Run dunit with a custom config file.

$ ./vendor/bin/dunit -c ../dunit.global.conf

Upgrading from 1.x to 2.x

The .dunitconfig syntax has changed entirely from version 1 to version 2 so it is required that you copy the new config file in place.

$ cp ./vendor/vectorface/dunit/dunitconfig.example ./.dunitconfig

and adjust your config accordingly.

Also note that DUnit no longer supports the environment variables DUNIT_PHPVERSION and DUNIT_DOCKERIMAGE. These variables have been merged as the variable DUNIT_IMAGES.

Similarly, the flag -p has been replaced by -i.