RedisTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. * This file is part of the Stash package.
  4. *
  5. * (c) Robert Hafner <tedivm@tedivm.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Stash\Test\Driver;
  11. /**
  12. * @package Stash
  13. * @author Robert Hafner <tedivm@tedivm.com>
  14. */
  15. class RedisTest extends AbstractDriverTest
  16. {
  17. protected $driverClass = 'Stash\Driver\Redis';
  18. protected $redisServer = '127.0.0.1';
  19. protected $redisPort = '6379';
  20. protected $redisNoServer = '127.0.0.1';
  21. protected $redisNoPort = '6381';
  22. protected $persistence = true;
  23. protected function setUp()
  24. {
  25. if (!$this->setup) {
  26. $this->startTime = time();
  27. $this->expiration = $this->startTime + 3600;
  28. if (!($sock = @fsockopen($this->redisServer, $this->redisPort, $errno, $errstr, 1))) {
  29. $this->markTestSkipped('Redis server unavailable for testing.');
  30. }
  31. fclose($sock);
  32. if ($sock = @fsockopen($this->redisNoServer, $this->redisNoPort, $errno, $errstr, 1)) {
  33. fclose($sock);
  34. $this->markTestSkipped("No server should be listening on {$this->redisNoServer}:{$this->redisNoPort} " .
  35. "so that we can test for exceptions.");
  36. }
  37. if (!$this->getFreshDriver()) {
  38. $this->markTestSkipped('Driver class unsuited for current environment');
  39. }
  40. $this->data['object'] = new \stdClass();
  41. $this->data['large_string'] = str_repeat('apples', ceil(200000 / 6));
  42. }
  43. }
  44. protected function getOptions()
  45. {
  46. return array('servers' => array(
  47. array('server' => $this->redisServer, 'port' => $this->redisPort, 'ttl' => 0.1)
  48. ));
  49. }
  50. protected function getInvalidOptions()
  51. {
  52. return array('servers' => array(
  53. array('server' => $this->redisNoServer, 'port' => $this->redisNoPort, 'ttl' => 0.1)
  54. ));
  55. }
  56. public function testBadDisconnect()
  57. {
  58. if (defined('HHVM_VERSION')) {
  59. $this->markTestSkipped('This test can not run on HHVM as HHVM throws a different set of errors.');
  60. }
  61. $driver = $this->getFreshDriver($this->getInvalidOptions());
  62. $driver->__destruct();
  63. $driver = null;
  64. }
  65. }