public function testPrimeReferencesWithDiscriminatedReferenceMany()
 {
     $group = new Group();
     $project = new Project('foo');
     $user = new FavoritesUser();
     $user->addFavorite($group);
     $user->addFavorite($project);
     $this->dm->persist($group);
     $this->dm->persist($project);
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $qb = $this->dm->createQueryBuilder('Documents\\Functional\\FavoritesUser')->field('favorites')->prime(true);
     foreach ($qb->getQuery() as $user) {
         $favorites = $user->getFavorites()->toArray();
         $this->assertNotInstanceOf('Doctrine\\ODM\\MongoDB\\Proxy\\Proxy', $favorites[0]);
         $this->assertInstanceOf('Documents\\Group', $favorites[0]);
         $this->assertNotInstanceOf('Doctrine\\ODM\\MongoDB\\Proxy\\Proxy', $favorites[1]);
         $this->assertInstanceOf('Documents\\Project', $favorites[1]);
     }
 }
Esempio n. 2
0
 public function testFavoritesReference()
 {
     $project = new Project('Test Project');
     $this->dm->persist($project);
     $this->dm->flush();
     $group = new Group('Test Group');
     $this->dm->persist($group);
     $this->dm->flush();
     $user = new FavoritesUser();
     $user->setName('favorites');
     $user->addFavorite($project);
     $user->addFavorite($group);
     $address = new Address();
     $address->setAddress('6512 Mercomatic Ct.');
     $address->setCity('Nashville');
     $address->setState('TN');
     $address->setZipcode('37209');
     $user->embed($address);
     $user->setEmbed($address);
     $document = new Phonenumber('6155139185');
     $user->embed($document);
     $user->setFavorite($project);
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $test = $this->dm->getDocumentCollection('Documents\\Functional\\FavoritesUser')->findOne(array('name' => 'favorites'));
     $this->assertTrue(isset($test['favorites'][0]['type']));
     $this->assertEquals('project', $test['favorites'][0]['type']);
     $this->assertEquals('group', $test['favorites'][1]['type']);
     $this->assertTrue(isset($test['favorite']['_doctrine_class_name']));
     $this->assertEquals('Documents\\Project', $test['favorite']['_doctrine_class_name']);
     $user = $this->dm->getRepository('Documents\\Functional\\FavoritesUser')->findOneBy(array('name' => 'favorites'));
     $favorites = $user->getFavorites();
     $this->assertInstanceOf('Documents\\Project', $favorites[0]);
     $this->assertInstanceOf('Documents\\Group', $favorites[1]);
     $embedded = $user->getEmbedded();
     $this->assertInstanceOf('Documents\\Address', $embedded[0]);
     $this->assertInstanceOf('Documents\\Phonenumber', $embedded[1]);
     $this->assertInstanceOf('Documents\\Address', $user->getEmbed());
     $this->assertInstanceOf('Documents\\Project', $user->getFavorite());
 }