RedisTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 Redis
  12. */
  13. class RedisTest extends Cache {
  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. }