Giter Club home page Giter Club logo

dunit's Introduction

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:

  • PHP 5.2 (add vectorface/php5.2 to your .dunitconfig)
  • PHP 5.3
  • PHP 5.4
  • PHP 5.5
  • PHP 5.6
  • PHP 7.0-dev (add vectorface/php-nightly to your dunitconfig)
  • HHVM stable
  • HHVM nightly (add vectorface/hhvm-nightly to your .dunitconfig)

and has the following native extensions installed:

  • apc (apcu on PHP 5.5 and newer)
  • curl
  • gd
  • intl (PHP 5.3 and newer)
  • json
  • mcrypt

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
  • Local config file
  • Script flags.

Environment variables

The following environment variables can be set to configure dunit.

  • DUNIT_IMAGES - a string like "vectorface/php5.3 vectorface/php5.4" which indicates the list of images to run against.
  • DUNIT_PHPSYNTAX - a true/false flag indicating whether dunit should run the syntax checks.
  • DUNIT_PHPSYNTAXCOMMAND - a string indicating the exact command dunit should run to perform the syntax checks. This variable is ignored if DUNIT_PHPSYNTAX is set to false. Note that the command runs inside the Docker container and not on your host machine.
  • DUNIT_PHPUNIT - a true/false flag indicating whether dunit should run PHPUnit.
  • DUNIT_PHPUNITCOMMAND - a string indicating the exact command dunit should execute for the unit test suite. This variable is ignored if DUNIT_PHPUNIT is set to false. Note that the command runs inside the Docker container and not on your host machine.

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.

  • -h - displays help information.
  • -c ./path/to/config - dunit will use the config located at the provided path instead of looking in your local folder for .dunitconfig.
  • -i "image1 image2" - dunit will only run against the specified images.
  • --version - displays the current version.
  • -p - pulls the latest version of all the docker images

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.

dunit's People

Contributors

ckdarby avatar danbruce avatar jdpanderson avatar vimishor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dunit's Issues

Custom install instructions

One of my projects requires ext-gd to run tests for. But the docker file doesn't take that into account. It would be great if we can provide custom install instructions for when the docker container is build. For other projects even more custom instructions are required.

How to add PHP extensions to docker images?

I've noticed that the Dockerfile for 5.4 (and probably others) accepts a build parameter of $PHP_EXTRA_BUILD_DEPS.

How can I tweak and pass this variable into the Dockerfile when pulling the images through dUnit?

For example, something along the lines of:
PHP_EXTRA_BUILD_DEPS='pdo pdo_mysql' ./vendor/bin/dunit -i -p

Warnings with config file

Hi,

I copy paste the content of the default configfile in .dunitconfig. The command ./vendor/bin/dunit outputs:

WARNING: Config file could not be read. Falling back to built-in defaults

Full output:

PHP Deprecated:  Comments starting with '#' are deprecated in /home/data/www/jeff/misc/halstead/.dunitconfig on line 1 in phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php on line 267
PHP Stack trace:
PHP   1. {main}() /home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit:0
PHP   2. require() /home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit:10
PHP   3. Symfony\Component\Console\Application->run() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/dunit.php:7
PHP   4. Symfony\Component\Console\Application->doRun() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Application.php:126
PHP   5. Symfony\Component\Console\Application->doRunCommand() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Application.php:195
PHP   6. Symfony\Component\Console\Command\Command->run() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Application.php:874
PHP   7. Vectorface\Dunit\DunitCommand->execute() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:252
PHP   8. Vectorface\Dunit\DunitCommand->getCurrentOptions() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php:136
PHP   9. Vectorface\Dunit\DunitCommand->mergeConfigFileIntoOptions() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php:180
PHP  10. parse_ini_file() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php:267

Deprecated: Comments starting with '#' are deprecated in /home/data/www/jeff/misc/halstead/.dunitconfig on line 1 in phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php on line 267

Call Stack:
    0.0001     228880   1. {main}() /home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit:0
    0.0030     355480   2. require('phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/dunit.php') /home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit:10
    0.0121    1777552   3. Symfony\Component\Console\Application->run() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/dunit.php:7
    0.0143    2113536   4. Symfony\Component\Console\Application->doRun() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Application.php:126
    0.0143    2114256   5. Symfony\Component\Console\Application->doRunCommand() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Application.php:195
    0.0143    2114800   6. Symfony\Component\Console\Command\Command->run() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Application.php:874
    0.0145    2117440   7. Vectorface\Dunit\DunitCommand->execute() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:252
    0.0145    2117704   8. Vectorface\Dunit\DunitCommand->getCurrentOptions() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php:136
    0.0146    2120392   9. Vectorface\Dunit\DunitCommand->mergeConfigFileIntoOptions() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php:180
    0.0146    2120632  10. parse_ini_file() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php:267

PHP Warning:  syntax error, unexpected BOOL_TRUE in /home/data/www/jeff/misc/halstead/.dunitconfig on line 7
 in phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php on line 267
PHP Stack trace:
PHP   1. {main}() /home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit:0
PHP   2. require() /home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit:10
PHP   3. Symfony\Component\Console\Application->run() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/dunit.php:7
PHP   4. Symfony\Component\Console\Application->doRun() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Application.php:126
PHP   5. Symfony\Component\Console\Application->doRunCommand() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Application.php:195
PHP   6. Symfony\Component\Console\Command\Command->run() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Application.php:874
PHP   7. Vectorface\Dunit\DunitCommand->execute() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:252
PHP   8. Vectorface\Dunit\DunitCommand->getCurrentOptions() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php:136
PHP   9. Vectorface\Dunit\DunitCommand->mergeConfigFileIntoOptions() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php:180
PHP  10. parse_ini_file() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php:267

Warning: syntax error, unexpected BOOL_TRUE in /home/data/www/jeff/misc/halstead/.dunitconfig on line 7
 in phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php on line 267

Call Stack:
    0.0001     228880   1. {main}() /home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit:0
    0.0030     355480   2. require('phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/dunit.php') /home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit:10
    0.0121    1777552   3. Symfony\Component\Console\Application->run() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/dunit.php:7
    0.0143    2113536   4. Symfony\Component\Console\Application->doRun() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Application.php:126
    0.0143    2114256   5. Symfony\Component\Console\Application->doRunCommand() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Application.php:195
    0.0143    2114800   6. Symfony\Component\Console\Command\Command->run() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Application.php:874
    0.0145    2117440   7. Vectorface\Dunit\DunitCommand->execute() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:252
    0.0145    2117704   8. Vectorface\Dunit\DunitCommand->getCurrentOptions() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php:136
    0.0146    2120392   9. Vectorface\Dunit\DunitCommand->mergeConfigFileIntoOptions() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php:180
    0.0146    2120632  10. parse_ini_file() phar:///home/data/www/jeff/misc/halstead/vendor/vectorface/dunit/bin/dunit/src/DunitCommand.php:267

WARNING: Config file could not be read. Falling back to built-in defaults.

My environment:

PHP 5.4.6-1ubuntu1.8 (cli) (built: Apr  4 2014 01:28:36) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans

Since PHP 5.3, # and simplde quotes are deprecated : documentation of parse_ini_file

CLI arguments should supersede config

Currently if you have a .dunitconfig with DUNIT_PHPVERSION="5.3 5.4" and you run ./vendor/bin/dunit -p "5.3" the config will "win" and PHP 5.3 & PHP 5.4 will be used. I would expect to win the CLI argument(s).

Proposal: Read config if there is one and overwrite parameters when there are specified from CLI.

Dunit needs an --update flag.

As per the subject, it would be nice to run:

./vendor/bin/dunit --update

in order to update existing docker images (in particular the nightly HHVM and future nightly PHP images).

PHPUnit via composer not running in PHP 5.2

Hello, first of all, thanks for this awesome project!

Unfortunately, I'm having a problem with a project:

root@fc2202c5aeef:/# php -d error_reporting=-1 /opt/source/vendor/bin/phpunit

Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /opt/source/vendor/phpunit/phpunit/composer/bin/phpunit on line 41

Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /opt/source/vendor/phpunit/phpunit/composer/bin/phpunit on line 42
You need to set up the project dependencies using the following commands:
curl -s http://getcomposer.org/installer | php
php composer.phar install

I trying to find a way to install phpunit in PHP 5.2, found some clues (I hope this can help):

Anyway, thanks again!

Dunit can't find phpunit

When I try to run e.g. ./vendor/bin/dunit -i "vectorface/php5.4" or just ./vendor/bin/dunit, I get:

/bin/bash: /opt/source/vendor/bin/phpunit: No such file or directory

Maybe I missed some setup? but I assume that path is referring to the docker image provided by dunit, so I don't understand what's gone wrong. I'm using boot2docker on OSX

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.