コード例 #1
0
 function it_downloads_an_album(Grab $grab, Filesystem $filesystem, RemoteResourceClient $remoteResourceClient, EventDispatcherInterface $eventDispatcher)
 {
     $grab->getImageUrls()->willReturn(['http://fb.me/photo/1.jpg', 'http://fb.me/photo/2.jpg']);
     $grab->getSavePath()->willReturn('/tmp');
     $filesystem->exists('/tmp')->willReturn(false);
     $filesystem->mkdir('/tmp')->shouldBeCalled();
     $remoteResourceClient->getResource('http://fb.me/photo/1.jpg')->willReturn('IMAGEBLOB_1');
     $remoteResourceClient->getResource('http://fb.me/photo/2.jpg')->willReturn('IMAGEBLOB_2');
     $filesystem->dumpFile('/tmp/1.jpg', 'IMAGEBLOB_1')->shouldBeCalled();
     $filesystem->dumpFile('/tmp/2.jpg', 'IMAGEBLOB_2')->shouldBeCalled();
     $eventDispatcher->dispatch('albumgrab.download_and_save', new DownloadAndSaveEvent('/tmp/1.jpg'))->shouldBeCalled();
     $eventDispatcher->dispatch('albumgrab.download_and_save', new DownloadAndSaveEvent('/tmp/2.jpg'))->shouldBeCalled();
     $this->download($grab);
 }
コード例 #2
0
 /**
  * @param Grab $grab
  *
  * @throws IOExceptionInterface if the save directory cannot be created.
  */
 private function prepareDirectory(Grab $grab)
 {
     if (!$this->filesystem->exists($grab->getSavePath())) {
         $this->filesystem->mkdir($grab->getSavePath());
     }
 }