Example #1
0
 public function testResponseStreamSetterRejectsInvalidValues()
 {
     $this->setExpectedException('\\InvalidArgumentException', 'Response stream need to be resource or null');
     $this->subjectUnderTest->setResponseStream('resource');
 }
Example #2
0
 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}");
     }
 }