/** * Argument validation test * Expecting MogileFS_Exception with 1XX code */ public function testFileValidation() { $file = new File(); try { $file->setFile('/tmp/me_n0_ex1st'); // Not valid value } catch (Exception $exc) { $this->assertLessThan(200, $exc->getCode(), 'Got unexpected exception code'); $this->assertGreaterThanOrEqual(100, $exc->getCode(), 'Got unexpected exception code'); return; } $this->fail('Did not get MogileFS_Exception exception'); }
public function testSettersAndGetters() { $testAdapter = new Test(array('domain' => 'toast')); $key = 'MyTestKey'; $file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid(); file_put_contents($file, 'test data'); $testFile = new File(array('key' => $key, 'file' => $file)); $result = $testAdapter->saveFile($key, $testFile->getFile()); unlink($file); $this->assertArrayHasKey('fid', $result); $this->assertArrayHasKey('paths', $result); $this->assertArrayHasKey('key', $result); $this->assertArrayHasKey('class', $result); $this->assertArrayHasKey('domain', $result); $this->assertNull($testAdapter->rename($key, $key . '2')); $this->assertNull($testAdapter->delete($key)); }
/** * * 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; }