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');
33 public function testDumpBackupsFileIfExisting()
35 $tempDir = sys_get_temp_dir();
36 $file = $tempDir.'/messages.en.concrete';
37 $backupFile = $file.'~';
41 $catalogue = new MessageCatalogue('en');
42 $catalogue->add(array('foo' => 'bar'));
44 $dumper = new ConcreteFileDumper();
45 $dumper->dump($catalogue, array('path' => $tempDir));
47 $this->assertFileExists($backupFile);
53 public function testDumpCreatesNestedDirectoriesAndFile()
55 $tempDir = sys_get_temp_dir();
56 $translationsDir = $tempDir.'/test/translations';
57 $file = $translationsDir.'/messages.en.concrete';
59 $catalogue = new MessageCatalogue('en');
60 $catalogue->add(array('foo' => 'bar'));
62 $dumper = new ConcreteFileDumper();
63 $dumper->setRelativePathTemplate('test/translations/%domain%.%locale%.%extension%');
64 $dumper->dump($catalogue, array('path' => $tempDir));
66 $this->assertFileExists($file);
69 @rmdir($translationsDir);
73 class ConcreteFileDumper extends FileDumper
75 public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
80 protected function getExtension()