2
votes

On my computer I have a CakePHP Project. And inside the cakephp project I have a composer.json file like below:

{
    "name": "a/b",
    "description": "c",
    "require-dev": {
        "phpunit/phpunit": "3.7.*",
        "phpunit/phpunit-selenium": ">=1.2"
    },
    "license": "Proprietary",
    "authors": [
        {
            "name": "d",
            "email": "e"
        }
    ],
    "minimum-stability": "f"
}

After running composer install I have phpunit and the selenium package installed and working here

/cakephpproject/vendor/bin/phpunit
/cakephpproject/vendor/phpunit/phpunit-selenium

Now from the /cakephpproject/app/ I tried to run the following command

../vendor/bin/phpunit Test/Case/Controller/MyControllerTest

But I am receiving the following error message

Fatal error: Class 'App' not found...

If I use ./Console/cake test app Controller/GranulesController the test does attempt to run but throws the PHPUnit_Extensions_Selenium2TestCase not found error since on the system PHPUnit Selenium is not installed.

How do I make cakephp use the phpunit & the phpunit-selenium I installed using composer and not use the phpunit installed globally?

2

2 Answers

0
votes

The following command seems to be executing the PHPUnit & PHPUnit-Selenium2 I installed using Composer.

./Console/cake test app AllControllers --bootstrap ../vendor/autoload.php
0
votes

I encountered a similar issue in CakePHP 2.x (it was fixed in the latest CakePHP 2.8.5).

CakePHP expects to find PHPUnit in one of the following places:

  1. vendors/phpunit/phpunit
  2. vendors/PHPUnit
  3. vendors/phpunit.phar
  4. app/Vendor/phpunit
  5. app/Vendor/PHPUnit
  6. app/Vendor/phpunit.phar
  7. [Composer's global directory]/vendor/phpunit
  8. [Composer's global directory]/vendor/PHPUnit
  9. [Composer's global directory]/vendor/phpunit.phar

But Composer (by default) creates a directory called vendor for its files (note the lack of a plural).

This issue was recently fixed for CakePHP 2.x, but you can get the same behaviour by setting the COMPOSER_VENDOR_DIR environment variable to vendors.