public function testReFormatFromCsvToJson() { $file = new LocalFile(static::$dir . 'reFormatInput.csv'); $file->setFormat(new CsvFormat(['headerRow' => 1])); $input = <<<CSV "first","second","third" "1","cake","monkies" "2","banana","fish" CSV; $file->write($input); $output = new LocalFile(static::$dir . 'reFormatOutput.json'); $output->setFormat(new JsonFormat(['fileType' => JsonFormat::JSON_FILE_TYPE_EACH_LINE])); $reFormat = new ReFormat(); $reFormat->reFormat($file, null, $output); $expected = <<<JSON {"first":"1","second":"cake","third":"monkies"} {"first":"2","second":"banana","third":"fish"} JSON; static::assertEquals($expected, $output->read()); }
public function testReFormatWithDeleteOldFile() { $file = m::mock(FileNodeInterface::class, FormatAwareInterface::class); $target = m::mock(LocalFileNodeInterface::class, FormatAwareInterface::class); $reader = m::mock(FileReader::class); $this->builder->shouldReceive('build')->with(FileReader::class, $file, null, $this->parserFactory)->andReturn($reader); $writer = m::mock(FileWriter::class); $this->builder->shouldReceive('build')->with(FileWriter::Class, $target, null, $this->formatterFactory)->andReturn($writer); $iterator = new ArrayIterator(['first', 'second']); $reader->shouldReceive('fetch')->andReturn($iterator); $writer->shouldReceive('insertAll')->with($iterator)->once(); $file->shouldReceive('exists')->andReturn(true); $file->shouldReceive('delete')->once(); static::assertSame($target, $this->reFormatter->reFormat($file, null, $target, null, ['keepOldFile' => false])); }