RedisTest.php 1.2 KB

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