SimpleKeyCacheInputStreamTest.php 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. require_once 'Swift/Tests/SwiftUnitTestCase.php';
  3. require_once 'Swift/KeyCache/SimpleKeyCacheInputStream.php';
  4. require_once 'Swift/KeyCache.php';
  5. class Swift_KeyCache_SimpleKeyCacheInputStreamTest
  6. extends Swift_Tests_SwiftUnitTestCase
  7. {
  8. private $_nsKey = 'ns1';
  9. public function testStreamWritesToCacheInAppendMode()
  10. {
  11. $cache = $this->_createKeyCache();
  12. $this->_checking(Expectations::create()
  13. -> one($cache)->setString($this->_nsKey, 'foo', 'a', Swift_KeyCache::MODE_APPEND)
  14. -> one($cache)->setString($this->_nsKey, 'foo', 'b', Swift_KeyCache::MODE_APPEND)
  15. -> one($cache)->setString($this->_nsKey, 'foo', 'c', Swift_KeyCache::MODE_APPEND)
  16. );
  17. $stream = new Swift_KeyCache_SimpleKeyCacheInputStream();
  18. $stream->setKeyCache($cache);
  19. $stream->setNsKey($this->_nsKey);
  20. $stream->setItemKey('foo');
  21. $stream->write('a');
  22. $stream->write('b');
  23. $stream->write('c');
  24. }
  25. public function testFlushContentClearsKey()
  26. {
  27. $cache = $this->_createKeyCache();
  28. $this->_checking(Expectations::create()
  29. -> one($cache)->clearKey($this->_nsKey, 'foo')
  30. );
  31. $stream = new Swift_KeyCache_SimpleKeyCacheInputStream();
  32. $stream->setKeyCache($cache);
  33. $stream->setNsKey($this->_nsKey);
  34. $stream->setItemKey('foo');
  35. $stream->flushBuffers();
  36. }
  37. public function testClonedStreamStillReferencesSameCache()
  38. {
  39. $cache = $this->_createKeyCache();
  40. $this->_checking(Expectations::create()
  41. -> one($cache)->setString($this->_nsKey, 'foo', 'a', Swift_KeyCache::MODE_APPEND)
  42. -> one($cache)->setString($this->_nsKey, 'foo', 'b', Swift_KeyCache::MODE_APPEND)
  43. -> one($cache)->setString('test', 'bar', 'x', Swift_KeyCache::MODE_APPEND)
  44. );
  45. $stream = new Swift_KeyCache_SimpleKeyCacheInputStream();
  46. $stream->setKeyCache($cache);
  47. $stream->setNsKey($this->_nsKey);
  48. $stream->setItemKey('foo');
  49. $stream->write('a');
  50. $stream->write('b');
  51. $newStream = clone $stream;
  52. $newStream->setKeyCache($cache);
  53. $newStream->setNsKey('test');
  54. $newStream->setItemKey('bar');
  55. $newStream->write('x');
  56. }
  57. // -- Creation Methods
  58. private function _createKeyCache()
  59. {
  60. return $this->_mock('Swift_KeyCache');
  61. }
  62. }