TranslationWriterTest.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 = array())
  44. {
  45. }
  46. }
  47. class BackupDumper implements DumperInterface
  48. {
  49. public $backup = true;
  50. public function dump(MessageCatalogue $messages, $options = array())
  51. {
  52. }
  53. public function setBackup($backup)
  54. {
  55. $this->backup = $backup;
  56. }
  57. }