cache.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\Memcache;
  9. abstract class Cache extends \Test_Cache {
  10. public function testExistsAfterSet() {
  11. $this->assertFalse($this->instance->hasKey('foo'));
  12. $this->instance->set('foo', 'bar');
  13. $this->assertTrue($this->instance->hasKey('foo'));
  14. }
  15. public function testGetAfterSet() {
  16. $this->assertNull($this->instance->get('foo'));
  17. $this->instance->set('foo', 'bar');
  18. $this->assertEquals('bar', $this->instance->get('foo'));
  19. }
  20. public function testGetArrayAfterSet() {
  21. $this->assertNull($this->instance->get('foo'));
  22. $this->instance->set('foo', ['bar']);
  23. $this->assertEquals(['bar'], $this->instance->get('foo'));
  24. }
  25. public function testDoesNotExistAfterRemove() {
  26. $this->instance->set('foo', 'bar');
  27. $this->instance->remove('foo');
  28. $this->assertFalse($this->instance->hasKey('foo'));
  29. }
  30. public function testArrayAccessSet() {
  31. $this->instance['foo'] = 'bar';
  32. $this->assertEquals('bar', $this->instance->get('foo'));
  33. }
  34. public function testArrayAccessGet() {
  35. $this->instance->set('foo', 'bar');
  36. $this->assertEquals('bar', $this->instance['foo']);
  37. }
  38. public function testArrayAccessExists() {
  39. $this->assertFalse(isset($this->instance['foo']));
  40. $this->instance->set('foo', 'bar');
  41. $this->assertTrue(isset($this->instance['foo']));
  42. }
  43. public function testArrayAccessUnset() {
  44. $this->instance->set('foo', 'bar');
  45. unset($this->instance['foo']);
  46. $this->assertFalse($this->instance->hasKey('foo'));
  47. }
  48. protected function tearDown() {
  49. if ($this->instance) {
  50. $this->instance->clear();
  51. }
  52. parent::tearDown();
  53. }
  54. }