How do I include the library / API in my Behat project that was added by Composer?

Apparently version 4 of PHPUnit now uses Composer for autoloading, which means that the usual means of enabling PHPUnit in Behat version 2 are:

require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Framework/Assert/Functions.php';

      

Does not work. I was hoping that /vendor/autoload.php

in my folder Behat would include it, but it looks like it doesn't.

I'm guessing what I'm asking is, what is the general way that I can include a Composer added library in my code?

+3


source to share


1 answer


You can successfully use default /vendor/autoload.php

to load your libraries and your code. It's hard to tell what might be wrong without further details, but make sure your composer dependencies are up to date and then just a composer is required authoload.php

. The .json composer should look like this:

{
    "require": {
        "behat/behat": "dev-master",
        "behat/mink": "dev-master",
        "behat/mink-extension": "dev-master",
        "behat/mink-browserkit-driver": "dev-master",
        "behat/mink-goutte-driver": "dev-master",
        "behat/mink-selenium2-driver": "dev-master",
        "phpunit/dbunit": "*",
        "phpunit/phpunit": "*",
    },
    "autoload": {
        "psr-0": {
            "": "./src/"
        }
    }
}

      



You can include it in your context hook (this is, however, an example from Behat 3):

/**
 * @beforeSuite
 */
public static function setUpSuite()
{
    require_once './vendor/autoload.php';
}

      

+4


source







All Articles