RedisTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. class RedisTest extends Cache {
  10. public static function setUpBeforeClass(): void {
  11. parent::setUpBeforeClass();
  12. if (!\OC\Memcache\Redis::isAvailable()) {
  13. self::markTestSkipped('The redis extension is not available.');
  14. }
  15. if (\OC::$server->getConfig()->getSystemValue('redis', []) === []) {
  16. self::markTestSkipped('Redis not configured in config.php');
  17. }
  18. $errorOccurred = false;
  19. set_error_handler(
  20. function ($errno, $errstr) {
  21. throw new \RuntimeException($errstr, 123456789);
  22. },
  23. E_WARNING
  24. );
  25. $instance = null;
  26. try {
  27. $instance = new \OC\Memcache\Redis(self::getUniqueID());
  28. } catch (\RuntimeException $e) {
  29. $errorOccurred = $e->getCode() === 123456789 ? $e->getMessage() : false;
  30. }
  31. restore_error_handler();
  32. if ($errorOccurred !== false) {
  33. self::markTestSkipped($errorOccurred);
  34. }
  35. if ($instance === null) {
  36. throw new \Exception('redis server is not reachable');
  37. }
  38. if ($instance->set(self::getUniqueID(), self::getUniqueID()) === false) {
  39. self::markTestSkipped('redis server seems to be down.');
  40. }
  41. }
  42. protected function setUp(): void {
  43. parent::setUp();
  44. $this->instance = new \OC\Memcache\Redis($this->getUniqueID());
  45. }
  46. }