Esempio n. 1
0
 public function testFixStrings()
 {
     $file = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'DataFixtures' . DIRECTORY_SEPARATOR . 'test.yml';
     $contents = file($file);
     $this->assertCount(8, $contents);
     $copyFile = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     $copyFile = $copyFile . ltrim(uniqid(), DIRECTORY_SEPARATOR);
     copy($file, $copyFile);
     YamlFixer::fixStrings($copyFile);
     try {
         $result = (bool) Yaml::parse($copyFile);
     } catch (\Exception $e) {
         $result = false;
     }
     $this->assertTrue($result);
     $contents = file($copyFile);
     unlink($copyFile);
     $this->assertCount(7, $contents);
 }
 /**
  * Apply downloaded and extracted language packs to Symfony, in app/Resources dir
  * Returns applied locale codes
  *
  * @param string $locale
  * @param string $sourceDir
  */
 protected function apply($locale, $sourceDir)
 {
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($sourceDir, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
     $catalog = new MessageCatalogue($locale);
     /** @var \SplFileInfo $fileInfo */
     foreach ($iterator as $fileInfo) {
         if ($iterator->getDepth() < 1 || $fileInfo->isDir()) {
             continue;
         }
         // fix bad formatted yaml that may come from third-party service
         YamlFixer::fixStrings($fileInfo->getPathname());
     }
     $this->translationLoader->loadMessages($sourceDir, $catalog);
     $this->databasePersister->persist($locale, $catalog->all());
 }