MemoryTest.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. if (file_exists($tmpDir)) {
  49. if (!rmdir($tmpDir)) {
  50. $dir = new DirectoryIterator($tmpDir);
  51. foreach ($dir as $file) {
  52. if (!$file->isDir()) {
  53. unlink($file->getPathname());
  54. }
  55. }
  56. if (!rmdir($tmpDir)) {
  57. throw new Exception('Unable to remove temporary directory ' . $tmpDir
  58. . '; perhaps it has a nested structure?');
  59. }
  60. }
  61. }
  62. mkdir($tmpDir);
  63. $this->cacheDir = $tmpDir;
  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. if (PHPUnit_MAIN_METHOD == 'Zend_Memory_MemoryTest::main') {
  83. Zend_Memory_MemoryTest::main();
  84. }