MemcachedTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\Memcache;
  8. /**
  9. * @group Memcache
  10. * @group Memcached
  11. */
  12. class MemcachedTest extends Cache {
  13. public static function setUpBeforeClass(): void {
  14. parent::setUpBeforeClass();
  15. if (!\OC\Memcache\Memcached::isAvailable()) {
  16. self::markTestSkipped('The memcached extension is not available.');
  17. }
  18. $instance = new \OC\Memcache\Memcached(self::getUniqueID());
  19. if ($instance->set(self::getUniqueID(), self::getUniqueID()) === false) {
  20. self::markTestSkipped('memcached server seems to be down.');
  21. }
  22. }
  23. protected function setUp(): void {
  24. parent::setUp();
  25. $this->instance = new \OC\Memcache\Memcached($this->getUniqueID());
  26. }
  27. public function testClear(): void {
  28. // Memcached is sometimes broken with clear(), so we don't test it thoroughly
  29. $value = 'ipsum lorum';
  30. $this->instance->set('1_value1', $value);
  31. $this->instance->set('1_value2', $value);
  32. $this->instance->set('2_value1', $value);
  33. $this->instance->set('3_value1', $value);
  34. $this->assertTrue($this->instance->clear('1_'));
  35. $this->assertFalse($this->instance->hasKey('1_value1'));
  36. $this->assertFalse($this->instance->hasKey('1_value2'));
  37. //$this->assertTrue($this->instance->hasKey('2_value1'));
  38. //$this->assertTrue($this->instance->hasKey('3_value1'));
  39. $this->assertTrue($this->instance->clear());
  40. $this->assertFalse($this->instance->hasKey('1_value1'));
  41. $this->assertFalse($this->instance->hasKey('1_value2'));
  42. $this->assertFalse($this->instance->hasKey('2_value1'));
  43. $this->assertFalse($this->instance->hasKey('3_value1'));
  44. }
  45. }