/**
  * Tests that unzipping is not skipped when target exists but is older than zip.
  */
 public function testDontSkipUnzip()
 {
     $transformer = $this->getMockBuilder(UnzipTransformer::class)->setMethods(['unzip'])->setConstructorArgs([[$this->filename], __DIR__])->getMock();
     $this->collection->addTransformer($transformer);
     // put the to be extracted file in the target dir
     file_put_contents(__DIR__ . '/' . $this->filename, $this->fileContents);
     // wait 1 second and touch the zip file
     sleep(1);
     touch($this->zipFilename);
     // unzip should be called when transforming
     $transformer->expects($this->once())->method('unzip');
     $this->collection->shift();
 }
 /**
  * @inheritdoc
  */
 public function transform(ResourceInterface $resource, ResourceCollection $collection)
 {
     // break up again
     $files = $this->breakup($resource);
     $resources = [];
     foreach ($files as $file) {
         $transport = FileTransport::create($file);
         $transport->setDestination($file);
         $resources[] = new FileResource($transport);
         if ($this->maxParts > 0 && sizeof($resources) >= $this->maxParts) {
             break;
         }
     }
     $collection->unshiftAll($resources);
     return $collection->shift();
 }
 /**
  *
  */
 protected function createNextReader()
 {
     if ($this->resource) {
         // end existing resource first
         $this->eventDispatcher->dispatch(FeedEvents::RESOURCE_END, new ResourceEvent($this->resource, $this->resources));
     }
     if ($this->resources->isEmpty()) {
         return;
     }
     // get the next resource
     $this->resource = $this->resources->shift();
     // dispatch start event
     $this->eventDispatcher->dispatch(FeedEvents::RESOURCE_START, new ResourceEvent($this->resource, $this->resources));
     // create a reader for this new resource
     $this->createReader($this->resource);
 }
 /**
  * @inheritdoc
  */
 public function transform(ResourceInterface $resource, ResourceCollection $collection)
 {
     if ($this->needsUnzipping($resource)) {
         $this->unzip($resource);
     }
     $resources = [];
     foreach ($this->files as $file) {
         $targetFile = $this->getTargetFile($resource, $file);
         if (!file_exists($targetFile)) {
             throw new TransportException(sprintf('File "%s" was not found in the archive', $targetFile));
         }
         $transport = FileTransport::create($targetFile);
         $transport->setDestinationDir($this->getTargetDir($resource));
         $resources[] = new FileResource($transport);
     }
     $collection->unshiftAll($resources);
     return $collection->shift();
 }