RedisArrayTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 RedisArrayTest extends RedisTest
  16. {
  17. protected $driverClass = 'Stash\Driver\Redis';
  18. protected $redisSecondServer = '127.0.0.1';
  19. protected $redisSecondPort = '6380';
  20. protected $persistence = true;
  21. protected function setUp()
  22. {
  23. if (defined('HHVM_VERSION')) {
  24. $this->markTestSkipped('RedisArray currently not supported by HHVM.');
  25. }
  26. parent::setUp();
  27. if (!($sock = @fsockopen($this->redisServer, $this->redisPort, $errno, $errstr, 1))) {
  28. $this->markTestSkipped('Redis server unavailable for testing.');
  29. }
  30. fclose($sock);
  31. if (!($sock = @fsockopen($this->redisSecondServer, $this->redisSecondPort, $errno, $errstr, 1))) {
  32. $this->markTestSkipped('Second Redis Server needed for more tests.');
  33. }
  34. fclose($sock);
  35. }
  36. protected function getOptions()
  37. {
  38. return array(
  39. 'servers' => array(
  40. array('server' => $this->redisServer, 'port' => $this->redisPort, 'ttl' => 0.1),
  41. array('server' => $this->redisSecondServer, 'port' => $this->redisSecondPort, 'ttl' => 0.1),
  42. ),
  43. );
  44. }
  45. /**
  46. * @test
  47. */
  48. public function itShouldConstructARedisArray()
  49. {
  50. $driver = $this->getFreshDriver();
  51. $class = new \ReflectionClass($driver);
  52. $redisProperty = $class->getProperty('redis');
  53. $redisProperty->setAccessible(true);
  54. $redisArray = $redisProperty->getValue($driver);
  55. $this->assertInstanceOf('\RedisArray', $redisArray);
  56. }
  57. /**
  58. * @test
  59. */
  60. public function itShouldPassOptionsToRedisArray()
  61. {
  62. $redisArrayOptions = array(
  63. "previous" => "something",
  64. "function" => function ($key) { return $key; },
  65. "distributor" => function ($key) { return 0; },
  66. "index" => "something",
  67. "autorehash" => "something",
  68. "pconnect" => "something",
  69. "retry_interval" => "something",
  70. "lazy_connect" => "something",
  71. "connect_timeout" => "something",
  72. );
  73. $driverOptions = array_merge(
  74. $this->getOptions(),
  75. $redisArrayOptions
  76. );
  77. if (!extension_loaded('uopz')) {
  78. $this->markTestSkipped('uopz extension is necessarry in order to stub "new".');
  79. }
  80. uopz_backup('\RedisArray', '__construct');
  81. $self = $this;
  82. uopz_function(
  83. '\RedisArray',
  84. '__construct',
  85. function ($serverArray, $actualRedisArrayOptions) use ($self, $redisArrayOptions) {
  86. $self->assertEquals(
  87. $redisArrayOptions,
  88. $actualRedisArrayOptions
  89. );
  90. }
  91. );
  92. $this->getFreshDriver($driverOptions);
  93. uopz_restore('\RedisArray', '__construct');
  94. }
  95. }