public function test() { $eventDispatcher = new EventDispatcher(); $eventDispatcher->addListener(ImportItemEvent::AFTER_READ, array($this, 'onAfterRead')); $eventDispatcher->addListener(ImportItemEvent::AFTER_FILTER, array($this, 'onAfterFilter')); $eventDispatcher->addListener(ImportItemEvent::AFTER_CONVERSION, array($this, 'onAfterConversion')); $eventDispatcher->addListener(ImportItemEvent::AFTER_CONVERSIONFILTER, array($this, 'onAfterConversionFilter')); $eventDispatcher->addListener(ImportItemEvent::AFTER_WRITE, array($this, 'onAfterWrite')); $fileDir = __DIR__ . '/../../../../../metadata/testfiles'; $finder = Finder::create()->in($fileDir)->name('*'); $lfsp = new FinderFileStorageProvider($finder); $lfsp->setStorageFactory(new FormatDiscoverLocalFileStorageFactory(new MimeTypeDiscoverStrategy(array('text/plain' => new CsvAutoDelimiterFormatFactory())))); $storageLocator = new StorageLocator(); $storageLocator->register('defaultProvider', $lfsp); $array = array(); $targetStorage = new ArrayStorage($array); $importer = Importer::build($targetStorage); $importRepository = new ImporterRepository(); $importRepository->register('defaultImporter', $importer); $importRequest = new ImportRequest($fileDir . '/100.csv', 'defaultProvider', 'defaultImporter'); $importBuilder = new ImportBuilder($importRepository, $storageLocator); $import = $importBuilder->buildFromRequest($importRequest); $import->mappings()->add('prefix', 'Anrede', 'upperCase')->add('name', 'Name', 'lowerCase'); $importRunner = new ImportRunner(new DefaultWorkflowFactory($eventDispatcher)); $expectedResult = array('Name' => 'jennie abernathy', 'Anrede' => 'MS.', 'street' => '866 Hyatt Isle Apt. 888', 'zip' => '65982', 'city' => 'East Laurie', 'phone' => '(551)436-0391', 'email' => '*****@*****.**'); $previewResult = $importRunner->preview($import, 0); $this->assertEquals($expectedResult, $previewResult['to']); }
protected function registerRepository() { $this->app['importengine.importer.repository'] = $this->app->share(function ($app) { $importerRepository = new ImporterRepository(); foreach ($app['config']['edgji/lie::importers'] as $name => $importConfig) { $finder = null; if (array_key_exists('preconditions', $importConfig)) { $finder = $this->generateFinder($importConfig['preconditions']); } $objectFactory = null; if (array_key_exists('object_factory', $importConfig)) { $objectFactory = $this->generateObjectFactory($importConfig['object_factory']); } $importer = $this->generateImporter($importConfig, $objectFactory); $importerRepository->register($name, $importer, $finder); } return $importerRepository; }); }