public function testFilesSavePathAcceptsValidRelativeDirectoryPathAndConvertsItToAbsolute() { $exampleRelative = dirname(__FILE__); $exampleAbsolute = realpath($exampleRelative); $this->subjectUnderTest->setFilesSavePath($exampleRelative); $this->assertSame($exampleAbsolute, $this->subjectUnderTest->getFilesSavePath()); }
private function downloadLinks(array $links) { $this->logger->info('Begin downloading ' . count($links) . ' files...'); foreach ($links as $name => $link) { //TODO check if filename exists! $filePath = $this->appConfiguration->getFilesSavePath() . '/' . $name . '_' . md5(rand()) . '.torrent'; $this->logger->debug("Downloading {$name} => {$link} to {$filePath}"); $fp = @fopen($filePath, 'w'); if (!$fp) { $this->logger->error("Downloading of {$link} failed - unable to create file {$filePath}"); continue; } $request = new Request('GET', $link); $job = new FetchJob($this->appConfiguration, $request); $job->setResponseStream($fp); $this->logger->debug("Executing job for {$link}"); try { if (!$job->execute()) { $this->logger->error("Downloading of {$link} failed - unknown error occurred"); continue; } } catch (\Exception $e) { $type = get_class($e); $this->logger->error("Downloading of {$link} failed - {$type}: " . $e->getMessage()); continue; } fclose($fp); $this->logger->info("Downloaded {$link} to {$filePath}"); } }