MemoryTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Memory
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Memory_MemoryTest::main');
  24. }
  25. /** Zend_Memory */
  26. require_once 'Zend/Memory.php';
  27. /**
  28. * @category Zend
  29. * @package Zend_Memory
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. * @group Zend_Memory
  34. */
  35. class Zend_Memory_MemoryTest extends PHPUnit_Framework_TestCase
  36. {
  37. public static function main()
  38. {
  39. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  40. $result = PHPUnit_TextUI_TestRunner::run($suite);
  41. }
  42. public function setUp()
  43. {
  44. $tmpDir = sys_get_temp_dir() . '/zend_memory';
  45. $this->_removeCacheDir($tmpDir);
  46. mkdir($tmpDir);
  47. $this->cacheDir = $tmpDir;
  48. }
  49. protected function _removeCacheDir($dir)
  50. {
  51. if (!file_exists($dir)) {
  52. return true;
  53. }
  54. if (!is_dir($dir) || is_link($dir)) {
  55. return unlink($dir);
  56. }
  57. foreach (scandir($dir) as $item) {
  58. if ($item == '.' || $item == '..') {
  59. continue;
  60. }
  61. $this->_removeCacheDir($dir . '/' . $item);
  62. }
  63. return rmdir($dir);
  64. }
  65. /**
  66. * tests the Memory Manager creation
  67. *
  68. */
  69. public function testCreation()
  70. {
  71. /** 'None' backend */
  72. $memoryManager = Zend_Memory::factory('None');
  73. $this->assertTrue($memoryManager instanceof Zend_Memory_Manager);
  74. unset($memoryManager);
  75. /** 'File' backend */
  76. $backendOptions = array('cache_dir' => $this->cacheDir); // Directory where to put the cache files
  77. $memoryManager = Zend_Memory::factory('File', $backendOptions);
  78. $this->assertTrue($memoryManager instanceof Zend_Memory_Manager);
  79. unset($memoryManager);
  80. }
  81. /**
  82. * @group ZF-9883
  83. * @dataProvider Zend_Memory_MemoryTest::providerCacheBackend
  84. */
  85. public function testFactoryCacheBackendStandards($backend)
  86. {
  87. try {
  88. $memoryManager = Zend_Memory::factory($backend);
  89. } catch(Zend_Cache_Exception $exception) {
  90. $this->markTestSkipped($exception->getMessage());
  91. }
  92. $this->assertTrue($memoryManager instanceof Zend_Memory_Manager);
  93. }
  94. /**
  95. * @group ZF-9883
  96. */
  97. public function providerCacheBackend()
  98. {
  99. return array(
  100. array('Apc'),
  101. array('File'),
  102. array('Libmemcached'),
  103. array('Memcached'),
  104. array('Sqlite'),
  105. array('TwoLevels'),
  106. array('Xcache'),
  107. array('ZendPlatform'),
  108. array('ZendServer_Disk'),
  109. array('ZendServer_ShMem')
  110. );
  111. }
  112. }
  113. if (PHPUnit_MAIN_METHOD == 'Zend_Memory_MemoryTest::main') {
  114. Zend_Memory_MemoryTest::main();
  115. }