####Installation

To install CakePHP with Composer in your project, I prefer to move the folders from the standard 2.x directory structure to the root level.

- app
    - Config
    - Console
    - Controller
    ...
    - webroot
    .htaccess
    composer.json
    index.php
- lib
    - Cake
- plugins
- vendors
...

to

- Config
- Console
- Controller
...
- webroot
.htaccess
composer.json
index.php

#####composer.json - phpunit included

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
    "name": "{useraname}/{project-name}",
    "description": "Example Project",
    "config": {
        "vendor-dir": "Vendor"
    },
    "require": {
		"cakephp/debug_kit": "2.2.*",
        "cakephp/cakephp": "2.5.*",
        "phpunit/phpunit": "3.7.*"
    },
    "authors": [
        {
            "name": "Andre Sugai",
            "email": "example@example.com"
        }
    ]
}

#####webroot/index.php - define the CAKE_CORE_INCLUDE_PATH

1
2
3
4
5
6
<?php
//...
define(
    'CAKE_CORE_INCLUDE_PATH',
    ROOT.DS.APP_DIR.DS.'Vendor'.DS.'cakephp'.DS.'cakephp'.DS.'lib'
);

#####webroot/test.php - define the CAKE_CORE_INCLUDE_PATH

1
2
3
4
5
6
<?php
//...
define(
    'CAKE_CORE_INCLUDE_PATH',
    ROOT.DS.APP_DIR.DS.'Vendor'.DS.'cakephp'.DS.'cakephp'.DS.'lib'
);

#####Config/bootstrap.php - Fixes autoloader issues

1
2
3
4
5
6
7
8
9
<?php
//...
// Load composer autoload.
require APP.'Vendor'.DS.'autoload.php';

// Remove and re-prepend CakePHP's autoloader as composer thinks it is the most important.
// See https://github.com/composer/composer/commit/c80cb76b9b5082ecc3e5b53b1050f76bb27b127b
spl_autoload_unregister(array('App', 'load'));
spl_autoload_register(array('App', 'load'), true, true);

#####Console/cake.php - If you are using an older version of cake (<2.6) replace the whole file (fixes console commands)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/php -q
<?php
/**
 * Command-line code generation utility to automate programmer chores.
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Console
 * @since         CakePHP(tm) v 2.0
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */

if (!defined('DS')) {
    define('DS', DIRECTORY_SEPARATOR);
}

$dispatcher = 'Cake'.DS.'Console'.DS.'ShellDispatcher.php';

if (function_exists('ini_set')) {
    $root = dirname(dirname(dirname(__FILE__)));
    $appDir = basename(dirname(dirname(__FILE__)));
    $install = $root.DS.'lib';
    $composerInstall = $root.DS.$appDir.DS.'Vendor'.DS.'cakephp'.DS.'cakephp'.DS.'lib';

    // the following lines differ from its sibling
    // /lib/Cake/Console/Templates/skel/Console/cake.php
    if (file_exists($composerInstall.DS.$dispatcher)) {
        $install = $composerInstall;
    }

    ini_set('include_path', $install.PATH_SEPARATOR.ini_get('include_path'));
    unset($root, $appDir, $install, $composerInstall);
}

if (!include $dispatcher) {
    trigger_error('Could not locate CakePHP core files.', E_USER_ERROR);
}
unset($dispatcher);

return ShellDispatcher::run($argv);

#####.travis.yml - a sample file showing how to set up file paths

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
language: php

php:
  - 5.5

before_script:
  - composer install
  - sh -c "mysql -u travis -e 'CREATE DATABASE test;'"
  - chmod -R 777 tmp
  - echo "<?php
    class DATABASE_CONFIG
    {
      public \$test = array(
          'datasource' => 'Database/Mysql',
          'persistent' => false,
          'host' => '0.0.0.0',
          'login' => 'travis',
          'password' => '',
          'database' => 'test',
          'prefix' => '',
          'encoding' => 'utf8'
      );
    }" > Config/database.php 

script:
  - ./Console/cake test app All

notifications:
  email: false;