MemoryTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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-2010 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. /**
  26. * Test helper
  27. */
  28. require_once dirname(__FILE__) . '/../../TestHelper.php';
  29. /** Zend_Memory */
  30. require_once 'Zend/Memory.php';
  31. /**
  32. * @category Zend
  33. * @package Zend_Memory
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @group Zend_Memory
  38. */
  39. class Zend_Memory_MemoryTest extends PHPUnit_Framework_TestCase
  40. {
  41. public static function main()
  42. {
  43. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  44. $result = PHPUnit_TextUI_TestRunner::run($suite);
  45. }
  46. public function setUp()
  47. {
  48. $tmpDir = sys_get_temp_dir() . '/zend_memory';
  49. $this->_removeCacheDir($tmpDir);
  50. mkdir($tmpDir);
  51. $this->cacheDir = $tmpDir;
  52. }
  53. protected function _removeCacheDir($dir)
  54. {
  55. if (!file_exists($dir)) {
  56. return true;
  57. }
  58. if (!is_dir($dir) || is_link($dir)) {
  59. return unlink($dir);
  60. }
  61. foreach (scandir($dir) as $item) {
  62. if ($item == '.' || $item == '..') {
  63. continue;
  64. }
  65. $this->_removeCacheDir($dir . '/' . $item);
  66. }
  67. return rmdir($dir);
  68. }
  69. /**
  70. * tests the Memory Manager creation
  71. *
  72. */
  73. public function testCreation()
  74. {
  75. /** 'None' backend */
  76. $memoryManager = Zend_Memory::factory('None');
  77. $this->assertTrue($memoryManager instanceof Zend_Memory_Manager);
  78. unset($memoryManager);
  79. /** 'File' backend */
  80. $backendOptions = array('cache_dir' => $this->cacheDir); // Directory where to put the cache files
  81. $memoryManager = Zend_Memory::factory('File', $backendOptions);
  82. $this->assertTrue($memoryManager instanceof Zend_Memory_Manager);
  83. unset($memoryManager);
  84. }
  85. }
  86. if (PHPUnit_MAIN_METHOD == 'Zend_Memory_MemoryTest::main') {
  87. Zend_Memory_MemoryTest::main();
  88. }