Earlier I wrote about some PHPUnit tips around Cake2. At that time the old SimpleTest testing framework had just been replaced by PHPUnit. So everything around this new framework was fairly new – especially to be.
I manually installed/downloaded the test suite files since I didnt want to install any PEAR stuff – on windows this is pretty annoying anyway. So is there a quick way to always be up to date with PHPUnit? Yes, there is. Since it is now pretty stable I want to introduce the PHPUnit plugin, which I developed together with Hyra.
Installing PHPUnit – the easy way
It never was easier. All you need for it is the PHPUnit plugin. Just open your console in your app directory and type
Phpunit.Phpunit install
Select your destination (APP or ROOT vendors) and done. This will download and extract all the necessary files, and put them in your specified Vendor folder.
Make sure you got CakePlugin::loadAll() – or specifically CakePlugin::load(‘Phpunit’) in your bootstrap! Otherwise the plugin will not be available. You can now use PHPUnit through the CLI or your favourite browser right away.
See the documentation of the plugin for details. Also note the convenience tasks (‘packages’, ‘info’) to check for updates and update the plugin shell if necessary. It also displays the so far unused pear packages.
Autoload
If you have it installed in your ROOT vendors and get some include warnings while baking put this at the top of the VENDORS/PHPUnit/Autoload.php file:
set_include_path(get_include_path().PATH_SEPARATOR.dirname(dirname(__FILE__)));
This way the vendors folder itself is also an include path and those warnings will go away.
Further setup and usage
For this I can just refer you to the official documentation.
Appendix
In my case just now, info printed the following:
# PHPUnit 3.6.11 OK (v3.6.11) # File Iterator 1.3.1 OK (v1.3.1) # Text Template 1.1.1 OK (v1.1.1) # PHP CodeCoverage 1.1.3 OK (v1.1.3) # PHP Timer 1.0.2 OK (v1.0.2) # PHPUnit MockObject 1.1.1 OK (v1.1.1) # PHP TokenStream 1.1.3 OK (v1.1.3) # DbUnit 1.1.2 OK (v1.1.2) # PHPUnit Story 1.0.0 OK (v1.0.0) # PHPUnit Selenium 1.2.7 OK (v1.2.7) # PHPUnit TicketListener GitHub 1.0.0 OK (v1.0.0) --------------------------------------------------------------- Unused pear packages: # FinderFacade (v1.0.1) # Object_Freezer (v1.0.0) # PHPUnit_SkeletonGenerator (v1.1.0) # PHPUnit_TestListener_DBUS (v1.0.0) # PHPUnit_TestListener_XHProf (v1.0.0) # PHPUnit_TicketListener_Fogbugz (v1.0.0) # PHPUnit_TicketListener_GoogleCode (v1.0.0) # PHPUnit_TicketListener_Trac (v1.0.0) # PHP_CodeBrowser (v1.0.2) # PHP_Invoker (v1.1.0) # bytekit (v1.1.2) # hphpa (v1.2.2) # phpcov (v1.0.0) # phpcpd (v1.3.5) # phpdcd (v0.9.3) # phploc (v1.6.4) # ppw (v1.0.4) # test_helpers (v1.1.0)
