PHPUnit
In php world, the standard de facto framework to make unit tests is PHPUnit. PHPUnit is downloadable as phar archive or via composer. We'll show both manners. There are other frameworks. This is just
Install PHPUnit's phar
PHPUnit distribute a PHP Archive (phar). This archive contains everything a PHP Developer needs in order to use PHPUnit. Phar archive can be downloaded using wget command. First command download the phat. Second command make it executable and runnable as command like ./phpunit.phar
instead of php ./phpunit.phar
. Third command make it a system command. This means that phpunit is runnable from everywhere in this machine.
wget -O phpunit https://phar.phpunit.de/phpunit-7.phar
chmod +x phpunit
mv phpunit.phar /usr/local/bin/phpunit
Install with Composer
Install phpunit with composer is very very simple. The following example is a phpunit installation inside a symfony4 project. Notice that in symfony4 uses flex to install libraries.
composer require phpunit
Run phpunit
Depending on your composer.json
configuration, it is possibile to run phpunit with
php vendor/bin/phpunit
I suggest a little improvement in composer configuration. This little improvement keep all binaries
in bin folder. There is a command that make it simple:
composer config bin-dir bin
From now you can run phpunit with shorten command.
./bin/phpunit
This is expected output after running the command
As you can see there are no tests here and "No tests executed!" appears.