RedisTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. public function testScriptHashes() {
  51. foreach (\OC\Memcache\Redis::LUA_SCRIPTS as $script) {
  52. $this->assertEquals(sha1($script[0]), $script[1]);
  53. }
  54. }
  55. }