TranslationWriterTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 testWrite()
  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->write(new MessageCatalogue('en'), 'test');
  26. }
  27. /**
  28. * @group legacy
  29. */
  30. public function testDisableBackup()
  31. {
  32. $nonBackupDumper = new NonBackupDumper();
  33. $backupDumper = new BackupDumper();
  34. $writer = new TranslationWriter();
  35. $writer->addDumper('non_backup', $nonBackupDumper);
  36. $writer->addDumper('backup', $backupDumper);
  37. $writer->disableBackup();
  38. $this->assertFalse($backupDumper->backup, 'backup can be disabled if setBackup() method does exist');
  39. }
  40. }
  41. class NonBackupDumper implements DumperInterface
  42. {
  43. public function dump(MessageCatalogue $messages, $options = [])
  44. {
  45. }
  46. }
  47. class BackupDumper implements DumperInterface
  48. {
  49. public $backup = true;
  50. public function dump(MessageCatalogue $messages, $options = [])
  51. {
  52. }
  53. public function setBackup($backup)
  54. {
  55. $this->backup = $backup;
  56. }
  57. }