Easy way to install PHPUnit

Unit Tests are the living description on how the Unit should work, and ensure that your own Creation is working in that way you wanted to. To write unit test cases in php, I would recommend you to go for PHPUnit. I will tell you an easy way if you are going for a manual installation.

The way of manual installation mentioned in PHPUnit manual is as follows:

  • Download a release archive from http://pear.phpunit.de/get/ and extract it to a directory that is listed in the include_path of your php.ini configuration file.
  • Prepare the phpunit script:
    • Rename the pear-phpunit script to phpunit.
    • Replace the @php_bin@ string in it with the path to your PHP command-line interpreter (usually /usr/bin/php).
    • Copy it to a directory that is in your PATH and make it executable (chmod +x phpunit).

I was bit confused while going through above steps as they mentioned :p.

Easy Method (in linux & mac):

  1. Download a release, extract it (no matter where). And find the phpunit.php inside the extracted folder.
  2. In terminal, change directory to /usr/bin then create symbolic link to phpunit.php and name it phpunit.In case you don't know here is the syntax,

sudo ln -s <absolute_path-to-phpunit.php> phpunit

Happy coding!