The primary goal of unit testing is to take the smallest piece of
testable software in the application, isolate it from the remainder of
the code, and determine whether it behaves exactly as you expect. Each
unit is tested separately before integrating them into modules to test
the interfaces between modules. Unit testing has proven its value in
that a large percentage of defects are identified during its use.
PHPUnit is a unit testing software framework for PHP, as you may guess.
At first I thought installation was something straight forward, but it was not. I had to install PEAR first, and problems appeared from the beginning.I don't want to discourage you, instead I am telling you this just to encourage you not to give up.
During the installation process, I was wondering, what I was doing wrong, so I kept googling and here I will present you the steps needed to install PEAR and PHPUnit error free on WAMP, according to the problems I have faced and the research I have done.
1) Install PEAR
1st step
3rd step
We are almost done here with PEAR installation. In order to use ‘pear’ command in your command prompt from anywhere, you will need to modify the windows environment variables.
2) Upgrade PEAR
In order to continue to the PHPUnit installation, you first have to upgrade PEAR
3) Install PHPUnit
Now we can continue with the PHPUnit installation
If you face a problem here, you can type
PHPUnit is a unit testing software framework for PHP, as you may guess.
At first I thought installation was something straight forward, but it was not. I had to install PEAR first, and problems appeared from the beginning.I don't want to discourage you, instead I am telling you this just to encourage you not to give up.
During the installation process, I was wondering, what I was doing wrong, so I kept googling and here I will present you the steps needed to install PEAR and PHPUnit error free on WAMP, according to the problems I have faced and the research I have done.
1) Install PEAR
1st step
- First open php.ini file located at C:\wamp\bin\php\php5.3.0\php.ini
- Find the following line ;phar.require_hash = On
- Uncomment by removing the semi-colon
- Change 'On' to 'Off'
- Save the file
2nd step
- Locate your php folder by writing cd C:\wamp\bin\php\php5.3.0 *** For those who don't know this, by typing cd .. in a command line, you are being moved one level up in the folder structure
- On command prompt type go-pear.bat
- Confirm "system" and hit enter a few times
- double click PEAR_ENV.reg found at your php folder
- edit php.ini again to add pear include path. Search for go-pear and you will see
- Copy these lines and paste them to "php.ini" file located at C:\wamp\bin\apache\apache2.2.11\bin
- Restart the apache
- Type pear upgrade pear and you have PEAR installed on you machine
3rd step
We are almost done here with PEAR installation. In order to use ‘pear’ command in your command prompt from anywhere, you will need to modify the windows environment variables.
- Right click on "My computer" choose Properties -> Advanced > Environmental variables
- Edit "Path" variable and add C:\wamp\bin\php\php5.3.0
- You also need to add a new variable ‘PHP_PEAR_PHP_BIN’ and set the value to
C:\wamp\bin\php\php5.3.0\php.exe
- Close the command prompt, open it again and type pear
- You will see pear command help printed for you
2) Upgrade PEAR
In order to continue to the PHPUnit installation, you first have to upgrade PEAR
- Just type pear upgrade pear
- Type pear -V, to see the version installed
3) Install PHPUnit
Now we can continue with the PHPUnit installation
- On ‘C’ drive create a folder named ‘php5’ (I don't know why and I don't know if this is necessasy, but I did it anyway
- On command prompt type following, but first be sure that you have upgraded PEAR
pear channel-discover components.ez.no pear channel-discover pear.phpunit.de pear channel-discover pear.symfony-project.com pear install --alldeps phpunit/PHPUnit
We’re done! type phpunit –version to confirm installation.
4) Solutions to problems you may face
If you face a problem here, you can type
pear update-channels
pear clear-cache
pear uninstall pear
If you want to unistall PHPUnit type
pear uninstall phpunit/PHPUnit
Duplicate package channel://components.ez.no/ConsoleTools-1.5.1 found
Duplicate package channel://components.ez.no/ConsoleTools-1.5.2 found
or a duplicate package to another channel like
Duplicate channel://pear.phpunit.de/Whatever1.1
Duplicate channel://pear.phpunit.de/Whatever1.2
you can type
pear uninstall pear.phpunit.de/Whatever1.2
pear install pear.phpunit.de/Whatever1.1
That last thing is what made the trick for me! I don't remember exactly which version I have installed and which I have uninstalled for the duplicate packages, but the point is that I read error message and figured out what I have to install or uninstall manually!
Useful links
http://docs.moodle.org/dev/PHPUnit_installation_in_Windows
http://amiworks.co.in/talk/installing-pear-and-phpunit-on-wamp-and-windows-7/
http://www.karakas-online.de/forum/viewtopic.php?t=10459
http://stackoverflow.com/questions/2006626/installing-phpunit-via-pear
http://share.ez.no/forums/install-configuration/noob-having-trouble-installing-pear-and-ezcomponents