public function download(MatchedShowCollection $showCollection, $downloadAll = true) { foreach ($showCollection->getCollection() as $show) { foreach ($show->getMatched() as $upstreamShow) { if ($upstreamShow->getType() != $this->downloader->getSupportedType()) { throw new \RunTimeException(sprintf('There is no downloaders for "%s" type', $upstreamShow->getType())); } $this->downloader->download($upstreamShow); $this->showStatus->setMarkAsDownloaded($show->getMineShow()); if (!$downloadAll) { break; } } } }
/** * @dataProvider getDownloadTest */ public function testDownload($i, $downloadAll) { $series = new Series(); $downloadFake = $this->getMock('Series\\Downloader\\DownloadInterface'); $downloadFake->expects($this->exactly($i))->method('getSupportedType')->will($this->returnValue('FAKE')); $downloadFake->expects($this->exactly($i))->method('download'); $series->setDownloader($downloadFake); $statusFake = $this->getMock('Series\\Show\\Status\\StatusInterface'); $statusFake->expects($this->exactly($i))->method('setMarkAsDownloaded'); $series->setShowStatus($statusFake); $show1 = new MineShow('foo', 1.0); $matchedShow1 = new MatchedShow($show1); $matchedShow1->addMatchedShow(new UpstreamShow('foo-1', '1.0')); $matchedShow1->addMatchedShow(new UpstreamShow('foo-2', '1.0')); $matchedShow1->addMatchedShow(new UpstreamShow('foo-3', '1.0')); $matchedShow1->addMatchedShow(new UpstreamShow('foo-4', '1.0')); $showCollection = new MatchedShowCollection(); $showCollection->add($matchedShow1); $series->download($showCollection, $downloadAll); }
public function testMatchedShowCollection() { $matchedShowCollections = new MatchedShowCollection(); $show1 = new MineShow('foo', 1); $matchedShow1 = new MatchedShow($show1); $matchedShowCollections->add($matchedShow1); $this->assertTrue($matchedShowCollections->contains($show1)); $this->assertEquals($matchedShow1, $matchedShowCollections->get($show1)); $show2 = new MineShow('bar', 1); $matchedShow2 = new MatchedShow($show2); $this->assertFalse($matchedShowCollections->contains($show2)); $matchedShowCollections->add($matchedShow2); $this->assertTrue($matchedShowCollections->contains($show2)); $this->assertEquals($matchedShow2, $matchedShowCollections->get($show2)); }