2
0

SqliteBackendTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * @package Zend_Cache
  4. * @subpackage UnitTests
  5. */
  6. /**
  7. * Zend_Cache
  8. */
  9. require_once 'Zend/Cache.php';
  10. require_once 'Zend/Cache/Backend/Sqlite.php';
  11. /**
  12. * Common tests for backends
  13. */
  14. require_once 'CommonExtendedBackendTest.php';
  15. /**
  16. * PHPUnit test case
  17. */
  18. require_once 'PHPUnit/Framework/TestCase.php';
  19. /**
  20. * @package Zend_Cache
  21. * @subpackage UnitTests
  22. */
  23. class Zend_Cache_sqliteBackendTest extends Zend_Cache_CommonExtendedBackendTest {
  24. protected $_instance;
  25. private $_cache_dir;
  26. public function __construct($name = null, array $data = array(), $dataName = '')
  27. {
  28. parent::__construct('Zend_Cache_Backend_Sqlite', $data, $dataName);
  29. }
  30. public function setUp($notag = false)
  31. {
  32. @mkdir($this->getTmpDir());
  33. $this->_cache_dir = $this->getTmpDir() . DIRECTORY_SEPARATOR;
  34. $this->_instance = new Zend_Cache_Backend_Sqlite(array(
  35. 'cache_db_complete_path' => $this->_cache_dir . 'cache.db'
  36. ));
  37. parent::setUp($notag);
  38. }
  39. public function tearDown()
  40. {
  41. parent::tearDown();
  42. unset($this->_instance);
  43. @unlink($this->_cache_dir . 'cache.db');
  44. $this->rmdir();
  45. }
  46. public function testConstructorCorrectCall()
  47. {
  48. $test = new Zend_Cache_Backend_Sqlite(array('cache_db_complete_path' => $this->_cache_dir . 'cache.db'));
  49. }
  50. public function testConstructorWithABadDBPath()
  51. {
  52. try {
  53. $test = new Zend_Cache_Backend_Sqlite(array('cache_db_complete_path' => '/foo/bar/lfjlqsdjfklsqd/cache.db'));
  54. } catch (Zend_Cache_Exception $e) {
  55. return;
  56. }
  57. $this->fail('Zend_Cache_Exception was expected but not thrown');
  58. }
  59. public function testCleanModeAllWithVacuum()
  60. {
  61. $this->_instance = new Zend_Cache_Backend_Sqlite(array(
  62. 'cache_db_complete_path' => $this->_cache_dir . 'cache.db',
  63. 'automatic_vacuum_factor' => 1
  64. ));
  65. parent::setUp();
  66. $this->assertTrue($this->_instance->clean('all'));
  67. $this->assertFalse($this->_instance->test('bar'));
  68. $this->assertFalse($this->_instance->test('bar2'));
  69. }
  70. public function testRemoveCorrectCallWithVacuum()
  71. {
  72. $this->_instance = new Zend_Cache_Backend_Sqlite(array(
  73. 'cache_db_complete_path' => $this->_cache_dir . 'cache.db',
  74. 'automatic_vacuum_factor' => 1
  75. ));
  76. parent::setUp();
  77. $this->assertTrue($this->_instance->remove('bar'));
  78. $this->assertFalse($this->_instance->test('bar'));
  79. $this->assertFalse($this->_instance->remove('barbar'));
  80. $this->assertFalse($this->_instance->test('barbar'));
  81. }
  82. }