TranslationWriterTest.php 1.7 KB

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