Search code examples
symfonydoctrine-ormbehat

Doctrine annotations are not loaded during execution of Behat context


I use Symfony 2.8 and Behat 3.3. I have standard FeatureContext class in project_root/features/bootstrap directory. Before scenario execution I want purge DB like that:

    /**
     * @BeforeScenario
     */
    public function beforeScenario()
    {
        // use Doctrine\Common\DataFixtures\Purger\ORMPurger
        $purger = new ORMPurger($this->em);
        $purger->purge();
    }

But when I execute test I receive error:

The annotation "@Doctrine\ORM\Mapping\Entity" in class XXX does not exist, or could not be auto-loaded.

My behat.yml is:

default:
    suites:
        default:
          contexts:
            - FeatureContext:
                em: '@doctrine.orm.entity_manager'

    extensions:
        Behat\Symfony2Extension:
          kernel:
            bootstrap: "vendor/autoload.php"
            env: "test"
            debug: "true"

composer.json autoload section:

"autoload": {
        "psr-4": {
            "": "src/"
        },
        "classmap": [
            "app/AppKernel.php",
            "app/AppCache.php"
        ]
    }   

Solution

  • If remove line bootstrap: "vendor/autoload.php" from behat.yml, everything will work as needed.