Alex Biddle     About     Archive     Feed

Install phpunit with CakePHP and Windows

The usual way to install phpunit was through PEAR, however this looks to be deprecated in the future.

There is a .phar package for phpunit, however it’s not immediately clear whether this can be used in combination with CakePHP’s web-runner interface.

One alternative that works is to include a local copy of the phpunit files in your CakePHP application. There is already project that does this for you, however it’s even easier to use Composer.

Firstly, you need to create a composer.json file in the root directory of your CakePHP application.

    "config": {
		"vendor-dir": "vendors"
    "require-dev": {
        "phpunit/phpunit": "3.7.*"

The vendors directory is the directory that already exists in CakePHP.

Next you have to install Composer. I’m running this on an Ubuntu with cURL, so it took about 10 seconds. I then moved the executable to a place where it would get picked up by the shell’s path:

sudo cp composer.phar /usr/local/bin

Once this is done, you can run composer.phar install in the same directory as your composer.json file, and it will automatically install phpunit and its dependencies into the vendors folder. The final step is to tell CakePHP to include the library using the autoload.php file generated by Composer:

require_once VENDORS . 'autoload.php';

After my colleague had updated his repository, his Windows installation could now run CakePHP’s phpunit web-runner.