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(); }
public function testCreateFileWithMongoGridFSFileObject() { $file = new \Doctrine\MongoDB\GridFSFile(__DIR__ . '/file.txt'); $image = new File(); $image->setName('Test'); $image->setFile($file); $profile = new Profile(); $profile->setFirstName('Jon'); $profile->setLastName('Wage'); $profile->setImage($image); $this->assertTrue($image->getFile()->isDirty()); $this->dm->persist($profile); $this->dm->flush(); $this->assertFalse($image->getFile()->isDirty()); $this->assertSame($file, $image->getFile()); $this->dm->clear(); $profile = $this->dm->createQueryBuilder('Documents\\Profile')->getQuery()->getSingleResult(); $image = $profile->getImage(); $this->assertInstanceOf('Doctrine\\MongoDB\\GridFSFile', $image->getFile()); $this->assertEquals('These are the bytes...', $image->getFile()->getBytes()); $image->getFile()->setFilename(__DIR__ . '/FilesTest.php'); $this->dm->flush(); $this->dm->clear(); $profile = $this->dm->createQueryBuilder('Documents\\Profile')->getQuery()->getSingleResult(); $image = $profile->getImage(); $this->assertEquals('Test', $image->getName()); $this->assertEquals(__DIR__ . '/FilesTest.php', $image->getFile()->getFilename()); $this->assertEquals(file_get_contents(__DIR__ . '/FilesTest.php'), $image->getFile()->getBytes()); $image->getFile()->setBytes('test'); $this->dm->flush(); $this->dm->clear(); $profile = $this->dm->createQueryBuilder('Documents\\Profile')->getQuery()->getSingleResult(); $image = $profile->getImage(); $this->assertEquals('test', $image->getFile()->getBytes()); }
public function testFiles() { $image = new File(); $image->setName('Test'); $image->setFile(__DIR__ . '/file.txt'); $profile = new Profile(); $profile->setFirstName('Jon'); $profile->setLastName('Wage'); $profile->setImage($image); $this->dm->persist($profile); $this->dm->flush(); $this->assertEquals('These are the bytes...', $image->getFile()->getBytes()); $image->setName('testing'); $this->dm->flush(); $this->dm->clear(); $image = $this->dm->find('Documents\\File', $image->getId()); $this->assertEquals('testing', $image->getName()); $this->assertEquals('These are the bytes...', $image->getFile()->getBytes()); }
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()); }
$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();