PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/cakesocial.local/app/vendors/zend/tests/Zend/Cache/ClassFrontendTest.php

https://github.com/miamiruby/cakestuff
PHP | 209 lines | 167 code | 23 blank | 19 comment | 2 complexity | dfa36045a6cd7b67582ae4e6c537b1ae MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.0, MIT
  1. <?php
  2. /**
  3. * @package Zend_Cache
  4. * @subpackage UnitTests
  5. */
  6. /**
  7. * Zend_Cache
  8. */
  9. require_once 'Zend/Cache.php';
  10. require_once 'Zend/Cache/Frontend/Class.php';
  11. require_once 'Zend/Cache/Backend/Test.php';
  12. /**
  13. * PHPUnit test case
  14. */
  15. require_once 'PHPUnit/Framework/TestCase.php';
  16. class test {
  17. private $_string = 'hello !';
  18. public static function foobar($param1, $param2) {
  19. echo "foobar_output($param1, $param2)";
  20. return "foobar_return($param1, $param2)";
  21. }
  22. public function foobar2($param1, $param2) {
  23. echo($this->_string);
  24. echo "foobar2_output($param1, $param2)";
  25. return "foobar2_return($param1, $param2)";
  26. }
  27. }
  28. /**
  29. * @package Zend_Cache
  30. * @subpackage UnitTests
  31. */
  32. class Zend_Cache_ClassFrontendTest extends PHPUnit_Framework_TestCase {
  33. private $_instance1;
  34. private $_instance2;
  35. public function setUp()
  36. {
  37. if (!$this->_instance1) {
  38. $options1 = array(
  39. 'cached_entity' => 'test'
  40. );
  41. $this->_instance1 = new Zend_Cache_Frontend_Class($options1);
  42. $this->_backend1 = new Zend_Cache_Backend_Test();
  43. $this->_instance1->setBackend($this->_backend1);
  44. }
  45. if (!$this->_instance2) {
  46. $options2 = array(
  47. 'cached_entity' => new test()
  48. );
  49. $this->_instance2 = new Zend_Cache_Frontend_Class($options2);
  50. $this->_backend2 = new Zend_Cache_Backend_Test();
  51. $this->_instance2->setBackend($this->_backend2);
  52. }
  53. }
  54. public function tearDown()
  55. {
  56. unset($this->_instance1);
  57. unset($this->_instance2);
  58. }
  59. public function testConstructorCorrectCall1()
  60. {
  61. $options = array(
  62. 'cache_by_default' => false,
  63. 'cached_entity' => 'test'
  64. );
  65. $test = new Zend_Cache_Frontend_Class($options);
  66. }
  67. public function testConstructorCorrectCall2()
  68. {
  69. $options = array(
  70. 'cache_by_default' => false,
  71. 'cached_entity' => new test()
  72. );
  73. $test = new Zend_Cache_Frontend_Class($options);
  74. }
  75. public function testConstructorBadCall()
  76. {
  77. $options = array(
  78. 'cache_by_default' => true
  79. );
  80. try {
  81. $test = new Zend_Cache_Frontend_Class($options);
  82. } catch (Zend_Cache_Exception $e) {
  83. return;
  84. }
  85. $this->fail('Zend_Cache_Exception was expected but not thrown');
  86. }
  87. public function testCallCorrectCall1()
  88. {
  89. ob_start();
  90. ob_implicit_flush(false);
  91. $return = $this->_instance1->foobar('param1', 'param2');
  92. $data = ob_get_contents();
  93. ob_end_clean();
  94. ob_implicit_flush(true);
  95. $this->assertEquals('bar', $return);
  96. $this->assertEquals('foo', $data);
  97. }
  98. public function testCallCorrectCall2()
  99. {
  100. ob_start();
  101. ob_implicit_flush(false);
  102. $return = $this->_instance1->foobar('param3', 'param4');
  103. $data = ob_get_contents();
  104. ob_end_clean();
  105. ob_implicit_flush(true);
  106. $this->assertEquals('foobar_return(param3, param4)', $return);
  107. $this->assertEquals('foobar_output(param3, param4)', $data);
  108. }
  109. public function testCallCorrectCall3()
  110. {
  111. ob_start();
  112. ob_implicit_flush(false);
  113. $return = $this->_instance2->foobar2('param1', 'param2');
  114. $data = ob_get_contents();
  115. ob_end_clean();
  116. ob_implicit_flush(true);
  117. $this->assertEquals('bar', $return);
  118. $this->assertEquals('foo', $data);
  119. }
  120. public function testCallCorrectCall4()
  121. {
  122. ob_start();
  123. ob_implicit_flush(false);
  124. $return = $this->_instance2->foobar2('param3', 'param4');
  125. $data = ob_get_contents();
  126. ob_end_clean();
  127. ob_implicit_flush(true);
  128. $this->assertEquals('foobar2_return(param3, param4)', $return);
  129. $this->assertEquals('hello !foobar2_output(param3, param4)', $data);
  130. }
  131. public function testCallCorrectCall5()
  132. {
  133. // cacheByDefault = false
  134. $this->_instance1->setOption('cache_by_default', false);
  135. ob_start();
  136. ob_implicit_flush(false);
  137. $return = $this->_instance1->foobar('param1', 'param2');
  138. $data = ob_get_contents();
  139. ob_end_clean();
  140. ob_implicit_flush(true);
  141. $this->assertEquals('foobar_return(param1, param2)', $return);
  142. $this->assertEquals('foobar_output(param1, param2)', $data);
  143. }
  144. public function testCallCorrectCall6()
  145. {
  146. // cacheByDefault = false
  147. // cachedMethods = array('foobar')
  148. $this->_instance1->setOption('cache_by_default', false);
  149. $this->_instance1->setOption('cached_methods', array('foobar'));
  150. ob_start();
  151. ob_implicit_flush(false);
  152. $return = $this->_instance1->foobar('param1', 'param2');
  153. $data = ob_get_contents();
  154. ob_end_clean();
  155. ob_implicit_flush(true);
  156. $this->assertEquals('bar', $return);
  157. $this->assertEquals('foo', $data);
  158. }
  159. public function testCallCorrectCall7()
  160. {
  161. // cacheByDefault = true
  162. // nonCachedMethods = array('foobar')
  163. $this->_instance1->setOption('cache_by_default', true);
  164. $this->_instance1->setOption('non_cached_methods', array('foobar'));
  165. ob_start();
  166. ob_implicit_flush(false);
  167. $return = $this->_instance1->foobar('param1', 'param2');
  168. $data = ob_get_contents();
  169. ob_end_clean();
  170. ob_implicit_flush(true);
  171. $this->assertEquals('foobar_return(param1, param2)', $return);
  172. $this->assertEquals('foobar_output(param1, param2)', $data);
  173. }
  174. public function testConstructorWithABadCachedEntity()
  175. {
  176. try {
  177. $options = array(
  178. 'cached_entity' => array()
  179. );
  180. $instance = new Zend_Cache_Frontend_Class($options);
  181. } catch (Zend_Cache_Exception $e) {
  182. return;
  183. }
  184. $this->fail('Zend_Cache_Exception was expected but not thrown');
  185. }
  186. }