/** * * @param \Sokil\Mongo\GridFS $gridFS instance of GridFS * @param array|\MongoGridFSFile $file instance of File or metadata array * @throws \Sokil\Mongo\Exception */ public function __construct(GridFS $gridFS, $file = null) { $this->gridFS = $gridFS; if (!$file) { return; } if (is_array($file)) { $file = new \MongoGridFSFile($gridFS->getMongoCollection(), $file); } elseif (!$file instanceof \MongoGridFSFile) { throw new Exception('Wrong file data specified'); } $this->file = $file; $this->setDataReference($file->file); }
/** * @expectedException \Sokil\Mongo\Exception * @expectedExceptionMessage Error deleting file: some_error: Some error message */ public function testDeleteFileById_WithAcknowledgedWriteConcern() { $mongoGridFsMock = $this->getMock('\\MongoGridFS', array('delete'), array($this->database->getMongoDB(), 'images')); $mongoGridFsMock->expects($this->once())->method('delete')->will($this->returnValue(array('ok' => (double) 0, 'err' => 'some_error', 'errmsg' => 'Some error message'))); $gridFS = new GridFS($this->database, $mongoGridFsMock); $id = $gridFS->storeBytes('data'); $gridFS->deleteFileById($id); }