Install PHPUnit Manually without Pear for a Single Project to test source code classes with or without Wamp/XAMP installation

Step By Step Guide to install PHPUnit

This tutorial is an easy start to test your PHP source code which is build using classes i.e. OOP’s with/without wamp/xamp doesn’t really matter.

The key to PHPUnit installation is set correct include path of your PHPUnit directory and extend correct phpUnit class in test case file.

Related Tutorial: Install and set single PHP Unit installation for multiple projects

1. Download PHPUnit from “”. Recommend to download latest PHPUnit. The latest PHPUnit at the time of writing the article is “PHPUnit-3.4.9.tar” (

2. Copy PHPUnit folder found in the downloaded phpUnit tar/tgz bundle to your website root. So your PHPUnit installation directory will look like “C:\wamp\www\YourProjectName\PHPUnit”.

3. Now the Key is to set the correct include path of PHPUnit file in order to execute unit test cases.

4. Setup the following path in Operating System Environment (win + break Key short cut OR right click on My Computer icon on desktop->  select properties-> select Advanced tab-> click environment variables button->select “Path” and then finally edit)-
Place this path (should be as per your setup)-> C:\wamp\bin\php\php5.2.9-2;

See screenshot at end of this post.

5. Create a “/tests/” folder in your project.

6. Create a dummyTest.php in “/tests/” folder.

7. Add the following code in dummyTest.php

$applicationRoot = dirname(__FILE__);

set_include_path(get_include_path() . PATH_SEPARATOR . $applicationRoot);
set_include_path(get_include_path() . PATH_SEPARATOR . $applicationRoot . '/PHPUnit');

require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php';

If you want particular pattern for your test file i.e. suffix.
How this can help-
In real world scenario you will be having a directory like "/tests/" which will include all the phpUnit test case files.
Now you can create a Master test case file like "RunAllTestCases.php".
In this file you can set the phpUnit include paths and can write customize code to automatically run all the test cases which are in "/tests/" folder.
//define('TEST_FILE_PATTERN', '-test.php');

require_once "YourClassFolder/UserLogin.class.php";

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

8. Make sure the following-
– PHPUnit include paths are correctly set in “dummyTest.php” as per your project installation.
– php unit test case file should extend PHPUnit_Framework_TestCase like- Class dummyTest extends PHPUnit_Framework_TestCase {}
– The Class file you want to test is included in the test case file like- require_once “YourClassFolder/UserLogin.class.php”;

9. Run your phpUnit Test case on command line as- C:\wamp\www\YourProjectName\tests>PHPUnit dummyTest.php




Set PHP in System Environment



Both comments and pings are currently closed.

17 Responses to “Install PHPUnit Manually without Pear for a Single Project to test source code classes with or without Wamp/XAMP installation”

  1. Garry says:

    Hi Darth,

    The problem seems to be of configuring correct path and not dependencies.
    You have just mentioned “require_once ‘PHP/CodeCoverage/Filter.php’;”.

    I am assuming that your applications is not able to find the correct path to filter.php. Installing and configuring does not require anything else other than PHP and PHPUnit.

    Also there is no folder like CodeCoverage in PHP. But yes, there are two separate files codecoverage.php and filter.php under utils folder.

    Check out that include paths are correctly set.

  2. DarthEroz says:

    I want to install PHPUnit manually.
    But PHPUnit is looking for its dependencies

    require_once ‘PHP/CodeCoverage/Filter.php’;
    and others…

    How can i install depencies if i install the PHPUnit manually in my linux ubuntu workstation.

  3. gilad says:

    i get this error:
    C:\wamp\www\trackstar\tests>phpunit dummytest.php
    Could not open input file: @bin_dir@\phpunit

  4. Finally, got what I was on the lookout for! I am definitely having fun with reading each little bit of it. Thankful I stumbled onto this post UncleCode.Com – Technology Blog | Install PHPUnit Manually without Pear for a Single Project to test source code classes, Install PHPUnit Manually, Step By Step Guide to install PHPUnit. ! I have you bookmarked to take a look at new stuff you write.

  5. Julian says:

    Great Article. Thanks!!

  6. DigolosSSD says:

    I liked a resource. Already many resources look well at last that have learned to do beautifully. Our information century has forced people to do the affairs and instantly to solve any questions through a global network the Internet.

  7. Hey this post is nice and interesting. I’ll use it for my essay :). Can you comment me some related articles I could use too?

  8. Definitely a superb post regarding the topic, keep up the great work also I hope to read even more of your stuff in the longer term.

  9. Robert Wilson says:

    thanks for the post

  10. mark says:


  11. Thanks a lot for sharing this with all of us you really know what you are talking about! Bookmarked 🙂 Please also visit my site about how to make money online.

  12. jason says: focus on DVD business for years. We provide large range of DVD Boxsets, TV series and Movies,Blu-rays in competitive price and high quality. All items are brand new and factory sealed. Wholesales & Drop shipping business cooperation are welcomed. We offer the best price for your resell business.It is our pleasure to build a long-term business relationship with you.

  13. This was really helpful, I appreciate it

  14. Excellent blog! I definitely love how it is easy on my eyes and the information are well written. I am wondering how I may be notified whenever a new post has been made. I have subscribed to your rss feed which should do the trick! Have a nice day!

  15. Great article, I just wish I could find the RSS button to subscribe!

  16. Thank you for share very nice knowledges.