Wednesday, May 11, 2011

Configuring PHPUnit with XAMPP in Windows

Installing and configuring phpunit is a trivial task in Linux environment. If you are a debian/Ubuntu user, just 'sudo apt-get install phpunit' will install it. If the installation reports any php extension as missing try 'sudo apt-get install php5-theExtensionThatWasMissing'.  It is as simple as that.

But getting it configured it in XAMPP in Windows environment involves some additional complexities. The reasons are
1. It comes with phpunit already installed which is 2.x.y. It may take some time to realize that this is not the latest phpunit, though this is the latest XAMPP
2. pear -V will show that it is 1.7.2 whereas 1.9.1 or higher is needed to install the latest phpunit. This is the first and foremost task.

If you have multiple php versions running, sorting out any path related issues before proceeding will save a lot of hardships and unnecessary confusions.



Steps to Install PHPUnit:
I am going to write down the steps that I had to follow to get it installed in my laptop.

1. cd c:\xampp\php
2. pear upgrade pear
The above command gave the following error
ERROR: failed to mkdir C:\php\pear\docs\Archive_Tar\docs
ERROR: unable to unpack C:\Users\Home539\AppData\Local\Temp\pear\download\Structures_Graph-1.0.4.tgz
ERROR: failed to mkdir C:\php\pear\docs\PEAR
3. mkdir c:\php
4. pear upgrade pear (again)
It upgraded. Now, the version is 1.9.2
Important: If this is not successful, there is no point in continuing further in this direction. If this step is blocking and could not continue, try some alternatives. I have listed some below.
a. Try installing pear freshly. Download and save this as  go-pear.php under c:\xampp\php and run 'php go-pear.php' from there. This should work.
b. Consider installing phpunit without pear as the final option if nothing works

5. Followed the commands in the official site. But, instead of  'pear install phpunit/PHPUnit' execute 'pear install --alldeps phpunit/PHPUnit'
This should install phpunit without any issues. phpunit --version now shows 3.5.13 now in my machine.

It is also recommended to enable xdebug (required for code coverage generation) and curl.

Enabling cURL:
1. Remove ';' from extension=php_curl.dll in php.ini (uncomment)
2. Ensure that  ssleay32.dll and libeay32.dll are in Windows/system32.(copy these from c:\xampp\php to windows\system32)
3. Copy php_curl.dll into Windows\System32 as well.(copy this from c:\xampp\php\ext to windows\system32)

Enabling XDebug:
1. Find the section [XDebug] in php.ini
2. Uncomment the following line (remove ; from the beginning of the line)
zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
3. Copy php_xdebug.dll into Windows\System32 as well.(copy this from c:\xampp\php\ext to windows\system32)

Note: Since XDebug is configured as a zend_extension in the above section, we need to make sure that it is not loaded as a dynamic extension. So, find and comment the following line, if it is their.
extension=php_xdebug.dll

Note: If your Windows is 64 bit, you need to copy the dlls to Windows/SysWOW64 Folder




6 comments:

Michel said...

Thank you !!

Oliver said...

Got it working now. Thanks!

Adam said...

Thanks! That's been a really big help.

stephanj said...

Thanks,

I have upgraded pear sucessfully.
When I type pear -V I get the following:

PEAR Version: 1.9.4
PHP Version: 5.3.8
Zend Engine Version: 2.3.0

However I get an empty output when I type
phpunit --version

Any idea what is going on?

Stephan

Mohamed Irshad said...

Did you continue to upgrade phpunit or just stopped after upgrading pear?
Did you try uninstalling and re-installing phpunit?

Anonymous said...

use this to get the latest php version. There's no point of having an outdated version. --version command is not avaialble in older phpunit settings.

pear upgrade --alldeps phpunit/PHPunit

There's also step by step tutorial for a phpunit sdk on windows 7 if your still having trouble

http://beagile.biz/agile-sdk-php-xampp-windows-7/