【问题标题】:phpunit can't find doctrine annotationsphpunit找不到教义注释
【发布时间】:2017-04-24 23:38:50
【问题描述】:

我在一个 sylius 项目中工作,并且我进行了一些功能测试。碰巧 sylius 已经切换到 symfony 3.2 并且在此之后我的许多测试都不再工作了。

每当我尝试运行测试时,我都会遇到类似的错误

Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The annotation "@Doctrine\ORM\Mapping\Entity" in class ...\Entity\Block does not exist, or could not be auto-loaded.

我的 phpunit.xml 看起来像

<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true"
     bootstrap="var/bootstrap.php.cache">
<php>
    <server name="KERNEL_DIR" value="./app" />
</php>
<testsuites>
    <testsuite name="Application Test Suite">
        <directory>./src/AppBundle/Tests/</directory>
    </testsuite>
</testsuites>

最后,我的测试有这种设置

abstract class BaseTestCase extends KernelTestCase {
...
protected function setUp()
{
    static::bootKernel();
}
}

知道我的设置可能有什么问题吗?

【问题讨论】:

    标签: doctrine-orm phpunit symfony


    【解决方案1】:

    找到了解决办法。我决定查看 sf 标准 repo 中的phpunit.xml,并将我的“boostrap”选项改为“app/autoload.php”。这解决了我遇到的那种错误。

    <?xml version="1.0" encoding="UTF-8"?>
    <phpunit colors="true"
         bootstrap="app/autoload.php">
    <php>
        <server name="KERNEL_DIR" value="./app" />
    </php>
    <testsuites>
        <testsuite name="Application Test Suite">
            <directory>./src/AppBundle/Tests/</directory>
        </testsuite>
    </testsuites>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-04
      • 2023-03-27
      • 2018-05-28
      • 1970-01-01
      • 2016-05-22
      • 2017-11-14
      • 1970-01-01
      相关资源
      最近更新 更多