StreamBufferTest.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. require_once 'Swift/Tests/SwiftUnitTestCase.php';
  3. require_once 'Swift/Transport/StreamBuffer.php';
  4. require_once 'Swift/ReplacementFilterFactory.php';
  5. require_once 'Swift/StreamFilter.php';
  6. class Swift_Transport_StreamBufferTest extends Swift_Tests_SwiftUnitTestCase
  7. {
  8. public function testSettingWriteTranslationsCreatesFilters()
  9. {
  10. $factory = $this->_createFactory();
  11. $this->_checking(Expectations::create()
  12. -> one($factory)->createFilter('a', 'b') -> returns($this->_createFilter())
  13. -> never($factory)
  14. );
  15. $buffer = $this->_createBuffer($factory);
  16. $buffer->setWriteTranslations(array('a' => 'b'));
  17. }
  18. public function testOverridingTranslationsOnlyAddsNeededFilters()
  19. {
  20. $factory = $this->_createFactory();
  21. $this->_checking(Expectations::create()
  22. -> one($factory)->createFilter('a', 'b') -> returns($this->_createFilter())
  23. -> one($factory)->createFilter('x', 'y') -> returns($this->_createFilter())
  24. -> never($factory)
  25. );
  26. $buffer = $this->_createBuffer($factory);
  27. $buffer->setWriteTranslations(array('a' => 'b'));
  28. $buffer->setWriteTranslations(array('x' => 'y', 'a' => 'b'));
  29. }
  30. // -- Creation methods
  31. private function _createBuffer($replacementFactory)
  32. {
  33. return new Swift_Transport_StreamBuffer($replacementFactory);
  34. }
  35. private function _createFactory()
  36. {
  37. return $this->_mock('Swift_ReplacementFilterFactory');
  38. }
  39. private function _createFilter()
  40. {
  41. return $this->_stub('Swift_StreamFilter');
  42. }
  43. }