Example #1
0
 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());
 }
Example #2
0
 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 testModifyingCollectionInChangeTrackingNotifyDocument()
 {
     $profile = new ProfileNotify();
     $f1 = new File();
     $f1->setName('av.jpeg');
     $profile->getImages()->add($f1);
     $f2 = new File();
     $f2->setName('ghost.gif');
     $profile->getImages()->add($f2);
     $this->dm->persist($profile);
     $this->dm->flush();
     $profile = $this->dm->find(get_class($profile), $profile->getProfileId());
     $profile->getImages()->move(0, 1);
     $this->dm->flush();
     $this->dm->clear();
     $profile = $this->dm->find(get_class($profile), $profile->getProfileId());
     $this->assertCount(2, $profile->getImages());
     $this->assertEquals($f2->getName(), $profile->getImages()[0]->getName());
     $this->assertEquals($f1->getName(), $profile->getImages()[1]->getName());
 }