public function testSettersAndGetters() { $file = new File(); $this->assertInstanceOf('MogileFS\\File', $file->setClass('dev')); $this->assertInstanceOf('MogileFS\\File', $file->setDomain('toast')); $this->assertInstanceOf('MogileFS\\File', $file->setFid(123)); $this->assertInstanceOf('MogileFS\\File', $file->setFile($this->getTestFile())); $this->assertInstanceOf('MogileFS\\File', $file->setKey('key')); $this->assertInstanceOf('MogileFS\\File', $file->setMapper(new Mapper())); $this->assertInstanceOf('MogileFS\\File', $file->setPaths(array('http://mypath.com/123.fid'))); $this->assertInstanceOf('MogileFS\\File', $file->setSize(321)); $this->assertEquals('dev', $file->getClass()); $this->assertEquals('toast', $file->getDomain()); $this->assertEquals(123, $file->getFid()); $this->assertEquals($this->getTestFile(), $file->getFile()); $this->assertEquals('key', $file->getKey()); $this->assertEquals(new Mapper(), $file->getMapper()); $this->assertEquals(array('http://mypath.com/123.fid'), $file->getPaths()); $this->assertEquals(321, $file->getSize()); }
/** * * Uploads file to MogileFS, and populate model with * returned values (such as fid) * @param MogileFS_File $file * @throws Exception * @return MogileFS_File stored in MogileFS */ public function save(File $file) { if (!$file->isValid()) { throw new Exception(__METHOD__ . ' Cannot save invalid file model', Exception::INVALID_ARGUMENT); } $file->setMapper($this); $this->getAdapter()->saveFile($file->getKey(), $file->getFile(false), $file->getClass(false)); $storedFile = $this->find($file->getKey(), false); $storedFileArray = $storedFile->toArray(); unset($storedFileArray['file']); // MogileFS has no information about local file $file->fromArray($storedFileArray); return $file; }