0

I am developing a PHP website. I have a version on my laptop where I develop everything and my web server which runs the site.

I have found that I can use composer to install PHPUnit only on my laptop and not on my web server using the "require-dev" option Using "require-dev" to install packages in composer

However, this comes with some downsides:

  1. From now on I have to call php composer update --no-dev on the webserver, and if I forget --no-dev then its also installed on the web server

  2. I have to use $ ./vendor/bin/phpunit to call phpunit

  3. I have to do install phpunit for each project on my laptop.

Would't it be much better to just install phpunit on Ubuntu sudo apt-get install phpunit? This way I would not have to worry about using the --no-dev option on the server and I could simply call it by $ phpunit. Am I missing anything important here?

Adam
  • 25,960
  • 22
  • 158
  • 247
  • Do not run `composer update` on a production environment. You probably want to install the dependencies, not update them. Run `composer install --no-dev`. – localheinz Jun 24 '17 at 08:38

2 Answers2

0

Fast answer is:

  1. You can have a version of phppunit you want in your project and another in another. And --no-dev should be used in production anyway, because you don't want to install all the dev dependencies in Production
  2. if you don't want to call ./vendor/bin/phpunit add a script to your composer.json and then run the tests by composer test or anything you create
  3. Explained in the first one. It really makes sense, especially when you work with some legacy code that works only with some particular versions of php/phpunit etc.
Mat
  • 2,378
  • 3
  • 26
  • 35
0

I usually install phpunit, and other tools in the 'require-dev' section, but another entirely reasonable option is to download the phpunit.phar file from the website, and check it in with the rest of your code - updating it manually occasionally.

A local (or global) Composer install will allow for better control of exactly which version is available though, and you can see when it, or your other dependencies are out of date with composer outdated.

As for a production deployment, you should be automating it as much as possible, to make sure that exactly the same thing happens every time. With that, it's just another few characters in your deployment script or other mechanism.

Alister Bulman
  • 34,482
  • 9
  • 71
  • 110