/** * 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'); }
/** * * Download file from MogileFS into a local temp file * @param MogileFS_File $file * @throws Exception */ public function fetchFile(File $file) { if (!$file->isValid()) { throw new Exception(__METHOD__ . ' Cannot fetch file from invalid file model', Exception::INVALID_ARGUMENT); } $localFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $file->getKey(); $fp = fopen($localFile, 'w'); $url = $file->getPaths()[0]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); curl_close($ch); fclose($fp); $file->setFile($localFile); return $file; }