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\Dumper\FileDumper;
16 use Symfony\Component\Translation\MessageCatalogue;
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');
32 @unlink($tempDir.'/messages.en.concrete');
38 public function testDumpBackupsFileIfExisting()
40 $tempDir = sys_get_temp_dir();
41 $file = $tempDir.'/messages.en.concrete';
42 $backupFile = $file.'~';
46 $catalogue = new MessageCatalogue('en');
47 $catalogue->add(array('foo' => 'bar'));
49 $dumper = new ConcreteFileDumper();
50 $dumper->dump($catalogue, array('path' => $tempDir));
52 $this->assertFileExists($backupFile);
58 public function testDumpCreatesNestedDirectoriesAndFile()
60 $tempDir = sys_get_temp_dir();
61 $translationsDir = $tempDir.'/test/translations';
62 $file = $translationsDir.'/messages.en.concrete';
64 $catalogue = new MessageCatalogue('en');
65 $catalogue->add(array('foo' => 'bar'));
67 $dumper = new ConcreteFileDumper();
68 $dumper->setRelativePathTemplate('test/translations/%domain%.%locale%.%extension%');
69 $dumper->dump($catalogue, array('path' => $tempDir));
71 $this->assertFileExists($file);
74 @rmdir($translationsDir);
78 class ConcreteFileDumper extends FileDumper
80 public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
85 protected function getExtension()