It is relatively easy. I am using cake 1.3 from composer installation. This is what my composer.json looks like:
{ "config": { "vendor-dir": "vendors/composer" }, "require": { "phpunit/phpunit": "3.7.*", "cakephp/cakephp-1.3": "1.3", }, "repositories": [ { "type": "package", "package": { "name": "cakephp/cakephp-1.3", "version": "1.3", "source": { "url": "https://github.com/cakephp/cakephp.git", "type": "git", "reference": "1.3" } } } ] }
Then the phpunit bootstrap.php file in the test directory:
<?php include('../vendors/composer/autoload.php'); include('../webroot/index.php');
This phpunit.xml form the same directory:
<?xml version="1.0" encoding="UTF-8"?> <phpunit bootstrap="bootstrap.php" backupStaticAttributes="false" cacheTokens="false" colors="false" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" forceCoversAnnotation="false" mapTestClassNameToCoveredClassName="false" printerClass="PHPUnit_TextUI_ResultPrinter" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader" strict="false" verbose="false" > <testsuites> <testsuite name="AllTests"> <directory>.</directory> </testsuite> </testsuites> <filter> <blacklist> <directory suffix=".php"></directory> <file></file> <exclude> <directory suffix=".php"></directory> <file></file> </exclude> </blacklist> <whitelist processUncoveredFilesFromWhitelist="true"> <directory suffix=".php"></directory> <file></file> <exclude> <directory suffix=".php"></directory> <file></file> </exclude> </whitelist> </filter> </phpunit>
Remember to load application classes into test setup. You can do it in cakephp way. For example, if your controller is called a calendar, your calendarTest.php might look like this:
<?php class CalendarTest extends PHPUnit_Framework_TestCase { private $calendarController; function setUp() { App::import('Core', array('View', 'Controller', 'Model', 'Router')); App::import('Controller', 'Calendar'); $this->calendarController =& new CalendarController(); $this->calendarController->constructClasses(); $this->calendarController->layout = null; } }
The same goes for models, vendor classes, etc. Works great for me.