I finally was able to add PHPUnit to an existing CakePHP project that wasn't created with composer.
I had a look inside the CakeTestSuiteDispatcher.php file to see where it was trying to find PHPUnit. It looks in the vendors, app/Vendor, and the include_path for a folder called PHPUnit that has the Autoload.php file (thanks to Nick Zinger for his help with this). Once this folder has been copied across, CakePHP will see that PHPUnit is installed but will throw errors when including dependencies (code coverage, timer, etc.). Here are the steps I took to get everything working.
- Ensure you have the test database setup in app/config/Database.php otherwise your main database may be overwritten or corrupted
- Install a fresh CakePHP (version 2.6.2) project to a new location with PHPUnit (I used version 3.7.38) via Composer
- Copy the inner PHPUnit folder with the Autoload.php file (phpunit/phpunit/PHPUnit ) in the new project to the cakephp vendors folder (the folder outside app) of the old project
- Copy the following folders from the phpunit folder (from the project created with composer in step 1) to you existing vendors folder (the one outside of app):
- php-code-coverage
- php-file-iterator
- php-text-template
- php-timer
- php-token-stream
- phpunit-mock-objects
- Update the require_once paths (I used absolute paths) in the following files in your existing project:
- PHPUnit/Autoload.php
- php-code-coverage/PHP/CodeCoverage/Autoload.php
Once these changes were made the CakePHP Test Suite was available and I was able to run my test cases. This worked for my CakePHP Project(v2.0.6) and my colleagues CakePHP project(v2.0.6).
I hope this helps anyone else having the same problem.