PHPUnit: local VS global install

Viewed 2740

Installing PHPUnit with composer globally seems more convenient to me for those two reasons: 1. Using it everywhere without needing an extra install. 2. Just running phpunitinstead of vendor/bin/phpunit (using an alias might solve this)

Are there any reasons why a local install might be the better choice? For example: using the exact same versions every time. (don't have a lot of experience with PHPUnit, so not sure if this really is an issue or not)

2 Answers

The big disadvantage of installing packages globally is that you might end up with different versions of PHPUnit between developers in your team (unless you are the only developer). This might cause some side effects.

If you install it locally using composer.json, then every developer in your team will have exactly the same version as you do for that specific application. Also, everybody will see when you change the version in composer.json.

If you don't like typing vendor/bin/phpunit, you can use Makefile (which is also in your project):

test:
    vendor/bin/phpunit --configuration=test/Unit/phpunit.xml

then run it ...

make test

I like to install it via composer and the require-dev block, but another way that does come highly recommended is to download the phpunit.phar into the project, to use that.

Either way, you control exactly which version is being used (and when it's updated) - which is the most important part, as you can't so easily control what people have installed globally.

Related