如何在 Symfony 3.4 的单元测试中使用数据库中的数据?

问题描述

我尝试编写测试并使用数据库中的数据,因此我按照文档进行操作。 我的代码

use Dooloo\ContentBundle\Entity\Patient;
use PHPUnit\Framework\TestCase;

class RecommendationTest extends TestCase
{
    /**
     * @var \Doctrine\ORM\EntityManager
     */
    private $entityManager;

    /**
     * {@inheritDoc}
     */
    protected function setUp(): void
    {
        $kernel = new \AppKernel('test',true);
        $kernel->boot();
        $container = $kernel->getContainer();

        $this->entityManager = $container
            ->get('doctrine')
            ->getManager();
    }

    public function test()
    {
        $products = $this->entityManager
            ->getRepository(Patient::class)
            ->find(1)
        ;

        $this->assertCount(1,$products->getId());
    }

    /**
     * {@inheritDoc}
     */
    protected function tearDown(): void
    {
        parent::tearDown();

        $this->entityManager->close();
        $this->entityManager = null; // avoid memory leaks
    }
}

但是当我运行测试时出现此错误错误:找不到“AppKernel”类

有人说为什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)