MemcachedTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. /**
  10. * @group Memcache
  11. * @group Memcached
  12. */
  13. class MemcachedTest extends Cache {
  14. public static function setUpBeforeClass(): void {
  15. parent::setUpBeforeClass();
  16. if (!\OC\Memcache\Memcached::isAvailable()) {
  17. self::markTestSkipped('The memcached extension is not available.');
  18. }
  19. $instance = new \OC\Memcache\Memcached(self::getUniqueID());
  20. if ($instance->set(self::getUniqueID(), self::getUniqueID()) === false) {
  21. self::markTestSkipped('memcached server seems to be down.');
  22. }
  23. }
  24. protected function setUp(): void {
  25. parent::setUp();
  26. $this->instance = new \OC\Memcache\Memcached($this->getUniqueID());
  27. }
  28. public function testClear() {
  29. // Memcached is sometimes broken with clear(), so we don't test it thoroughly
  30. $value = 'ipsum lorum';
  31. $this->instance->set('1_value1', $value);
  32. $this->instance->set('1_value2', $value);
  33. $this->instance->set('2_value1', $value);
  34. $this->instance->set('3_value1', $value);
  35. $this->assertTrue($this->instance->clear('1_'));
  36. $this->assertFalse($this->instance->hasKey('1_value1'));
  37. $this->assertFalse($this->instance->hasKey('1_value2'));
  38. //$this->assertTrue($this->instance->hasKey('2_value1'));
  39. //$this->assertTrue($this->instance->hasKey('3_value1'));
  40. $this->assertTrue($this->instance->clear());
  41. $this->assertFalse($this->instance->hasKey('1_value1'));
  42. $this->assertFalse($this->instance->hasKey('1_value2'));
  43. $this->assertFalse($this->instance->hasKey('2_value1'));
  44. $this->assertFalse($this->instance->hasKey('3_value1'));
  45. }
  46. }