TranslationWriterTest.php 1.8 KB

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\Writer;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Translation\Dumper\DumperInterface;
  13. use Symfony\Component\Translation\MessageCatalogue;
  14. use Symfony\Component\Translation\Writer\TranslationWriter;
  15. class TranslationWriterTest extends TestCase
  16. {
  17. public function testWriteTranslations()
  18. {
  19. $dumper = $this->getMockBuilder('Symfony\Component\Translation\Dumper\DumperInterface')->getMock();
  20. $dumper
  21. ->expects($this->once())
  22. ->method('dump');
  23. $writer = new TranslationWriter();
  24. $writer->addDumper('test', $dumper);
  25. $writer->writeTranslations(new MessageCatalogue(array()), 'test');
  26. }
  27. public function testDisableBackup()
  28. {
  29. $nonBackupDumper = new NonBackupDumper();
  30. $backupDumper = new BackupDumper();
  31. $writer = new TranslationWriter();
  32. $writer->addDumper('non_backup', $nonBackupDumper);
  33. $writer->addDumper('backup', $backupDumper);
  34. $writer->disableBackup();
  35. $this->assertFalse($backupDumper->backup, 'backup can be disabled if setBackup() method does exist');
  36. }
  37. }
  38. class NonBackupDumper implements DumperInterface
  39. {
  40. public function dump(MessageCatalogue $messages, $options = array())
  41. {
  42. }
  43. }
  44. class BackupDumper implements DumperInterface
  45. {
  46. public $backup = true;
  47. public function dump(MessageCatalogue $messages, $options = array())
  48. {
  49. }
  50. public function setBackup($backup)
  51. {
  52. $this->backup = $backup;
  53. }
  54. }