Installing PHPUnit on XAMPP on Ubuntu or Mint 12

This blog relates to the installation of “PHPUnit” – the unit testing framework that is used within the yii framework to carry out unit tests on things like class methods etc. It should be installed using the PEAR installer that comes with PHP. I have downloaded XAMPP (version 1.7.7) onto Linux Mint (version 12) system and therefore php is built into the software stack and is installed at:

/opt/lampp/bin

Other blogs and documentation has stated that the pear command can be called directly however I have to use the following syntax to get the thing installed in Mint 12 – open the shell and give the full path to the pear shell script:

sudo /opt/lampp/bin/pear channel-discover pear.phpunit.de
sudo /opt/lampp/bin/pear channel-discover components.ez.no
sudo /opt/lampp/bin/pear channel-discover pear.symfony-project.com

sudo ./pear ... should also work if you are in the actual directory

Version Check

Use the following command to check the installed version of pear which should be greater than version 1.9.2

sudo /opt/lampp/bin/pear -V

Note the capital V not v

if the version is less that 1.9.2 then the PEAR installer needs to be upgraded using the following line:

sudo /opt/lampp/bin/pear upgrade PEAR

Note again capital PEAR not pear

The final installation to add the phpunit to the xampp installation is:

sudo /opt/lampp/bin/pear install phpunit/PHPUnit

I then discovered that the Selenium RC integration for PHPUnit is required and can be installed with the following command.

sudo /opt/lampp/bin/pear install phpunit/PHPUnit_Selenium

In order to actually run a unit test I then use the following command from the terminal window:

/opt/lampp/bin/php /opt/lampp/bin/phpunit path/to/test/fileTest.php

e.g.
from the test folder
/opt/lampp/bin/php /opt/lampp/bin/phpunit ./unit/DbTest.php

leaving off the DbTest.php will run all tests within the unit/ folder.

The first parameter identifies PHP, the second runs the phpunit.php file and the third identifies the testfile.php to be run. Good to go! running unit testing along with the XAMPP installation.

Posted in yii
2 comments on “Installing PHPUnit on XAMPP on Ubuntu or Mint 12
  1. […] Installing PHPUnit on XAMPP on Ubuntu or Mint 12 […]

  2. ardinoto says:

    Thank you so much !! This should be appeared on Yii Wiki

Leave a comment