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 “http://pear.phpunit.de/get/”. Recommend to download latest PHPUnit. The latest PHPUnit at the time of writing the article is “PHPUnit-3.4.9.tar” (http://pear.phpunit.de/get/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

<?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

Execute--Run-PHPUnit-Test-Case-Command-Line

 

 

Set PHP in System Environment

 

php-set-in-environment-path

Bookmark and Share
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. 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.

  11. jason says:

    dvdscollect.com 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.

  12. This was really helpful, I appreciate it

  13. 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!

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

  15. Thank you for share very nice knowledges.

n

400-101 70-410 200-120 MB2-703 070-462 70-462 70-461 070-410 JN0-102 70-411 C_TADM51_731 C4090-958 70-483 EX300 070-461 MB2-702 C2180-278 HP0-J73 ICBB 070-246 070-341 070-417 070-457 400-101 70-410 050-SEPROAUTH-02 200-120 MB2-703 070-462 70-462 70-461 070-410 JN0-102 70-411 C_TADM51_731 C4090-958 70-483 EX300 070-461 MB2-702 MB7-702 642-874 642-902 70-410 70-411 70-417 1y0-371 c4090-971 77-420 400-101 70-410 050-SEPROAUTH-02 200-120 MB2-703 070-462 70-462 70-461 070-410 JN0-102 70-411 C_TADM51_731 C4090-958 70-483 C2030-283-test C2040-403-test 70-480 70-413 70-412 70-460 70-410 70-688 200-101 070-411 100-101 640-554 700-505 70-457 70-460 400-101 70-410 70-417 70-463 70-488 70-462 C2090-303 70-410 400-101 70-410 050-SEPROAUTH-02 200-120 MB2-703 070-462 70-462 70-461 070-410 JN0-102 70-411 70-342 70-460 74-338 MB6-871 200-101 70-484 C2090-303 MB6-886 1Z0-481 1Z0-899 400-051 70-246 70-496 74-343 70-460 C2150-197 EX0-001 070-243 70-466 C_THR12_66 C4040-225 1Z0-061 70-347 C4090-452 VCP-550 70-243 VCP-550 70-414 70-466 100-101 JN0-102 1Z0-060 MB2-701 70-467 EX200 M70-301 70-489 220-802 050-SEPROAUTH-02 M70-101 70-458 70-462 70-461 646-206 700-501 70-480 C4040-108 MB2-701 070-411 100-101 640-554 700-505 70-457 70-460 70-457 70-460 C2150-197 EX0-001 070-461 MB2-702 MB7-702 220-802 400-101 646-206 700-501 70-460 C2150-197 EX0-001 070-243 70-466 C_THR12_66 C4040-225 1Z0-061 70-411 C_TADM51_731 C4090-958 70-483 EX300 070-461 MB2-702 MB7-702 220-802 400-101 646-206 700-501 200-120 300-101 70-410 70-411 sy0-401 220-801 1z0-051 1z0-803 vcp550 2v0-621d ex0-001 70-246 70-496 74-343 1Y0-200 70-178 70-640 CV0-001 MB6-872 C2170-008 exam 400-101 70-410 JN0-102 200-120 MB2-703 070-462 70-462 70-461 070-410 200-120 MB2-703 070-462 70-462 70-461 070-410 1Z0-485 1Z0-897 200-120 PR000041 exam 200-120 400-101 300-115 100-101 200-101 70-410 70-411 70-680 70-412 646-206 700-501 70-480 C4040-108 MB2-701 070-411 100-101 640-554 700-505 70-457 70-460 C2150-197 EX0-001 070-243 70-410-braindumps 70-411 70-461 300-209 400-101 70-417 642-998 642-999 JN0-102 C2150-197 EX0-001 070-243 70-466 C_THR12_66 C4040-225 1Z0-061 70-347 C4090-452