Installing & setting up PHPUnit manually without PEAR

If there is one thing I hate in PHP world then that’s PEAR. With full respect to it, but it simply does not work for me. I usually jump around from Linux, Windows, OSX on a monthly basis and honestly I have never had it work out of the box. There where always some installation issues with PEAR itself then with the packages. Experience I’m describing here is completely subjective so please do not look at it as me trashing the PEAR. If it works for you, then great. If not, then here is s little HowTo on installing the PHPUnit manually without PEAR.

You can find the source code of PHPUnit at Sebastian Bergmann GITHub ccount, If you scroll down the page there, you fill find the list of git repositories for core PHPUnit and its dependencies:

git clone git://
git clone git://
git clone git://
git clone git://
git clone git://
git clone git://
git clone git://
git clone git://
git clone git://
git clone git://
git clone git://

Using the above list, you pull those packages into the appropriate folder on your disk, I usually create the /lib folder and then add it to my PHP include_path path.

Here is how the structure of my folders looks like.

Once you have pulled everthing from GIT, then you can modify the /lib/PHPUnit/phpunit.bat file to something like:

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" %*

Now add the “C:\Users\branko\Server\lib\PHPUnit” to system path variable, so that “phpunit” command on console executes the “C:\Users\branko\Server\lib\PHPUnit\phpunit.bat”. You also need to have add php.exe to system path.

Finally, if you pulled the above packages from GIT each to it’s own folder under some /lib folder then you need to add those to the php.ini include_path, maybe something like:

include_path = ".:C:/Users/branko/Server/lib:C:/Users/branko/Server/lib/phpunit/php-file-iterator:C:/Users/branko/Server/lib/phpunit/php-code-coverage:C:/Users/branko/Server/lib/phpunit/php-invoker:C:/Users/branko/Server/lib/phpunit/php-text-template:C:/Users/branko/Server/lib/phpunit/php-timer:C:/Users/branko/Server/lib/phpunit/php-token-stream:C:/Users/branko/Server/lib/phpunit/phpunit-mock-objects:C:/Users/branko/Server/lib/phpunit/phpunit-selenium:C:/Users/branko/Server/lib/phpunit/phpunit-story:C:/Users/branko/Server/lib/phpunit:C:/Users/branko/Server/lib/phing-2.4.9/classes"

The above steps should do it, now all you need to do is to actually write some simple unit test and see if it works:

< ?php
class DummyTest extends PHPUnit_Framework_TestCase
    public function testFail()
        $this->fail('Your test successfully failed!');

Save the above code under test1.php then run the console command “phpunit test1.php” (given that you are in the folder where test1.php is). If you see the message “Your test successfully failed!” then you got everything setup OK.

You made it all the way down here so you must have enjoyed this post! You may also like:

How to generate SSH keys for Git authorization Hrvoje Ivancic
, | 17

How to generate SSH keys for Git authorization

Integrating ERP with eCommerce platform Maja Kokolari
, | 3

Integrating ERP with eCommerce platform

Tips for writing maintainable code Stjepan Udovicic
, | 2

Tips for writing maintainable code


  1. Firstly I’ve got to say thank you for posting this! Lord knows how many people needed this!

    I know this post is a little old but though I’d add a comment with some useful information to it.

    I got phpunit to work with this tutorial and then found out that a tool exists for loading php dependencies in a cinch via a json config! Composer! Check it out here:

    It made manually installing phpunit manually a cinch! As easy as calling:

    php composer.phar install (which reads your json config) and then loads the dependencies for your dependecies from a json file:

    “require”: {
    “phpunit/phpunit”: “3.7.*”

    Thanks again for post!

  2. I also donwloadet PHPunit (only 403 KB so i am wonderering).

    There is no phpunit.bat into.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.