public function testIsValid() { $file = new File(); $this->assertFalse($file->isValid(), 'File without any values cannot be valid'); $file->setKey('key'); $file->setFile($this->getTestFile()); $this->assertTrue($file->isValid(), 'File with both key and file should be valid'); }
/** * * 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; }