/** * @medium */ public function testImportExport() { $sourceStorage = new LocalFileStorage(new \SplFileInfo(__DIR__ . '/../../../metadata/testfiles/100.csv'), new CsvFormat()); $targetStorage = new DoctrineStorage(self::$em, 'TestEntities\\Address'); $this->assertEquals(new StorageInfo(['name' => 'SELECT o FROM TestEntities\\Address o', 'count' => 0, 'type' => 'DQL Query']), $targetStorage->info()); $importer = Importer::build($targetStorage); $importConfiguration = new ImportConfiguration(); $importRun = $importConfiguration->toRun(); $import = Import::build($importer, $sourceStorage, $importRun); $eventDispatcher = new EventDispatcher(); $importRunner = new ImportRunner(new DefaultWorkflowFactory($eventDispatcher)); $importRunner->run($import); $entities = self::$em->getRepository('TestEntities\\Address')->findAll(); //import worked $this->assertEquals(100, count($entities)); $exportFile = '/tmp/doctrine_test.csv'; @unlink($exportFile); $sourceStorage = new DoctrineStorage(self::$em, null, self::$em->createQuery("SELECT A FROM TestEntities\\Address A WHERE A.zip LIKE '2%'")); $this->assertEquals(new StorageInfo(['name' => "SELECT A FROM TestEntities\\Address A WHERE A.zip LIKE '2%'", 'count' => 10, 'type' => 'DQL Query']), $sourceStorage->info()); $targetStorage = new LocalFileStorage(new \SplFileInfo($exportFile), new CsvFormat()); $importer = Importer::build($targetStorage); $importConfiguration = new ImportConfiguration(); $importRun = $importConfiguration->toRun(); $import = Import::build($importer, $sourceStorage, $importRun); $eventDispatcher = new EventDispatcher(); $importRunner = new ImportRunner(new DefaultWorkflowFactory($eventDispatcher)); $importRunner->run($import); $this->assertFileExists($exportFile); $this->assertEquals(11, count(file($exportFile))); //+header $this->assertEquals(10, $import->getRun()->toArray()['statistics']['processed']); }
/** * @medium */ public function test() { $sourceStorage = new ServiceStorage(array($this, 'readData')); $targetStorage = new ServiceStorage(array($this, 'writeData')); $importer = Importer::build($targetStorage); $import = Import::build($importer, $sourceStorage); $eventDispatcher = new EventDispatcher(); $importRunner = new ImportRunner(new DefaultWorkflowFactory($eventDispatcher)); $importRunner->run($import); $this->assertEquals(array(array('data1'), array('data2')), $this->dataWritten); }
/** * @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); } }