Last Updated: February 25, 2016
· vinceve

Installing PHPUnit on Windows

This article is written because installing PHPUnit on Windows is a pain. I assume PHP is already installed and already added to your environment variables.

1. Create a folder and download git projects in the folder

git clone git://github.com/sebastianbergmann/phpunit.git
git clone git://github.com/sebastianbergmann/dbunit.git
git clone git://github.com/sebastianbergmann/php-file-iterator.git
git clone git://github.com/sebastianbergmann/php-text-template.git
git clone git://github.com/sebastianbergmann/php-code-coverage.git
git clone git://github.com/sebastianbergmann/php-token-stream.git
git clone git://github.com/sebastianbergmann/php-timer.git
git clone git://github.com/sebastianbergmann/phpunit-mock-objects.git
git clone git://github.com/sebastianbergmann/phpunit-selenium.git
git clone git://github.com/sebastianbergmann/phpunit-story.git
git clone git://github.com/sebastianbergmann/php-invoker.git

2. Open the php.ini and configure the include_path, this is an example of me. PROTIP: Look closely at the paths.

include_path = ".;F:/softwaredev/UniServer/home/us_pear/PEAR;F:/softwaredev/UniServer/lib;F:\softwaredev\UniServer\lib\phpunit;F:\softwaredev\UniServer\lib\php-code-coverage;F:\softwaredev\UniServer\lib\php-file-iterator;F:\softwaredev\UniServer\lib\php-invoker;F:\softwaredev\UniServer\lib\php-text-template;F:\softwaredev\UniServer\lib\php-timer;F:\softwaredev\UniServer\lib\php-token-stream;F:\softwaredev\UniServer\lib\phpunit-mock-objects;F:\softwaredev\UniServer\lib\phpunit-selenium;F:\softwaredev\UniServer\lib\phpunit-story"

3. Copy the include_path to your php-cli.ini for running tests at the commandline

4. Open the phpunit folder that you checked out, and open the bat file in an editor.

if "%PHPBIN%" == "" set     PHPBIN="C:\WampDeveloper\Components\Php\php.exe"
if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto     USE_PEAR_PATH


"%PHPBIN%" -d safe_mode=Off     "C:\Users\branko\Server\lib\PHPUnit\phpunit.php" %*

5. Add the phpunit folder where the bat file is located to your environment variables.

Tests can now be run from the commandline :-)

Say Thanks

2 Responses
Add your response


Installing PHPUnit on Windows is as easy as downloading http://pear.phpunit.de/get/phpunit.phar and running it via "php phpunit.phar".

BTW: You're instructing your readers to install development versions of PHPUnit (that require PHP 5.4) without telling them about it.

over 1 year ago ·

For reference: The new download location for the phar is: https://phar.phpunit.de/phpunit.phar


over 1 year ago ·