MemoryTest.php 2.7 KB

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