SQLite3CacheTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Doctrine\Tests\Common\Cache;
  3. use Doctrine\Common\Cache\Cache;
  4. use Doctrine\Common\Cache\SQLite3Cache;
  5. use SQLite3;
  6. class SQLite3Test extends CacheTest
  7. {
  8. /**
  9. * @var SQLite3
  10. */
  11. private $file, $sqlite;
  12. protected function setUp()
  13. {
  14. if ( ! extension_loaded('sqlite3')) {
  15. $this->markTestSkipped('The ' . __CLASS__ .' requires the use of SQLite3');
  16. }
  17. $this->file = tempnam(null, 'doctrine-cache-test-');
  18. unlink($this->file);
  19. $this->sqlite = new SQLite3($this->file);
  20. }
  21. protected function tearDown()
  22. {
  23. $this->sqlite = null; // DB must be closed before
  24. unlink($this->file);
  25. }
  26. public function testGetStats()
  27. {
  28. $this->assertNull($this->_getCacheDriver()->getStats());
  29. }
  30. public function testFetchSingle()
  31. {
  32. $id = uniqid('sqlite3_id_');
  33. $data = "\0"; // produces null bytes in serialized format
  34. $this->_getCacheDriver()->save($id, $data, 30);
  35. $this->assertEquals($data, $this->_getCacheDriver()->fetch($id));
  36. }
  37. protected function _getCacheDriver()
  38. {
  39. return new SQLite3Cache($this->sqlite, 'test_table');
  40. }
  41. }