static function threeItems(EntityManager $em, $parent, $name = '')
 {
     $i1 = OrderedItemWithParentRelation::build('i 1' . $name, $parent);
     $i2 = OrderedItemWithParentRelation::build('i 2' . $name, $parent);
     $i3 = OrderedItemWithParentRelation::build('i 3' . $name, $parent);
     $i4 = OrderedItemWithParentRelation::build('i 4' . $name, $parent);
     $repo = $em->getRepository('Gradua\\DoctrineExtensions\\OrderedItem\\ExampleEntities\\OrderedItemWithParentRelation');
     //        $em->persist($parent);
     //        $em->persist($i1);
     //        $em->persist($i2);
     //        $em->persist($i3);
     //        $em->persist($i4);
     $repo->addLast($parent);
     $repo->addLast($i1);
     $repo->addLast($i2);
     $repo->addLast($i3);
     $repo->addLast($i4);
     $em->flush();
     $em->remove($i3);
     $em->flush();
     return array($i1->getId(), $i2->getId(), $i4->getId());
 }
     $f1 = $repo->find($fixtureIds[0]);
     $f2 = $repo->find($fixtureIds[1]);
     $f3 = $repo->find($fixtureIds[2]);
     $repo->addBefore($f3, $f1);
     $em->flush();
     $em->clear();
     $parent = $repo->find($f1->getParent()->getId());
     $all = $repo->findAllByParent($parent);
     expect($all[0]->getid())->should('be', $f3->getId());
     expect($all[1]->getid())->should('be', $f1->getId());
     expect($all[2]->getid())->should('be', $f2->getId());
 });
 it('should move to another parent', function () use(&$fixtureIds) {
     $em = Project::sc()->em();
     $repo = $em->getRepository('Gradua\\DoctrineExtensions\\OrderedItem\\ExampleEntities\\OrderedItemWithParentRelation');
     $parent2 = OrderedItemWithParentRelation::build('parent2', null);
     $repo->addLast($parent2);
     $em->flush();
     $fixture2Ids = OrderedItemWithParentRelationFixtures::threeItems($em, $parent2);
     $f_1 = $repo->find($fixtureIds[1]);
     $f2_1 = $repo->find($fixture2Ids[1]);
     $em->flush();
     $em->clear();
     $parent = $repo->find($parent2->getId());
     $f_1->setParent($parent);
     // needs to clear the repo before calling add last to test the query to find the max position.
     $repo->addLast($f_1);
     $children = $repo->findAllByParent($parent);
     expect(count($children))->should('be', 4);
     expect($children[3]->getId())->should('be', $f_1->getId());
 });