RedisTest.php 1.4 KB

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