I'm doing integration testing and I can't directly set an ID to an entity. What I need is, somehow tell Doctrine to reset ID to 1.
When I call flush I get IDs 20, 21, then 22,23.
I have tried deleting table, reseting identity or this thread but nothing helps.
My code:
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();
}
Thanks in advance.