PredisAdapterTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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 Symfony\Component\Cache\Tests\Adapter;
  11. use Predis\Connection\StreamConnection;
  12. use Symfony\Component\Cache\Adapter\RedisAdapter;
  13. class PredisAdapterTest extends AbstractRedisAdapterTest
  14. {
  15. public static function setupBeforeClass()
  16. {
  17. parent::setupBeforeClass();
  18. self::$redis = new \Predis\Client(['host' => getenv('REDIS_HOST')]);
  19. }
  20. public function testCreateConnection()
  21. {
  22. $redisHost = getenv('REDIS_HOST');
  23. $redis = RedisAdapter::createConnection('redis://'.$redisHost.'/1', ['class' => \Predis\Client::class, 'timeout' => 3]);
  24. $this->assertInstanceOf(\Predis\Client::class, $redis);
  25. $connection = $redis->getConnection();
  26. $this->assertInstanceOf(StreamConnection::class, $connection);
  27. $params = [
  28. 'scheme' => 'tcp',
  29. 'host' => $redisHost,
  30. 'path' => '',
  31. 'dbindex' => '1',
  32. 'port' => 6379,
  33. 'class' => 'Predis\Client',
  34. 'timeout' => 3,
  35. 'persistent' => 0,
  36. 'persistent_id' => null,
  37. 'read_timeout' => 0,
  38. 'retry_interval' => 0,
  39. 'lazy' => false,
  40. 'database' => '1',
  41. 'password' => null,
  42. ];
  43. $this->assertSame($params, $connection->getParameters()->toArray());
  44. }
  45. }