/** * 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(); }
public function testTransformOnce() { $count = 0; $transformer = new CallbackTransformer(function () use($count) { return new StringResource('bar' . ++$count); }); $resource = new StringResource('foo'); $collection = new ResourceCollection([$resource]); $collection->addTransformer($transformer); $transformed = $collection->pop(); $this->assertSame('bar1', $transformed->getFile()->fgets()); // add the same resource again $collection->push($resource); $transformed = $collection->pop(); $this->assertSame('foo', $transformed->getFile()->fgets(), 'A resource only gets transformed once'); }
/** * @inheritdoc */ public function build(ReaderTypeInterface $type, array $transportConfig, $resourceType, array $options) { $resolver = $this->getOptionsResolver($type); $transport = $this->createTransport($transportConfig, $this->destinationDir, $this->eventDispatcher); $resources = new ResourceCollection([new FileResource($transport)]); $type->build($this, $resolver->resolve($options)); if (isset($this->transformers[$resourceType])) { foreach ($this->transformers[$resourceType] as $transformer) { $resources->addTransformer($transformer); } } switch ($this->readerType) { case self::READER_TYPE_JSONLINES: return new JsonLinesReader($resources, $this->eventDispatcher); break; case self::READER_TYPE_XML: // xml is the default, let it fall through // xml is the default, let it fall through default: return new XmlReader($resources, $this->eventDispatcher); } }