public function testXlsx() { $format = new ExcelFormat(); $localFile = new LocalFileStorage(new \SplFileObject(__DIR__ . '/../../../../metadata/testfiles/flatdata-excel-xml.xlsx'), $format); $reader = $localFile->reader(); $info = $localFile->info(); $this->assertEquals(new StorageInfo(array('name' => 'flatdata-excel-xml.xlsx', 'format' => $format, 'size' => 8895, 'count' => 2, 'hash' => 'b297aa9bbc37f9cd51d8472498772474')), $info); $headers = $reader->getColumnHeaders(); $this->assertEquals(2, count($headers)); }
/** * @dataProvider getStorages * @medium */ public function testImport($sourceFile, Format $format, Format $targetFormat = null) { if (!$targetFormat) { $targetFormat = $format; } $targetFile = tempnam('/tmp', 'test'); @unlink($targetFile); $sourceStorage = new LocalFileStorage(new \SplFileInfo($sourceFile), $format); $targetStorage = new LocalFileStorage(new \SplFileInfo($targetFile), $targetFormat); $this->assertEquals(new StorageInfo(array('name' => basename($targetFile), 'hash' => null, 'format' => $targetFormat, 'size' => 0, 'count' => 0)), $targetStorage->info()); $importer = Importer::build($targetStorage); $importConfiguration = new ImportConfiguration(); $importRun = $importConfiguration->toRun(); $import = Import::build($importer, $sourceStorage, $importRun); $importRunner = new ImportRunner(); $importRunner->run($import); $this->assertFileExists($targetFile); if ($format instanceof XmlFormat) { $this->assertXmlFileEqualsXmlFile($sourceFile, $targetFile); } elseif ($format instanceof CsvFormat) { $this->assertFileEquals($sourceFile, $targetFile); } }
public function testGetAvailableFormats() { $storage = new LocalFileStorage(new \SplFileObject('tests/metadata/testfiles/100.csv'), new CsvFormat()); $this->assertEquals(['csv', 'excel', 'xml', 'json', 'zlib'], $storage->getAvailableFormats()); }