SqliteBackendTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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-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. /**
  23. * Zend_Cache
  24. */
  25. require_once 'Zend/Cache.php';
  26. require_once 'Zend/Cache/Backend/Sqlite.php';
  27. /**
  28. * Common tests for backends
  29. */
  30. require_once 'CommonExtendedBackendTest.php';
  31. /**
  32. * @category Zend
  33. * @package Zend_Cache
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @group Zend_Cache
  38. */
  39. class Zend_Cache_sqliteBackendTest extends Zend_Cache_CommonExtendedBackendTest {
  40. protected $_instance;
  41. private $_cache_dir;
  42. public function __construct($name = null, array $data = array(), $dataName = '')
  43. {
  44. parent::__construct('Zend_Cache_Backend_Sqlite', $data, $dataName);
  45. }
  46. public function setUp($notag = false)
  47. {
  48. @mkdir($this->getTmpDir());
  49. $this->_cache_dir = $this->getTmpDir() . DIRECTORY_SEPARATOR;
  50. $this->_instance = new Zend_Cache_Backend_Sqlite(array(
  51. 'cache_db_complete_path' => $this->_cache_dir . 'cache.db'
  52. ));
  53. parent::setUp($notag);
  54. }
  55. public function tearDown()
  56. {
  57. parent::tearDown();
  58. unset($this->_instance);
  59. @unlink($this->_cache_dir . 'cache.db');
  60. $this->rmdir();
  61. }
  62. public function testConstructorCorrectCall()
  63. {
  64. $test = new Zend_Cache_Backend_Sqlite(array('cache_db_complete_path' => $this->_cache_dir . 'cache.db'));
  65. }
  66. public function testConstructorWithABadDBPath()
  67. {
  68. try {
  69. $test = new Zend_Cache_Backend_Sqlite(array('cache_db_complete_path' => '/foo/bar/lfjlqsdjfklsqd/cache.db'));
  70. } catch (Zend_Cache_Exception $e) {
  71. return;
  72. }
  73. $this->fail('Zend_Cache_Exception was expected but not thrown');
  74. }
  75. public function testCleanModeAllWithVacuum()
  76. {
  77. $this->_instance = new Zend_Cache_Backend_Sqlite(array(
  78. 'cache_db_complete_path' => $this->_cache_dir . 'cache.db',
  79. 'automatic_vacuum_factor' => 1
  80. ));
  81. parent::setUp();
  82. $this->assertTrue($this->_instance->clean('all'));
  83. $this->assertFalse($this->_instance->test('bar'));
  84. $this->assertFalse($this->_instance->test('bar2'));
  85. }
  86. public function testRemoveCorrectCallWithVacuum()
  87. {
  88. $this->_instance = new Zend_Cache_Backend_Sqlite(array(
  89. 'cache_db_complete_path' => $this->_cache_dir . 'cache.db',
  90. 'automatic_vacuum_factor' => 1
  91. ));
  92. parent::setUp();
  93. $this->assertTrue($this->_instance->remove('bar'));
  94. $this->assertFalse($this->_instance->test('bar'));
  95. $this->assertFalse($this->_instance->remove('barbar'));
  96. $this->assertFalse($this->_instance->test('barbar'));
  97. }
  98. /**
  99. * @group ZF-11640
  100. */
  101. public function testRemoveCorrectCallWithVacuumOnMemoryDb()
  102. {
  103. $this->_instance = new Zend_Cache_Backend_Sqlite(array(
  104. 'cache_db_complete_path' => ':memory:',
  105. 'automatic_vacuum_factor' => 1
  106. ));
  107. parent::setUp();
  108. $this->assertGreaterThan(0, $this->_instance->test('bar2'));
  109. $this->assertTrue($this->_instance->remove('bar'));
  110. $this->assertFalse($this->_instance->test('bar'));
  111. $this->assertGreaterThan(0, $this->_instance->test('bar2'));
  112. }
  113. }