/**
  * @return mixed
  */
 protected function buildContainer(ContainerBuilder $container)
 {
     $cacheDir = THELIA_CACHE_DIR . "test";
     if (!is_dir($cacheDir)) {
         mkdir($cacheDir);
     }
     $archiveBuilders = [new ZipArchiveBuilder(), new TarArchiveBuilder(), new TarBz2ArchiveBuilder(), new TarGzArchiveBuilder()];
     $archiveBuilderManager = new ArchiveBuilderManager("test");
     /**
      * @var \Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder $archiveBuilder
      */
     foreach ($archiveBuilders as $key => $archiveBuilder) {
         if (!$archiveBuilder->isAvailable()) {
             unset($archiveBuilders[$key]);
         } else {
             $archiveBuilderManager->add($archiveBuilder);
         }
     }
     if (empty($archiveBuilders)) {
         $this->markTestSkipped("You don't have any archive builder, you can't run this test");
     }
     $container->set("thelia.manager.archive_builder_manager", $archiveBuilderManager);
     $formatterManager = (new FormatterManager())->add(new XMLFormatter())->add(new JsonFormatter())->add(new CSVFormatter());
     $container->set("thelia.manager.formatter_manager", $formatterManager);
 }
示例#2
0
 public function retrieveFormatTools($fileName, ImportHandler $handler, FormatterManager $formatterManager, ArchiveBuilderManager $archiveBuilderManager)
 {
     $nameLength = strlen($fileName);
     $types = $handler->getHandledTypes();
     $formats = $formatterManager->getExtensionsByTypes($types, true) + $archiveBuilderManager->getExtensions(true);
     $uploadFormat = null;
     /** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter $formatter */
     $formatter = null;
     /** @var \Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder $archiveBuilder */
     $archiveBuilder = null;
     foreach ($formats as $objectName => $format) {
         $formatLength = strlen($format);
         $formatExtension = substr($fileName, -$formatLength);
         if ($nameLength >= $formatLength && $formatExtension === $format) {
             $uploadFormat = $format;
             try {
                 $formatter = $formatterManager->get($objectName);
             } catch (\OutOfBoundsException $e) {
             }
             try {
                 $archiveBuilder = $archiveBuilderManager->get($objectName);
             } catch (\OutOfBoundsException $e) {
             }
             break;
         }
     }
     $this->checkFileExtension($fileName, $uploadFormat);
     return array("formatter" => $formatter, "archive_builder" => $archiveBuilder, "extension" => $uploadFormat, "types" => $types);
 }
 /**
  * @expectedException \OutOfBoundsException
  */
 public function testDeleteNotExistingArchiveBuilder()
 {
     $this->manager->delete("foo");
 }