0

我尝试编写一个测试并使用我的数据库中的数据,所以我按照文档去做。我的代码:

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'

有人说为什么?

4

0 回答 0