Well, before installing PHPUnit into your system, you need to check for some prerequisites.

Prerequisite:

  1. PHP 5.6 or >5.6
  2. PEAR (optional)

Installing PHP 5.6

To install PHP 5.6, I am going to use curl which comes out of the box with OS X.

Okey, let’s start installing PHP 5.6. Open your system terminal command + space bar opens up the search box and type in terminal and hit enter. Now terminal will open up for you. Now enter the below commands to install the PHP 5.6 version.

curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6
cd /usr/local/bin
ln -s /usr/local/php5/bin/php php
ln -s /usr/local/php5/bin/phpize phpize
ln -s /usr/local/php5/bin/php-config php-config

That’s it PHP 5.6 is installed on your system. Didn’t believe me? Okey, let’s check it.

php -v

Now believe, if you see as below.

PHP 5.6.23 (cli) (built: Jun 26 2016 13:17:47) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

Cool! right?

Let’s install PHPUnit

To install PHPUnit, run the below commands on the terminal.

curl https://phar.phpunit.de/phpunit.phar -L -o phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit

This will install PHPUnit package and moves it into /usr/local/bin/phpunit directory.

Now check the PHPUnit version.

# phpunit --version
PHPUnit 5.5.0 by Sebastian Bergmann and contributors.

That’s it, enjoy….