PHPUnit

Get PEAR ready
PHPUnit is used for unit testing of PHP projects. It helps with writing unit tests, running, and analyzing them.

PHPUnit should be installed using the PEAR installer. The current, stable release is 1.9.1 (of Feb 15, 2011). To install PHPUnit, you must have PEAR 1.8.1 or higher.

C:\Program Files\BitNami WAMPStack\php>pear -V PEAR Version: 1.7.2 PHP Version: 5.2.10 Zend Engine Version: 2.2.0 Running on: Windows NT MIHAELA-UNHM 5.1 build 2600
 * Check PEAR version with  

To upgrade PEAR on Windows is known to be tricky. It might be easier to install the latest version of XAMPP.

Here is an example of upgrading PEAR 1.7.2 delivered with a BitNami WAMP stack to 1.9.1.

C:\Program Files\BitNami WAMPStack\php>pear upgrade pear
 * Upgrade an existing PEAR installation with  :

WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update pear/Console_Getopt requires PEAR Installer (version >= 1.9.1), installed version is 1.7.2 downloading PEAR-1.9.1.tgz ... Starting to download PEAR-1.9.1.tgz (293,587 bytes) .............................................................done: 293,587 bytes

downloading Archive_Tar-1.3.7.tgz ... Starting to download Archive_Tar-1.3.7.tgz (17,610 bytes) ...done: 17,610 bytes downloading Structures_Graph-1.0.4.tgz ... Starting to download Structures_Graph-1.0.4.tgz (30,318 bytes) ...done: 30,318 bytes downloading XML_Util-1.2.1.tgz ... Starting to download XML_Util-1.2.1.tgz (17,729 bytes) ...done: 17,729 bytes upgrade ok: channel://pear.php.net/Archive_Tar-1.3.7 upgrade ok: channel://pear.php.net/Structures_Graph-1.0.4 upgrade ok: channel://pear.php.net/XML_Util-1.2.1 upgrade ok: channel://pear.php.net/PEAR-1.9.1 PEAR: Optional feature webinstaller available (PEAR's web-based installer) PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer) PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)

PEAR: To install optional features use "pear install pear/PEAR#featurename"

C:\Program Files\BitNami WAMPStack\php>


 * Update PEAR using   command.

If the installation of PHPUnit shows that a remote channel is unknown, then you have to: C:\Program Files\BitNami WAMPStack\php>pear list -c phpunit INSTALLED PACKAGES, CHANNEL PEAR.PHPUNIT.DE:
 * Discover the missing packages with
 * Check whether symfony has updated its protocols with  
 * Update "symfony" channel with   command:
 * Install again PHPUnit with  
 * Check that PHPUnit has been installed successfully with '''
 * Install again PHPUnit with  
 * Check that PHPUnit has been installed successfully with '''

=
=============================== PACKAGE           VERSION STATE DbUnit            1.0.1   stable File_Iterator     1.2.3   stable PHPUnit           3.5.11  stable PHPUnit_MockObject 1.0.8  stable PHPUnit_Selenium  1.0.2   stable PHP_CodeCoverage  1.0.4   stable PHP_Timer         1.0.0   stable PHP_TokenStream   1.0.1   stable Text_Template     1.1.0   stable

C:\Program Files\BitNami WAMPStack\php>

Install PHPUnit
When asked to add the registry value, say Yes.
 * Add a registry value for PEAR by executing the command  .

PHPUnit distributes its software through PEAR-compatible channels. By using channels, you can install packages that are not part of PEAR. Adding Channel "pear.phpunit.de" succeeded Discovery of channel "pear.phpunit.de" succeeded C:\Documents and Settings\mcs>pear install phpunit/PHPUnit phpunit/PHPUnit can optionally use PHP extension "dbus" downloading PHPUnit-3.5.11.tgz ... Starting to download PHPUnit-3.5.11.tgz (117,869 bytes) ..........................done: 117,869 bytes install ok: channel://pear.phpunit.de/PHPUnit-3.5.11
 * Before you can use a channel, your PEAR installation needs to know about it. This process is called "channel discovery" and uses the URL of the package that you want to install. PHPUnit's URL is  .
 * Once you know the package's channel URL, type the command '''.
 * If the channel discovery is succesful, PEAR outputs
 * Install PHPUnit by executing the PEAR install command  . If installation is successful, the output is:

PHPUnit support in Eclipse
See PHPUnit Eclipse plugin.


 * Install the PHP_CodeSniffer plugin
 * Configure PHPUnit plugin
 * Create a test case skeleton from a PHP class
 * Run the test case

Get PEAR to work
XAMPP has a PEAR package that is bundled with PHP. In the php directory there is a batch file, go-pear, which is supposed to get PEAR ready. It is unclear when this script works. It did it on my XP from a BitNamiWAMP stack.

These are the execution steps from running go-pear batch file: Are you installing a system-wide PEAR or a local copy? (system|local) [system] : Simply hit Return to install a system-wide PEAR (in general, with installation of PEAR, if you don't know what it is asking you, always choose the default value). Below is a suggested file layout for your new PEAR installation. To change individual locations, type the number in front of the directory. Type 'all' to change all of them or simply press Enter to accept these locations. 1. Installation base ($prefix) : C:\php51 2. Binaries directory : C:\php51 3. PHP code directory ($php_dir) : C:\php51\pear 4. Documentation directory : C:\php51\pear\docs 5. Data directory : C:\php51\pear\data 6. Tests directory : C:\php51\pear\tests 7. Name of configuration file : C:\php5\pear.ini 8. Path to CLI php.exe : C:\php51\. 1-8, 'all' or Enter to continue: Beginning install... Configuration written to C:\Program Files\BitNami WAMPStack\php\pear.ini... Initialized registry... Preparing to install... installing phar://go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.3.2.tar... installing phar://go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.2.3.tar...
 * It asks if you are installing a local or a system installation.
 * Next, it asks you for a location to install your copy of PEAR:
 * Hit Enter to continue. The suggested layout should be ok. If you want to make a change, type the number in front of the item and hit Enter. If you wish to change the installation base directory, type 1 and hit Enter. If you want to modify all of the values, type all and hit Enter.
 * At this point, it installs packages. This is a sample output during this installation step:

installing phar://go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.7.2.tar... installing phar://go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.0.2.tar. .. pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0) install ok: channel://pear.php.net/Archive_Tar-1.3.2 install ok: channel://pear.php.net/Console_Getopt-1.2.3 install ok: channel://pear.php.net/Structures_Graph-1.0.2 install ok: channel://pear.php.net/PEAR-1.7.2 PEAR: Optional feature webinstaller available (PEAR's web-based installer) PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer) PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)

PEAR: To install optional features use "pear install pear/PEAR#featurename"

WARNING! The include_path defined in the currently used php.ini does not contain the PEAR PHP directory you just specified:  If the specified directory is also not in the include_path used by your scripts, you will have problems getting any PEAR packages working.
 * Asks if you would like to modify php.ini.

Would you like to alter php.ini  ? [Y/n] : php.ini  include_path updated.
 * If you choose to do this, enter y and it will automatically update the include_path setting in php.ini.

Current include path          : .;C:\php5\pear Configured directory          : C:\Program Files\BitNami WAMPStack\php\pear Currently used php.ini (guess) : C:\Program Files\BitNami WAMPStack\php\php.ini Press Enter to continue:

remove it or be sure to use the new c:\program files\bitnami wampstack\php\pear. bat command
 * WARNING! Old version found at C:\Program Files\BitNami WAMPStack\php, please

The pear command is now at your service at c:\program files\bitnami wampstack\ php\pear.bat

For convenience, a REG file is available under C:\Program Files\BitNami WAMPStack\php\PEAR_ENV.reg. This file creates ENV variables for the current user.
 * WINDOWS ENVIRONMENT VARIABLES *

Double-click this file to add it to the current user registry.

Press any key to continue. ..

Troubleshooting PEAR installation
If running Windows 7/Vista make sure to disable UAC or phpunit will not install!

1) Go to your control panel 2) Go to User Accounts 3) Depending on your OS, there is a line somewhere that says 'Change UAC settings', or something like that. 4) Disable UAC by setting it to the lowest settings. 5) Restart Computer 6) Enjoy!