If there is one thing I hate in PHP world then that’s PEAR. With full respect to it, but it simply does not work for me. I usually jump around from Linux, Windows, OSX on a monthly basis and honestly I have never had it work out of the box. There where always some installation issues with PEAR itself then with the packages. Experience I’m describing here is completely subjective so please do not look at it as me trashing the PEAR. If it works for you, then great. If not, then here is s little HowTo on installing the PHPUnit manually without PEAR.
You can find the source code of PHPUnit at Sebastian Bergmann GITHub ccount, https://github.com/sebastianbergmann/phpunit/. If you scroll down the page there, you fill find the list of git repositories for core PHPUnit and its dependencies:
git clone git://github.com/sebastianbergmann/phpunit.git
git clone git://github.com/sebastianbergmann/dbunit.git
git clone git://github.com/sebastianbergmann/php-file-iterator.git
git clone git://github.com/sebastianbergmann/php-text-template.git
git clone git://github.com/sebastianbergmann/php-code-coverage.git
git clone git://github.com/sebastianbergmann/php-token-stream.git
git clone git://github.com/sebastianbergmann/php-timer.git
git clone git://github.com/sebastianbergmann/phpunit-mock-objects.git
git clone git://github.com/sebastianbergmann/phpunit-selenium.git
git clone git://github.com/sebastianbergmann/phpunit-story.git
git clone git://github.com/sebastianbergmann/php-invoker.git
Using the above list, you pull those packages into the appropriate folder on your disk, I usually create the /lib folder and then add it to my PHP include_path path.
Here is how the structure of my folders looks like.
Once you have pulled everthing from GIT, then you can modify the /lib/PHPUnit/phpunit.bat file to something like:
if "%PHPBIN%" == "" set PHPBIN="C:WampDeveloperComponentsPhpphp.exe"
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%" -d safe_mode=Off "C:UsersbrankoServerlibPHPUnitphpunit.php" %*
Now add the “C:UsersbrankoServerlibPHPUnit” to system path variable, so that “phpunit” command on console executes the “C:UsersbrankoServerlibPHPUnitphpunit.bat”. You also need to have add php.exe to system path.
Finally, if you pulled the above packages from GIT each to it’s own folder under some /lib folder then you need to add those to the php.ini include_path, maybe something like:
include_path = ".:C:/Users/branko/Server/lib:C:/Users/branko/Server/lib/phpunit/php-file-iterator:C:/Users/branko/Server/lib/phpunit/php-code-coverage:C:/Users/branko/Server/lib/phpunit/php-invoker:C:/Users/branko/Server/lib/phpunit/php-text-template:C:/Users/branko/Server/lib/phpunit/php-timer:C:/Users/branko/Server/lib/phpunit/php-token-stream:C:/Users/branko/Server/lib/phpunit/phpunit-mock-objects:C:/Users/branko/Server/lib/phpunit/phpunit-selenium:C:/Users/branko/Server/lib/phpunit/phpunit-story:C:/Users/branko/Server/lib/phpunit:C:/Users/branko/Server/lib/phing-2.4.9/classes"
The above steps should do it, now all you need to do is to actually write some simple unit test and see if it works:
< ?php
class DummyTest extends PHPUnit_Framework_TestCase
{
public function testFail()
{
$this->fail('Your test successfully failed!');
}
}
Save the above code under test1.php then run the console command “phpunit test1.php” (given that you are in the folder where test1.php is). If you see the message “Your test successfully failed!” then you got everything setup OK.