Example #1
0
 public function setUp()
 {
     parent::setUp();
     $this->ids = array();
     $groupA = new Group('groupA');
     $groupB = new Group('groupB');
     $profile = new Profile();
     $profile->setFirstname('Timothy');
     $tim = new User();
     $tim->setUsername('Tim');
     $tim->setHits(10);
     $tim->addGroup($groupA);
     $tim->addGroup($groupB);
     $tim->setProfile($profile);
     $this->dm->persist($tim);
     $john = new User();
     $john->setUsername('John');
     $john->setHits(10);
     $this->dm->persist($john);
     $this->dm->flush();
     $this->dm->clear();
     $this->ids['tim'] = $tim->getId();
     $this->ids['john'] = $john->getId();
     $this->fc = $this->dm->getFilterCollection();
 }
Example #2
0
 public function testLazyLoadReference()
 {
     $user = new User();
     $profile = new Profile();
     $profile->setFirstName('Jonathan');
     $profile->setLastName('Wage');
     $user->setProfile($profile);
     $user->setUsername('jwage');
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $query = $this->dm->createQuery('Documents\\User')->where('id', $user->getId());
     $user = $query->getSingleResult();
     $profile = $user->getProfile();
     $this->assertTrue($profile instanceof \Proxies\DocumentsProfileProxy);
     $profile->getFirstName();
     $this->assertEquals('Jonathan', $profile->getFirstName());
     $this->assertEquals('Wage', $profile->getLastName());
 }
 /**
  * @expectedException \Doctrine\ODM\MongoDB\DocumentNotFoundException
  * @expectedExceptionMessage The "Proxies\__CG__\Documents\Profile" document with identifier "abcdefabcdefabcdefabcdef" could not be found.
  */
 public function testDocumentNotFoundExceptionWithMongoId()
 {
     $profile = new Profile();
     $user = new User();
     $user->setProfile($profile);
     $this->dm->persist($profile);
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $collection = $this->dm->getDocumentCollection(get_class($user));
     $invalidId = new \MongoId('abcdefabcdefabcdefabcdef');
     $collection->update(array('_id' => new \MongoId($user->getId())), array('$set' => array('profile.$id' => $invalidId)));
     $user = $this->dm->find(get_class($user), $user->getId());
     $profile = $user->getProfile();
     $profile->__load();
 }
Example #4
0
 public function testDocumentNotFoundEvent()
 {
     $profile = new Profile();
     $user = new User();
     $user->setProfile($profile);
     $this->dm->persist($profile);
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $collection = $this->dm->getDocumentCollection(get_class($user));
     $invalidId = new \MongoId('abcdefabcdefabcdefabcdef');
     $collection->update(array('_id' => new \MongoId($user->getId())), array('$set' => array('profile.$id' => $invalidId)));
     $user = $this->dm->find(get_class($user), $user->getId());
     $profile = $user->getProfile();
     $closure = function (DocumentNotFoundEventArgs $eventArgs) use($profile) {
         $this->assertFalse($eventArgs->isExceptionDisabled());
         $this->assertSame($profile, $eventArgs->getObject());
         $eventArgs->disableException();
     };
     $this->dm->getEventManager()->addEventListener(Events::documentNotFound, new DocumentNotFoundListener($closure));
     $profile->__load();
 }
Example #5
0
$classLoader->register();
$config = new Configuration();
/*
$config->setLoggerCallable(function(array $log) {
    print_r($log);
});
$config->setMetadataCacheImpl(new ApcCache());
*/
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$reader = new AnnotationReader();
$reader->setDefaultAnnotationNamespace('Doctrine\\ODM\\MongoDB\\Mapping\\');
$config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents'));
//$config->setMetadataDriverImpl(new XmlDriver(__DIR__ . '/xml'));
//$config->setMetadataDriverImpl(new YamlDriver(__DIR__ . '/yaml'));
//$config->setMetadataDriverImpl(new PHPDriver());
$dm = DocumentManager::create(new Mongo(), $config);
$profile = new Profile();
$profile->setName('Jonathan H. Wage');
$profile->addSong(new Song('Testinfuckckcg'));
$user = new User();
$user->setUsername('jwage');
$user->setPassword('changeme');
$user->addPhonenumber(new Phonenumber('6155139185'));
$user->setProfile($profile);
$configuration = new ConfigurationDoc();
$configuration->setTimezone('Eastern');
$configuration->setTheme('doctrine');
$user->setConfiguration($configuration);
$dm->persist($user);
$dm->flush();