Install PHPUnit On Wamp / Xamp Manually without Pear

All over the internet you can hundred of articles dealing with the installation of PHPUnit with Pear but rarely you will find any help for manual installation of PHPUnit with PHP or Wamp or XAMP on windows without installing Pear. There is no difference for the installation of PHPUnit if you have only PHP working on your system or have a wamp / xamp installation.

Related Tutorial: Easy Installation Install and set PHP Unit installation for a single project

What you need?

  1. Should have a PHPUnit bundle. You can get this from http://pear.phpunit.de/get/ . You can download PHPUnit-3.4.9.tar from the available list in official website mentioned.
  2. Need to set path of PHPUnit source code directly in include_path of php.ini. So where ever you have extracted PHPUnit it should be in php.ini include path. Read on to know more on this.
  3. PHP installation directory path should be set in Operating System Environment so that you can run php through command line.

Step By Step Guide for Installing PHPUnit manually without Pear

Now you are ready to setup phpunit. Following are the steps required to setup PHPUnit. I am using Windows XP with Wamp. If you are using custom php installation then only thing which should change are directory paths.

  1. Download PHPUnit- http://pear.phpunit.de/get/
  2. You can opt for the latest PHPUnit to download from above URL
  3. 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;
  4. This is the path to your PHP installation directory. In linux/unix based system the path can be /usr/bin/php
  5. Now in your php installation directory create a folder (if does not already exist) “includes”
  6. Open php.ini and set include path as “C:\wamp\bin\php\php5.2.9-2\includes” (if not already set). So it will look like-  “include_path = “.;C:\wamp\bin\php\php5.2.9-2\includes;C:\wamp\bin\php\php5.2.9-2\includes\PHPUnit-3.2.0;”
  7. In above #6 assuming that PhpUnit is contained in parent folder “PHPUnit-3.2.0”
  8. Now in includes folder extract PHPUnit so that the folder structure is like “C:\wamp\bin\php\php5.2.9-2\includes\PHPUnit-3.2.0\PHPUnit” so that PHPUnit directory should include source code folder such as Extensions, Framework, Util etc.
  9. Now at this path “C:\wamp\bin\php\php5.2.9-2\includes\PHPUnit-3.2.0” you will find a file pear-phpunit.bat file. Copy this file and place this file in “C:\wamp\bin\php\php5.2.9-2” directory so that this file is accessible through operating system environment because “C:\wamp\bin\php\php5.2.9-2” path we have set in the environment in step 4 above.
  10. Now rename this pear-phpunit.bat file to phpunit.bat. So the logic is that now through command line if we type in phpunit then operating system can detect file phpunit.bat
  11. Open this file phpunit.bat in a editor like notepad.
  12. Replace the string @php_bin@ with your php installation path. So you file should look something like-set PHPBIN=”C:\wamp\bin\php\php5.2.9-2\php.exe” “C:\wamp\bin\php\php5.2.9-2\php.exe” -dsafe_mode=Off “C:/wamp/bin/php/php5.2.9-2/includes/PHPUnit-3.2.0/PHPUnit/TextUI/Command.php” %*
  13. Note that the path to phpunit source code has also been changed above.
  14. Now we will check the installation. Go to command prompt and type phpunit – -version this should give you an output of the phpunit version you are using.
  15. Now you are done.
  16. Next you need to jump over to you php unit test file and run the test.
  17. So my phpunit test files are at cd projects/tests
  18. We can run the phpunit test file as phpunit MyTest.
  19. View and get a copy of modified / refactored phpunit.bat file for yourself- Click here to view

Setup Environment Variable

php-set-in-environment-path

phpunit-version-check

PHPUnit.Bat file

Get modified / refactored phpunit.bat file for yourself- Click here to view

phpunit.bat

Bookmark and Share
Both comments and pings are currently closed.

6 Responses to “Install PHPUnit On Wamp / Xamp Manually without Pear”

  1. Garry says:

    Hi there,

    I think the problem is with the path settings.
    PHP is not able to find the included files in the include file path specified.

    Check below settings-

    I think #2 requires to be configured in your php.ini file.

    Make sure you have “phpunit.bat” at “C:\PHP\” path.

    In your php.ini in PHP folder make sure you have phpunit path is set something as (as per your system)- include_path = “.;C:\php\includes\PHPUnit-3.2.0”

    My setting is-
    include_path = “.;C:\wamp\bin\php\php5.2.9-2\includes;C:\wamp\www\testphpunit\PHPUnit-3.2.0;C:\wamp\bin\php\php5.2.9-2\includes\PHPUnit-3.2.0”

    Hope this helps.

  2. Phongveth says:

    Dear all,
    I try above steps so many times and the following problems occurs, please help
    Thanks a lot

    D:\PHPProject\ASSET\test>phpunit – -version
    PHP Warning: require_once(PHPUnit/TextUI/TestRunner.php): failed to open stream
    : No such file or directory in C:\PHP\includes\PHPUnit-3.3.17\PHPUnit\TextUI\Com
    mand.php on line 48

    Warning: require_once(PHPUnit/TextUI/TestRunner.php): failed to open stream: No
    such file or directory in C:\PHP\includes\PHPUnit-3.3.17\PHPUnit\TextUI\Command.
    php on line 48
    PHP Fatal error: require_once(): Failed opening required ‘PHPUnit/TextUI/TestRu
    nner.php’ (include_path=’.;c:/php/includes/’) in C:\PHP\includes\PHPUnit-3.3.17\
    PHPUnit\TextUI\Command.php on line 48

    Fatal error: require_once(): Failed opening required ‘PHPUnit/TextUI/TestRunner.
    php’ (include_path=’.;c:/php/includes/’) in C:\PHP\includes\PHPUnit-3.3.17\PHPUn
    it\TextUI\Command.php on line 48

    D:\PHPProject\ASSET\test>

  3. gilad says:

    the bat file is now like this:
    if “%PHPBIN%” == “” set PHPBIN=@php_bin@
    if not exist “%PHPBIN%” if “%PHP_PEAR_PHP_BIN%” neq “” goto USE_PEAR_PATH
    GOTO RUN
    :USE_PEAR_PATH
    set PHPBIN=%PHP_PEAR_PHP_BIN%
    :RUN
    “%PHPBIN%” “@bin_dir@\phpunit” %*

    what changes am i need to make?

  4. Dan says:

    Hey Garry —

    Forgot to stop back in and say ‘thanks’ after I got phpunit working with a manual install on xp x64.

    Followed alot of different tuts tryihg to get PhpUnit up and running, but it was your bat file command that finally did the trick.

    Thanks much for posting this.

    Dan

  5. Garry says:

    Hey Dan,

    I am attaching the screen shot and also phpunit.bat for download.

    Let me know if you face any other problems. The very first thing is get your PHP to be executed by command line.

  6. dan n says:

    garyy –
    tnx for the great article on this. I am struggling to install phpunit w/o pear on windows.

    Q: In tsill a bit confused by step 11. Is that whole string…

    “PHPBIN=”C:\wamp\bin\php\php5.2.9-2\php.exe” “C:\wamp\bin\php\php5.2.9-2\php.exe” -dsafe_mode=Off “C:/wamp/bin/php/php5.2.9-2/includes/PHPUnit-3.2.0/PHPUnit/TextUI/Command.php” %*”

    ..on one single line in the .bat file?

    (or maybe could you just post an screenshot of your finalized .bat file? That would make it totally clear)

    tnx for your tut. Good stuff.

    Dan

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