public function testSelfReferencingManyToMany() { $person1 = new CompanyPerson(); $person1->setName('Roman'); $person2 = new CompanyPerson(); $person2->setName('Jonathan'); $person1->addFriend($person2); $this->assertEquals(1, count($person1->getFriends())); $this->assertEquals(1, count($person2->getFriends())); $this->_em->persist($person1); $this->_em->persist($person2); $this->_em->flush(); $this->_em->clear(); $query = $this->_em->createQuery('select p, f from Doctrine\\Tests\\Models\\Company\\CompanyPerson p join p.friends f where p.name=?1'); $query->setParameter(1, 'Roman'); $result = $query->getResult(); $this->assertEquals(1, count($result)); $this->assertEquals(1, count($result[0]->getFriends())); $this->assertEquals('Roman', $result[0]->getName()); $friends = $result[0]->getFriends(); $this->assertEquals('Jonathan', $friends[0]->getName()); }