4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\Tests\Dumper;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Translation\MessageCatalogue;
16 use Symfony\Component\Translation\Dumper\FileDumper;
18 class FileDumperTest extends TestCase
20 public function testDump()
22 $tempDir = sys_get_temp_dir();
24 $catalogue = new MessageCatalogue('en');
25 $catalogue->add(array('foo' => 'bar'));
27 $dumper = new ConcreteFileDumper();
28 $dumper->dump($catalogue, array('path' => $tempDir));
30 $this->assertFileExists($tempDir.'/messages.en.concrete');
36 public function testDumpBackupsFileIfExisting()
38 $tempDir = sys_get_temp_dir();
39 $file = $tempDir.'/messages.en.concrete';
40 $backupFile = $file.'~';
44 $catalogue = new MessageCatalogue('en');
45 $catalogue->add(array('foo' => 'bar'));
47 $dumper = new ConcreteFileDumper();
48 $dumper->dump($catalogue, array('path' => $tempDir));
50 $this->assertFileExists($backupFile);
56 public function testDumpCreatesNestedDirectoriesAndFile()
58 $tempDir = sys_get_temp_dir();
59 $translationsDir = $tempDir.'/test/translations';
60 $file = $translationsDir.'/messages.en.concrete';
62 $catalogue = new MessageCatalogue('en');
63 $catalogue->add(array('foo' => 'bar'));
65 $dumper = new ConcreteFileDumper();
66 $dumper->setRelativePathTemplate('test/translations/%domain%.%locale%.%extension%');
67 $dumper->dump($catalogue, array('path' => $tempDir));
69 $this->assertFileExists($file);
72 @rmdir($translationsDir);
76 class ConcreteFileDumper extends FileDumper
78 public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
83 protected function getExtension()