Freelance developer, and designer

Setting Up CakePHP 2 and PHPUnit via Composer

This article is heavily outdated which may more may not help people. Though looking back, I needed the composer autoload import thing.

Just recently, I've been having problems collaborating on some minor projects due to conflicting settings and dependencies. So, I worked up the whole morning finding the right settings for me to provide a natural-ish workflow.

After a project has been baked, cake bake project_name, I setup composer to install CakePHP and PHPUnit.

Setting up the composer.json file

So, here's the deal, I still suck at composer! But.. I'm trying aren't I? So, on your app directory, create a composer.json file.

  "require": {
    "cakephp/cakephp": "2.3.5",
    "phpunit/phpunit": "3.7.*"
  "repositories": [
      "type": "package",
      "package": {
        "name": "cakephp/cakephp",
        "version": "2.3.5",
        "dist": {
          "url": "https://github.com/cakephp/cakephp/archive/master.zip",
          "type": "zip"
  "config": {
    "vendor-dir": "Vendor"

After creating the file, run composer install. If you don't have Composer installed, I recommend you go here.

This gets the latest version of CakePHP (from GitHub) and PHPUnit and dump 'em all inside our Vendor folder.

Importing composer's Autoload

In your Config/bootstrap.php, you need to import the Composer's autoload.php

App::import('Vendor', array('file' => 'autoload'));

Patching up the index file

Now, go to line 66, or just find define('CAKE_CORE_INCLUDE_PATH' and replace the line with this:

define('CAKE_CORE_INCLUDE_PATH', ROOT . DS .  APP_DIR . DS . 'Vendor' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib');

The project would start using the Vendor copy rather than your local copy of CakePHP.


I prefer this setup because it's kind of a hassle having the same environment setup as the other guys in developing an app just to avoid commit conflicts.

Composer, though still kind of young, really helped a handful in patching up some rather complicated problems we've had from ways back.