Exemplo n.º 1
0
 public function testGetSizeWithSetMongoGridFSFile()
 {
     $mongoGridFSFile = $this->getMockMongoGridFSFile();
     $mongoGridFSFile->expects($this->once())->method('getSize')->will($this->returnValue(200));
     $file = new GridFSFile();
     $file->setMongoGridFSFile($mongoGridFSFile);
     $this->assertEquals(200, $file->getSize());
 }
Exemplo n.º 2
0
 /**
  * Wrapper method for MongoGridFS::storeFile().
  *
  * This method returns the GridFSFile object, unlike the base MongoGridFS
  * method, which returns the "_id" field of the saved document. The "_id"
  * will be set on the $document parameter, which is passed by reference.
  *
  * @see http://php.net/manual/en/mongogridfs.storefile.php
  * @param string|GridFSFile $file     String filename or a GridFSFile object
  * @param array             $document
  * @param array             $options
  * @return GridFSFile
  */
 public function storeFile($file, array &$document, array $options = [])
 {
     if (!$file instanceof GridFSFile) {
         $file = new GridFSFile($file);
     }
     $options = isset($options['safe']) ? $this->convertWriteConcern($options) : $options;
     if ($file->hasUnpersistedFile()) {
         $id = $this->mongoCollection->storeFile($file->getFilename(), $document, $options);
     } else {
         $id = $this->mongoCollection->storeBytes($file->getBytes(), $document, $options);
     }
     $document = array_merge(['_id' => $id], $document);
     $gridFsFile = $this->mongoCollection->get($id);
     // TODO: Consider throwing exception if file cannot be fetched
     $file->setMongoGridFSFile($this->mongoCollection->get($id));
     return $file;
 }