在执行 Behat 上下文期间不加载 Doctrine 注释

Doctrine annotations are not loaded during execution of Behat context

我使用 Symfony 2.8 和 Behat 3.3。我在 project_root/features/bootstrap 目录中有标准的 FeatureContext class。在场景执行之前,我想像这样清除数据库:

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

但是当我执行测试时,我收到 error:

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

我的behat.yml是:

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": {
        "psr-4": {
            "": "src/"
        },
        "classmap": [
            "app/AppKernel.php",
            "app/AppCache.php"
        ]
    }   

如果从 behat.yml 中删除行 bootstrap: "vendor/autoload.php",一切都会按需运行。