PredisAdapterTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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(): void
  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. 'port' => 6379,
  31. 'persistent' => 0,
  32. 'timeout' => 3,
  33. 'read_write_timeout' => 0,
  34. 'tcp_nodelay' => true,
  35. 'database' => '1',
  36. ];
  37. $this->assertSame($params, $connection->getParameters()->toArray());
  38. }
  39. }