/cake/tests/cases/libs/cache/apc.test.php

https://github.com/hardsshah/bookmarks · PHP · 140 lines · 61 code · 12 blank · 67 comment · 2 complexity · 9b5305f47274132aae45186779789037 MD5 · raw file

  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * ApcEngineTest file
  5. *
  6. * Long description for file
  7. *
  8. * PHP versions 4 and 5
  9. *
  10. * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  11. * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  12. *
  13. * Licensed under The Open Group Test Suite License
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @filesource
  17. * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  18. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  19. * @package cake
  20. * @subpackage cake.tests.cases.libs.cache
  21. * @since CakePHP(tm) v 1.2.0.5434
  22. * @version $Revision$
  23. * @modifiedby $LastChangedBy$
  24. * @lastmodified $Date$
  25. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  26. */
  27. if (!class_exists('Cache')) {
  28. require LIBS . 'cache.php';
  29. }
  30. /**
  31. * ApcEngineTest class
  32. *
  33. * @package cake
  34. * @subpackage cake.tests.cases.libs.cache
  35. */
  36. class ApcEngineTest extends UnitTestCase {
  37. /**
  38. * skip method
  39. *
  40. * @access public
  41. * @return void
  42. */
  43. function skip() {
  44. $skip = true;
  45. if (Cache::engine('Apc')) {
  46. $skip = false;
  47. }
  48. $this->skipif($skip, 'Apc is not installed or configured properly');
  49. }
  50. /**
  51. * setUp method
  52. *
  53. * @access public
  54. * @return void
  55. */
  56. function setUp() {
  57. Cache::config('apc', array('engine'=>'Apc', 'prefix' => 'cake_'));
  58. }
  59. /**
  60. * tearDown method
  61. *
  62. * @access public
  63. * @return void
  64. */
  65. function tearDown() {
  66. Cache::config('default');
  67. }
  68. /**
  69. * testReadAndWriteCache method
  70. *
  71. * @access public
  72. * @return void
  73. */
  74. function testReadAndWriteCache() {
  75. Cache::set(array('duration' => 1));
  76. $result = Cache::read('test');
  77. $expecting = '';
  78. $this->assertEqual($result, $expecting);
  79. $data = 'this is a test of the emergency broadcasting system';
  80. $result = Cache::write('test', $data);
  81. $this->assertTrue($result);
  82. $result = Cache::read('test');
  83. $expecting = $data;
  84. $this->assertEqual($result, $expecting);
  85. Cache::delete('test');
  86. }
  87. /**
  88. * testExpiry method
  89. *
  90. * @access public
  91. * @return void
  92. */
  93. function testExpiry() {
  94. Cache::set(array('duration' => 1));
  95. $result = Cache::read('test');
  96. $this->assertFalse($result);
  97. $data = 'this is a test of the emergency broadcasting system';
  98. $result = Cache::write('other_test', $data);
  99. $this->assertTrue($result);
  100. sleep(2);
  101. $result = Cache::read('other_test');
  102. $this->assertFalse($result);
  103. Cache::set(array('duration' => "+1 second"));
  104. $data = 'this is a test of the emergency broadcasting system';
  105. $result = Cache::write('other_test', $data);
  106. $this->assertTrue($result);
  107. sleep(2);
  108. $result = Cache::read('other_test');
  109. $this->assertFalse($result);
  110. sleep(2);
  111. $result = Cache::read('other_test');
  112. $this->assertFalse($result);
  113. }
  114. /**
  115. * testDeleteCache method
  116. *
  117. * @access public
  118. * @return void
  119. */
  120. function testDeleteCache() {
  121. $data = 'this is a test of the emergency broadcasting system';
  122. $result = Cache::write('delete_test', $data);
  123. $this->assertTrue($result);
  124. $result = Cache::delete('delete_test');
  125. $this->assertTrue($result);
  126. }
  127. }
  128. ?>