private function populate() { $food = new Category(); $food->setTitle("Food"); $this->em->persist($food); $fruits = new Category(); $fruits->setTitle('Fruits'); $fruits->setParent($food); $this->em->persist($fruits); $oranges = new Category(); $oranges->setTitle('Oranges'); $oranges->setParent($fruits); $this->em->persist($oranges); $lemons = new Category(); $lemons->setTitle('Lemons'); $lemons->setParent($fruits); $this->em->persist($lemons); $berries = new Category(); $berries->setTitle('Berries'); $berries->setParent($fruits); $this->em->persist($berries); $strawberries = new Category(); $strawberries->setTitle('Strawberries'); $strawberries->setParent($berries); $this->em->persist($strawberries); $vegitables = new Category(); $vegitables->setTitle('Vegitables'); $vegitables->setParent($food); $this->em->persist($vegitables); $cabbages = new Category(); $cabbages->setTitle('Cabbages'); $cabbages->setParent($vegitables); $this->em->persist($cabbages); $carrots = new Category(); $carrots->setTitle('Carrots'); $carrots->setParent($vegitables); $this->em->persist($carrots); $milk = new Category(); $milk->setTitle('Milk'); $milk->setParent($food); $this->em->persist($milk); $cheese = new Category(); $cheese->setTitle('Cheese'); $cheese->setParent($milk); $this->em->persist($cheese); $mouldCheese = new Category(); $mouldCheese->setTitle('Mould cheese'); $mouldCheese->setParent($cheese); $this->em->persist($mouldCheese); $this->em->flush(); }
public function testCascadePersistTree() { $politics = new Category(); $politics->setTitle('Politics'); $news = new News('Lorem ipsum', $politics); $this->em->persist($news); $this->em->flush(); $closure = $this->em->createQueryBuilder()->select('c')->from(self::CLOSURE, 'c')->where('c.ancestor = :ancestor')->setParameter('ancestor', $politics->getId())->getQuery()->getResult(); $this->assertCount(1, $closure); }
public function testPersistOnRightEmInstance() { $evm = new EventManager(); $evm->addEventSubscriber(new TreeListener()); $emOne = $this->getMockSqliteEntityManager($evm); $emTwo = $this->getMockSqliteEntityManager($evm); $categoryOne = new Category(); $categoryOne->setTitle('Politics'); $categoryTwo = new Category(); $categoryTwo->setTitle('Politics'); // Persist and Flush on different times ! $emOne->persist($categoryOne); $emTwo->persist($categoryTwo); $emTwo->flush(); $emOne->flush(); $this->assertNotNull($categoryOne->getId()); $this->assertNotNull($categoryTwo->getId()); }