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