I'm a web developer, freelancer, author, speaker, entrepreneur, technical reviewer and blogger based in the North East, living in a village just outside of Chester-le-Street.
My blog
PHPUnit on WAMP
At Peacock Carter, we wanted to setup PHPUnit on our local development machines, all of which are Windows. The instructions seemed fairly straight forward. I'm not a fan of PEAR so I tried the manual install instructions, which didn't work at all, after much frustration, I gave the PEAR method a go, which after appearing to do lots of things, also didn't work. I found a couple of articles online regarding the problems installing on Windows, but they didn't cover everything, so I thought (and because Richard Thompson asked me to, so he had a reference for installing it at home!) I'd blog the exact instructions of what to do.
PHPUnit
The first thing is to download and extract PHPUnit, download the file, unzip it and place the resulting folder in
C:\wamp\bin\php\php5.2.9-2\
(I renamed the folder from PHPUnit-3.5.4 to phpunit but its up to you. You can also put the folder anywhere you want, so long as you amend the include path instruction below).
PHP.ini
With the PHPUnit files extracted, we need to alter our php.ini file to have an include path of our PHPUnit directory, add the following line to the appropriate section of the php.ini file.
include_path = "C:\wamp\bin\php\php5.2.9-2\phpunit"
Dependancies
Because I didn't/couldn't/wouldn't install this through PEAR, there were quite alot of dependancies missing, which was frustrating considering the manual installation instructions didn't mention this. I also found, that these dependancies had to be extracted to the (root) phpunit folder, and not the PHPUnit folder within there (which is where I'd initially put them - to a further series of errors!). Download the following dependancies, and extract them to the root phpunit folder (i.e. C:\wamp\bin\php\php5.2.9-2\phpunit).
- PHP/CodeCoverage (copy the PHP folder and its contents)
- PHP/Timer (copy the PHP folder and its contents (don't override the PHP folder from the previous dependancy))
- PHP/TokenStream (copy the PHP folder and its contents (don't override the PHP folder from the previous dependancies))
- Text/Template (copy the Text folder and its contents)
- File/Iterator (copy the File folder and its contents)
The bat (cave) file
Since we are running on Windows, to run PHPUnit, we can't simply rename phpunit.php to phpunit and run it (as per the instructions), we instead run the phpunit.bat file. The bat file in turn runs the PHP executable, and opens the phpunit.php file with it.
Open the phpunit.bat file, and replace its contents with the following (replacing paths to php.exe and phpunit.php with your own systems paths).
C:\wamp\bin\php\php5.2.9-2\php.exe -d safe_mode=Off "C:\wamp\bin\php\php5.2.9-2\phpunit\phpunit.php" %*
phpunit.php
Within the phpunit.php file you need to replace @php_bim@ with the path to your php directory (as per the documentation)
C:\wamp\bin\php\php5.2.9-2
Running PHPUnit
Now simply open the command prompt, browse to your phpunit folder, and run phpunit followed by the file path of your tests.
Alternatives
If you know of alternative or better ways to install it, I'd love to hear them. I have a feeling that my aversion to PEAR (aside from the fact I couldn't get it working that way anyway!) made things more complicated.
Posted by Michael on 23rd Nov 2010 at 01:01
Comments
A useful entry indeed, sounds like whoever suggested you post this entry is a legend, and is worthy of a large pay rise.
Posted by Richard T on 23rd November 2010 at 13:01
Every thing goes fine and easy, only at last while I came to test writing phpunit at CLI, there was warning. So I simply correct it in php.ini, as follows. include_path = "C:\wamp\bin\php\php5.3.5\phpunit\PHP" I liked this post so much because after trying a lot by PEAR and got failure, it helped me to quickly understand and configure well.
Posted by Rajiv Mahmud on 25th July 2011 at 05:05
I got PEAR working, here's how I did it: http://comfycode.wordpress.com/2011/09/29/installingphpunit/
Posted by Alex on 3rd October 2011 at 12:12
Thanks for sharing such a nice article. It saved my time
Posted by sachin on 25th November 2011 at 07:07
Hi Mr. Peacock I got your drupal 6 book and i just have a question for experience since my major is computer engineering and applied science, I tried to connect the wamp server and I did but on phpmyadmin site it keep saying forbidding and it wont show me anything I dont know why any idea? please help it keep saying something about I have to register as admin on my pc which I am already. but still...
Posted by ramin on 20th February 2012 at 02:02


