How to use phpunit installed from composer? How to use phpunit installed from composer? symfony symfony

How to use phpunit installed from composer?


If you followed the documentation, you have set the phpunit/phpunit dependency as a 'dev-dependency'.

If you don't have composer, you need to install it first. This is explained in the documentation: Installation *nix or Installation Windows.If you already installed composer, it is a good practise to update composer to the latest version by running the self-update command:

$ php composer.phar self-update

After your have done that, you need to install all dependencies, including the dev dependencies. This is done by running the update command with the --dev switch:

$ php composer.phar update --dev

All the dependencies are installed in the vendor directory. PHPunit runs from the console. Composer automatic put the console files inside the vendor/bin directory. You need to execute the phpunit file in there:

$ vendor/bin/phpunit -c app/

The -c switch tells PHPUnit to look for the configuration file in the app directory, Symfony2 already set up the correct configuration to run all tests that are in the <bundle>/Tests directory.

UPDATE (05-04-2013)

Composer has changed their update/install commands. update will install dev dependencies by default and if you want to install dev dependencies, you need to use the --dev option.

UPDATE (11-06-2013)

Composer has changed their commands again, the install command will also install dev dependencies.


What about more composer way?

composer exec phpunit

It can be used for every binary file in vendor/bin directory.


UPDATE (12-02-2014)

Composer and PHPUnit have changed their commands again. The install command will also install dev dependencies:

Composer.json:

..."require-dev": {    "phpunit/phpunit": "3.7.*"},

Run it:

$ composer.phar update --prefer-dist --dev

Now you can run your tests by:

$ bin/phpunit -c /app

Cheers,