I’ve had a ton of trouble getting PHPUnit to work with CakePHP 2.2.5 lately, and wanted to document here the steps required to get it to work as intended by the CakePHP developers.
Cake requires a specific version of PHPUnit 3.6.12 in order to function correctly, and report errors correctly. If you run the pear installer as documented in the CakePHP manual, then it will install the latest version of PHPUnit 3.7.13 which isn’t compatible with CakePHP 2.2.5.
Let’s just jump into the instructions to get the right version installed. These steps were take from Ashwini Dhekane’s blog post on the same topic (but unrelated to CakePHP). First make sure you add the PHPUnit channel to pear.
pear channel-discover pear.phpunit.de
If you’re not running the latest version of pear, then it’s best to update now.
pear update-channels pear upgrade-all Remove any existing PHPUnit dependencies
If you have already installed PHPUnit (likely cause you are now searching for a way to get it to work), then remove what you have, because we need to downgrade it. This can be done by uninstalling in the following order.
pear uninstall phpunit/PHPUnit pear uninstall phpunit/PHP_CodeCoverage pear uninstall phpunit/PHPUnit_MockObject pear uninstall phpunit/Text_Template pear uninstall phpunit/PHP_TokenStream pear uninstall phpunit/PHP_Timer pear uninstall phpunit/File_Iterator
After that you need to clear the cache.
We need to now install all the pear packages required for PHPUnit in the correct order, but define which version we want to use.
pear install phpunit/File_Iterator-1.3.2 pear install phpunit/PHP_Timer-1.0.3 pear install phpunit/PHP_TokenStream-1.1.4 pear install phpunit/Text_Template-1.1.2 pear install phpunit/PHPUnit_MockObject-1.1.1 pear install phpunit/PHP_CodeCoverage-1.1.0 pear install phpunit/PHPUnit-3.5.12
After these are installed you can verify that everything was installed with the correct version. This can be done with the pear list command.
pear list -c pear.phpunit.de
Should output the following;
INSTALLED PACKAGES, CHANNEL PEAR.PHPUNIT.DE: ============================================ PACKAGE VERSION STATE File_Iterator 1.3.2 stable PHPUnit 3.6.12 stable PHPUnit_MockObject 1.1.1 stable PHP_CodeCoverage 1.1.0 stable PHP_Timer 1.0.3 stable PHP_TokenStream 1.1.4 stable Text_Template 1.1.2 stable