FileDumperTest.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Translation\Tests\Dumper;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Translation\MessageCatalogue;
  13. use Symfony\Component\Translation\Dumper\FileDumper;
  14. class FileDumperTest extends TestCase
  15. {
  16. public function testDump()
  17. {
  18. $tempDir = sys_get_temp_dir();
  19. $catalogue = new MessageCatalogue('en');
  20. $catalogue->add(array('foo' => 'bar'));
  21. $dumper = new ConcreteFileDumper();
  22. $dumper->dump($catalogue, array('path' => $tempDir));
  23. $this->assertFileExists($tempDir.'/messages.en.concrete');
  24. @unlink($tempDir.'/messages.en.concrete');
  25. }
  26. public function testDumpCreatesNestedDirectoriesAndFile()
  27. {
  28. $tempDir = sys_get_temp_dir();
  29. $translationsDir = $tempDir.'/test/translations';
  30. $file = $translationsDir.'/messages.en.concrete';
  31. $catalogue = new MessageCatalogue('en');
  32. $catalogue->add(array('foo' => 'bar'));
  33. $dumper = new ConcreteFileDumper();
  34. $dumper->setRelativePathTemplate('test/translations/%domain%.%locale%.%extension%');
  35. $dumper->dump($catalogue, array('path' => $tempDir));
  36. $this->assertFileExists($file);
  37. @unlink($file);
  38. @rmdir($translationsDir);
  39. }
  40. }
  41. class ConcreteFileDumper extends FileDumper
  42. {
  43. public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
  44. {
  45. return '';
  46. }
  47. protected function getExtension()
  48. {
  49. return 'concrete';
  50. }
  51. }