In this article we will see how to setup PHPUnit for a PHP project. There are two methods by which we can use PHPUnit in a project.
Method1 : With PHAR file
1. Download PHAR file for the latest version of PHPUnit at https://phar.phpunit.de/phpunit-7.0.phar
2. Rename the downloaded PHPUnit phar file
$mv phpunit-7.0.phar phpunit
3. Copy the downloaded PHPUnit phar file to the directory /usr/local/bin
$sudo cp phpunit /usr/local/bin
4. Checking phpunit is working
$sudo phpunit --version
The setup is success, if the above command is returning the given below message :
PHPUnit 7.0.3 by Sebastian Bergmann and contributors.
Method2 : With Composer
1. Download the composer installer to the root directory of the project
The installer can be downloaded at https://getcomposer.org/installer
2. Execute the installer in terminal with the given below command
$php installer
This will download the file composer.phar to the root directory of the project
3. Adding the PHPUnit library to this project
$php composer.phar require --dev phpunit/phpunit
This will download the latest version of PHPUnit to the directory vendor
4. Checking phpunit is working
$./vendor/bin/phpunit --version
The setup is success, if the above command is returning the given below message :
PHPUnit 7.0.3 by Sebastian Bergmann and contributors.
Comments on this post