baseTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. use Ark\Filecache\FileCache;
  3. class BaseTest extends PHPUnit_Framework_TestCase {
  4. protected $cache;
  5. public function setUp() {
  6. $this->cache = new FileCache([
  7. 'root' => __DIR__ . '/cache',
  8. ]);
  9. }
  10. public function tearDown() {
  11. $this->cache->clear();
  12. // test clear twice
  13. $this->cache->clear();
  14. }
  15. public function testSet() {
  16. $key = __FUNCTION__;
  17. $value = 'hello world';
  18. $this->cache->set($key, $value);
  19. $this->assertEquals($this->cache->get($key), $value);
  20. }
  21. public function testTTL() {
  22. $key = __FUNCTION__;
  23. $value = 'hello world';
  24. $this->cache->set($key, $value, array(
  25. 'ttl' => 2,
  26. ));
  27. $this->assertEquals($this->cache->get($key), $value);
  28. sleep(3);
  29. $this->assertEquals($this->cache->get($key), false);
  30. }
  31. public function testCompress() {
  32. $key = __FUNCTION__;
  33. $value = 'hello world';
  34. $this->cache->set($key, $value, array(
  35. 'compress' => true
  36. ));
  37. $meta = $this->cache->getMeta($key);
  38. $this->assertEquals($meta['compress'], '1');
  39. $this->assertEquals($this->cache->get($key), $value);
  40. }
  41. public function testDelete()
  42. {
  43. $key = __FUNCTION__;
  44. $value = 'hello world';
  45. $this->cache->set($key, $value);
  46. $this->cache->delete($key);
  47. $this->assertEquals($this->cache->get($key), false);
  48. }
  49. }