PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Zend/Cache/TwoLevelsBackendTest.php

https://github.com/mridgway/zf2
PHP | 120 lines | 79 code | 13 blank | 28 comment | 1 complexity | 063c2c8272245c74c988eee86bb0b72c MD5 | raw file
  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_Cache
  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. namespace ZendTest\Cache;
  23. use Zend\Cache;
  24. /**
  25. * @category Zend
  26. * @package Zend_Cache
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Cache
  31. */
  32. class TwoLevelsBackendTest extends TestCommonExtendedBackend
  33. {
  34. protected $_instance;
  35. private $_cache_dir;
  36. public function __construct($name = null, array $data = array(), $dataName = '')
  37. {
  38. parent::__construct('Zend\Cache\Backend\TwoLevels', $data, $dataName);
  39. }
  40. public function setUp($notag = false)
  41. {
  42. if (!constant('TESTS_ZEND_CACHE_APC_ENABLED')) {
  43. $this->markTestSkipped('Zend_Cache APC tests not enabled');
  44. }
  45. @mkdir($this->getTmpDir());
  46. $this->_cache_dir = $this->getTmpDir() . DIRECTORY_SEPARATOR;
  47. $slowBackend = 'File';
  48. $fastBackend = 'Apc';
  49. $slowBackendOptions = array(
  50. 'cache_dir' => $this->_cache_dir
  51. );
  52. $fastBackendOptions = array(
  53. );
  54. $this->_instance = new Cache\Backend\TwoLevels(array(
  55. 'fast_backend' => $fastBackend,
  56. 'slow_backend' => $slowBackend,
  57. 'fast_backend_options' => $fastBackendOptions,
  58. 'slow_backend_options' => $slowBackendOptions
  59. ));
  60. parent::setUp($notag);
  61. }
  62. public function tearDown()
  63. {
  64. parent::tearDown();
  65. unset($this->_instance);
  66. }
  67. public function testConstructorCorrectCall()
  68. {
  69. $slowBackend = 'File';
  70. $fastBackend = 'Apc';
  71. $slowBackendOptions = array(
  72. 'cache_dir' => $this->_cache_dir
  73. );
  74. $fastBackendOptions = array(
  75. );
  76. $test = new Cache\Backend\TwoLevels(array(
  77. 'fast_backend' => $fastBackend,
  78. 'slow_backend' => $slowBackend,
  79. 'fast_backend_options' => $fastBackendOptions,
  80. 'slow_backend_options' => $slowBackendOptions
  81. ));
  82. }
  83. public function testSaveOverwritesIfFastIsFull()
  84. {
  85. $slowBackend = 'File';
  86. $fastBackend = $this->getMock('Zend_Cache_Backend_Apc', array('getFillingPercentage'));
  87. $fastBackend->expects($this->at(0))
  88. ->method('getFillingPercentage')
  89. ->will($this->returnValue(0));
  90. $fastBackend->expects($this->at(1))
  91. ->method('getFillingPercentage')
  92. ->will($this->returnValue(90));
  93. $slowBackendOptions = array(
  94. 'cache_dir' => $this->_cache_dir
  95. );
  96. $cache = new Zend_Cache_Backend_TwoLevels(array(
  97. 'fast_backend' => $fastBackend,
  98. 'slow_backend' => $slowBackend,
  99. 'slow_backend_options' => $slowBackendOptions,
  100. 'stats_update_factor' => 1
  101. ));
  102. $id = 'test'.uniqid();
  103. $cache->save(10, $id); //fast usage at 0%
  104. $cache->save(100, $id); //fast usage at 90%
  105. $this->assertEquals(100, $cache->load($id));
  106. }
  107. }