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']);
 }
 /**
  * @return Import
  *
  * @throws InvalidConfigurationException
  */
 public function build(ImportConfiguration $importConfiguration, StorageInterface $sourceStorage = null, $createdBy = null, $requestContext = null)
 {
     $importer = $this->importerRepository->get($importConfiguration->getImporterId());
     if ($importer->getSourceStorage()) {
         $sourceStorage = $importer->getSourceStorage();
     } elseif (!$sourceStorage) {
         throw new InvalidConfigurationException("Either the importRequest or the importer '" . $importConfiguration->getImporterId() . "' must have a source storage set.");
     }
     $importRun = $importConfiguration->toRun($createdBy);
     //apply static context from importer & request
     $context = $requestContext;
     if (!is_null($importer->getContext()) && !empty($importer->getContext())) {
         $importerContext = $importer->getContext();
         if ($importerContext && $requestContext) {
             $context = array_merge($importerContext, $requestContext);
         } else {
             $context = $importerContext;
         }
     }
     $importRun->setContext($context);
     $import = $this->factorImport($importer, $sourceStorage, $importRun);
     //after everthing was build, apply softdata from sourcestorage to importrun
     //dont do this any earlier, as there might be AFTER_BUILD hooks, that may change
     //the sourcestorage configuration
     $importRun->setInfo((array) $sourceStorage->info());
     return $import;
 }
 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;
     });
 }