5

I'm working on a CakePHP 2.x plugin that uses Composer to pull in a package dependency. I am now trying to use the Friends of Cake's Travis package to automatically run my unit tests whenever the plugin's repository is updated.

As far as I can tell this does not include the Composer autoload file required for loading in my vendor files. As a result my tests fail as the class defined in the third-party package is missing.

As described in CakePHP 2's advanced installation I'm trying to add the following to bootstrap.php:-

require APP . 'Vendor' . DS . 'autoload.php';

I've attempted to do this via the before_script of my .travis.yml file to append bootstrap.php:-

before_script:
  - git clone https://github.com/FriendsOfCake/travis.git --depth 1 ../travis
  - ../travis/before_script.sh
  - echo "require APP . 'Vendor' . DS . 'autoload.php';" >> ../cakephp/app/Config/bootstrap.php

Unfortunately this is failing as the file APP . 'Vendor' . DS . 'autoload.php' cannot be found. (I have also tried looking for the file in APP . '..' . DS . 'Vendor' . DS . 'autoload.php').

Where is the Composer autoload.php file located when installing CakePHP using Travis? How can I ensure my third-party package is loaded when my tests run remotely on Travis CI?

drmonkeyninja
  • 8,490
  • 4
  • 31
  • 59
  • 1
    I'm guessing that it's using the default composer vendor directory, which is `./vendor/autoload.php` (lowercase vendor, top directory). In Cake 2, all vendor files where within the app structure under Vendor, and the first bit in the [docs](http://book.cakephp.org/2.0/en/installation/advanced-installation.html#installing-cakephp-with-composer) about the composer file changes composer's vendor directory, which the FOC travis installer doesn't do for you. You may be able to edit the directory to what Cake expects by adding `composer config vendor-dir "Vendor/"` in your before_script block. – jeremyharris Dec 22 '15 at 18:19

2 Answers2

3

Default directory name for third party plugins is vendor (lower case), CakePHP have Vendor, you can change that in .../app/composer.json

{
   "config": {
      "vendor-dir": "Vendor" // CakePHP third party plugins dir name
   },
   "require": {
      ...
   }
}
Sojtin
  • 2,714
  • 2
  • 18
  • 32
1

The solution was to change the Vendor folder in the require statement to the lowercase vendor in the before_script:-

before_script:
  - git clone https://github.com/FriendsOfCake/travis.git --depth 1 ../travis
  - ../travis/before_script.sh
  - echo "require APP . 'vendor' . DS . 'autoload.php';" >> ../cakephp/app/Config/bootstrap.php

After doing this CakePHP correctly includes the Composer autoload file.

drmonkeyninja
  • 8,490
  • 4
  • 31
  • 59