/**
  * @param string[] $files Catalog configuration files to load
  *
  * @throws \Exception
  */
 protected function loadCatalog($files)
 {
     // prepare replace paths to use Behat catalog paths and not the minimal fixtures path, please note that we can
     // have several files per job in case of Enterprise Catalog, for instance,
     // [
     //     'jobs' => [
     //         "/project/features/Context/catalog/footwear/jobs.yml"
     //         "/project/features/PimEnterprise/Behat/Context/../../../Context/catalog/footwear/jobs.yml"
     // ]
     $replacePaths = [];
     foreach ($files as $file) {
         $tokens = explode(DIRECTORY_SEPARATOR, $file);
         $fileName = array_pop($tokens);
         if (!isset($replacePaths[$fileName])) {
             $replacePaths[$fileName] = [];
         }
         $replacePaths[$fileName][] = $file;
     }
     // configure and load job instances in database
     $this->getFixtureJobLoader()->loadJobInstances($replacePaths);
     // setup application to be able to run akeneo:batch:job command
     $application = new Application();
     $application->add(new BatchCommand());
     $batchJobCommand = $application->find('akeneo:batch:job');
     $batchJobCommand->setContainer($this->getContainer());
     $command = new CommandTester($batchJobCommand);
     // install the catalog via the job instances
     $jobInstances = $this->getFixtureJobLoader()->getLoadedJobInstances();
     foreach ($jobInstances as $jobInstance) {
         $exitCode = $command->execute(['command' => $batchJobCommand->getName(), 'code' => $jobInstance->getCode(), '--no-log' => true, '-v' => true]);
         if (0 !== $exitCode) {
             throw new \Exception(sprintf('Catalog not installable! "%s"', $command->getDisplay()));
         }
     }
     // delete the job instances
     $this->getFixtureJobLoader()->deleteJobInstances();
     // install reference data
     $bundles = $this->getContainer()->getParameter('kernel.bundles');
     if (isset($bundles['AcmeAppBundle'])) {
         $referenceDataLoader = new ReferenceDataLoader();
         $referenceDataLoader->load($this->getEntityManager());
     }
     // clear product manager UOW after the install to start the scenario execution with a clean state
     $productObjectManager = $this->getContainer()->get('pim_catalog.object_manager.product');
     $productObjectManager->clear();
     // clear the standard entity manager UOW after the install to start the scenario execution with a clean state
     $standardObjectManager = $this->getContainer()->get('doctrine.orm.entity_manager');
     $standardObjectManager->clear();
 }
 /**
  * @param string[] $files Catalog configuration files to load
  */
 protected function loadCatalog($files)
 {
     $treatedFiles = [];
     foreach ($this->preEntityLoaders as $loaderName => $fileName) {
         $loader = sprintf('%s\\%s', $this->entityLoaderPath, $loaderName);
         $file = $this->getLoaderFile($files, $fileName);
         if ($file) {
             $treatedFiles[] = $file;
         }
         $this->runLoader($loader, $file);
     }
     $files = array_diff($files, $treatedFiles);
     if (count($files)) {
         $this->getContainer()->get('pim_installer.fixture_loader.multiple_loader')->load($this->getEntityManager(), $this->referenceRepository, $files);
     }
     foreach ($this->postEntityLoaders as $loaderName => $fileName) {
         $loader = sprintf('%s\\%s', $this->entityLoaderPath, $loaderName);
         $file = $this->getLoaderFile($files, $fileName);
         if ($file) {
             $treatedFiles[] = $file;
         }
         $this->runLoader($loader, $file);
     }
     $bundles = $this->getContainer()->getParameter('kernel.bundles');
     if (isset($bundles['AcmeAppBundle'])) {
         $referenceDataLoader = new ReferenceDataLoader();
         $referenceDataLoader->load($this->getEntityManager());
     }
 }