【发布时间】:2016-07-04 15:14:28
【问题描述】:
我正在进行集成测试,我无法直接为实体设置 ID。我需要的是,以某种方式告诉 Doctrine 将 ID 重置为 1。
当我调用 flush 时,我得到 ID 20、21,然后是 22,23。
我已尝试删除表、重置身份或 thread,但没有任何帮助。
我的代码:
public function testFindingAllOrderedByDefault()
{
/** @var $bundles Bundle[] */
$bundles = $this->repository->findAll();
$this->assertCount(2, $bundles);
$this->assertSame(1, $bundles[0]->getId());
$this->assertSame(2, $bundles[1]->getId());
}
protected function prepareDatabase(EntityManager $entityManager, Connection $connection)
{
$connection->executeQuery('TRUNCATE bundle CASCADE');
$entityManager->persist(
(new Bundle())
->setPrice(1200)
->setPriceVat(5000)
->setDiscount(1000)
->setCurrency('czk')
);
$entityManager->persist(
(new Bundle())
->setPrice(1300)
->setPriceVat(4000)
->setDiscount(500)
->setCurrency('eur')
);
$entityManager->flush();
}
提前致谢。
【问题讨论】:
标签: php database postgresql doctrine-orm integration-testing