public function testNestedReference() { $test = new Hierarchy('Root'); $child1 = $test->addChild('Child 1'); $child2 = $test->addChild('Child 2'); $this->dm->persist($child1); $this->dm->persist($child2); $this->dm->persist($test); $this->dm->flush(); $this->dm->clear(); $test = $this->dm->getRepository(__NAMESPACE__ . '\\Hierarchy')->findOneBy(array('name' => 'Root')); $this->assertNotNull($test); $child1 = $test->getChild('Child 1')->setName('Child 1 Changed'); $child2 = $test->getChild('Child 2')->setName('Child 2 Changed'); $test->setName('Root Changed'); $child3 = $test->addChild('Child 3'); $this->dm->persist($child3); $this->dm->flush(); $this->dm->clear(); $test = $this->dm->find(__NAMESPACE__ . '\\Hierarchy', $test->getId()); $this->assertNotNull($test); $this->assertEquals('Root Changed', $test->getName()); $this->assertEquals('Child 1 Changed', $test->getChild(0)->getName()); $this->assertEquals('Child 2 Changed', $test->getChild(1)->getName()); $child3 = $this->dm->getRepository(__NAMESPACE__ . '\\Hierarchy')->findOneBy(array('name' => 'Child 3')); $this->assertNotNull($child3); $child3->setName('Child 3 Changed'); $this->dm->flush(); $child3 = $this->dm->getRepository(__NAMESPACE__ . '\\Hierarchy')->findOneBy(array('name' => 'Child 3 Changed')); $this->assertNotNull($child3); $this->assertEquals('Child 3 Changed', $child3->getName()); $test = $this->dm->getDocumentCollection(__NAMESPACE__ . '\\Hierarchy')->findOne(array('name' => 'Child 1 Changed')); $this->assertFalse(isset($test['children']), 'Test empty array is not stored'); }