/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Redis/RedisConnectorTest.php
312 строк
10 KB
Lucas Michot
Remove useless parent::setUp()/tearDown() calls in tests extending PHPUnit's TestCase directly (#60994)
03 авг 2026, 20:54
Не верифицирован
03 авг 2026, 20:54
14a6983
Код
Авторство
О чём код?
<?php namespace Illuminate\Tests\Redis; use Illuminate\Foundation\Application; use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis; use Illuminate\Redis\RedisManager; use PHPUnit\Framework\TestCase; use Redis; class RedisConnectorTest extends TestCase { use InteractsWithRedis; protected function setUp(): void { $this->setUpRedis(); } protected function tearDown(): void { $this->tearDownRedis(); } public function testDefaultConfiguration() { $host = env('REDIS_HOST', '127.0.0.1'); $port = env('REDIS_PORT', 6379); $predisClient = $this->redis['predis']->connection()->client(); $parameters = $predisClient->getConnection()->getParameters(); $this->assertSame('tcp', $parameters->scheme); $this->assertEquals($host, $parameters->host); $this->assertEquals($port, $parameters->port); $phpRedisClient = $this->redis['phpredis']->connection()->client(); $this->assertEquals($host, $phpRedisClient->getHost()); $this->assertEquals($port, $phpRedisClient->getPort()); $this->assertSame('default', $phpRedisClient->client('GETNAME')); } public function testUrl() { $host = env('REDIS_HOST', '127.0.0.1'); $port = env('REDIS_PORT', 6379); $predis = new RedisManager(new Application, 'predis', [ 'cluster' => false, 'options' => [ 'prefix' => 'test_', ], 'default' => [ 'url' => "redis://{$host}:{$port}", 'database' => 5, 'timeout' => 0.5, ], ]); $predisClient = $predis->connection()->client(); $parameters = $predisClient->getConnection()->getParameters(); $this->assertSame('tcp', $parameters->scheme); $this->assertEquals($host, $parameters->host); $this->assertEquals($port, $parameters->port); $phpRedis = new RedisManager(new Application, 'phpredis', [ 'cluster' => false, 'options' => [ 'prefix' => 'test_', ], 'default' => [ 'url' => "redis://{$host}:{$port}", 'database' => 5, 'timeout' => 0.5, ], ]); $phpRedisClient = $phpRedis->connection()->client(); $this->assertSame("tcp://{$host}", $phpRedisClient->getHost()); $this->assertEquals($port, $phpRedisClient->getPort()); } public function testUrlWithScheme() { $host = env('REDIS_HOST', '127.0.0.1'); $port = env('REDIS_PORT', 6379); $predis = new RedisManager(new Application, 'predis', [ 'cluster' => false, 'options' => [ 'prefix' => 'test_', ], 'default' => [ 'url' => "tls://{$host}:{$port}", 'database' => 5, 'timeout' => 0.5, ], ]); $predisClient = $predis->connection()->client(); $parameters = $predisClient->getConnection()->getParameters(); $this->assertSame('tls', $parameters->scheme); $this->assertEquals($host, $parameters->host); $this->assertEquals($port, $parameters->port); $phpRedis = new RedisManager(new Application, 'phpredis', [ 'cluster' => false, 'options' => [ 'prefix' => 'test_', ], 'default' => [ 'url' => "tcp://{$host}:{$port}", 'database' => 5, 'timeout' => 0.5, ], ]); $phpRedisClient = $phpRedis->connection()->client(); $this->assertSame("tcp://{$host}", $phpRedisClient->getHost()); $this->assertEquals($port, $phpRedisClient->getPort()); } public function testScheme() { $host = env('REDIS_HOST', '127.0.0.1'); $port = env('REDIS_PORT', 6379); $predis = new RedisManager(new Application, 'predis', [ 'cluster' => false, 'options' => [ 'prefix' => 'test_', ], 'default' => [ 'scheme' => 'tls', 'host' => $host, 'port' => $port, 'database' => 5, 'timeout' => 0.5, ], ]); $predisClient = $predis->connection()->client(); $parameters = $predisClient->getConnection()->getParameters(); $this->assertSame('tls', $parameters->scheme); $this->assertEquals($host, $parameters->host); $this->assertEquals($port, $parameters->port); $phpRedis = new RedisManager(new Application, 'phpredis', [ 'cluster' => false, 'options' => [ 'prefix' => 'test_', ], 'default' => [ 'scheme' => 'tcp', 'host' => $host, 'port' => $port, 'database' => 5, 'timeout' => 0.5, ], ]); $phpRedisClient = $phpRedis->connection()->client(); $this->assertSame("tcp://{$host}", $phpRedisClient->getHost()); $this->assertEquals($port, $phpRedisClient->getPort()); } public function testPredisConfigurationWithUsername() { $host = env('REDIS_HOST', '127.0.0.1'); $port = env('REDIS_PORT', 6379); $username = 'testuser'; $password = 'testpw'; $predis = new RedisManager(new Application, 'predis', [ 'default' => [ 'host' => $host, 'port' => $port, 'username' => $username, 'password' => $password, 'database' => 5, 'timeout' => 0.5, ], ]); $predisClient = $predis->connection()->client(); $parameters = $predisClient->getConnection()->getParameters(); $this->assertEquals($username, $parameters->username); $this->assertEquals($password, $parameters->password); } public function testPredisConfigurationWithSentinel() { $host = env('REDIS_HOST', '127.0.0.1'); $port = env('REDIS_PORT', 6379); $predis = new RedisManager(new Application, 'predis', [ 'cluster' => false, 'options' => [ 'replication' => 'sentinel', 'service' => 'mymaster', 'parameters' => [ 'default' => [ 'database' => 5, ], ], ], 'default' => [ "tcp://{$host}:{$port}", ], ]); $predisClient = $predis->connection()->client(); $parameters = $predisClient->getConnection()->getSentinelConnection()->getParameters(); $this->assertEquals($host, $parameters->host); } public function testPhpRedisTcpKeepalive() { $host = env('REDIS_HOST', '127.0.0.1'); $port = env('REDIS_PORT', 6379); $phpRedis = new RedisManager(new Application, 'phpredis', [ 'cluster' => false, 'default' => [ 'host' => $host, 'port' => $port, 'database' => 5, 'timeout' => 0.5, 'tcp_keepalive' => 60, ], ]); $phpRedisClient = $phpRedis->connection()->client(); $this->assertEquals(1, $phpRedisClient->getOption(Redis::OPT_TCP_KEEPALIVE)); } public function testPrefixOverrideBehaviour() { $host = env('REDIS_HOST', '127.0.0.1'); $port = env('REDIS_PORT', 6379); $predis1 = new RedisManager(new Application, 'predis', [ 'cluster' => false, 'options' => [ 'prefix' => 'test_', ], 'default' => [ 'scheme' => 'tls', 'host' => $host, 'port' => $port, 'database' => 5, 'timeout' => 0.5, 'options' => [ 'prefix' => 'test_default_options_', ], ], ]); $predisClient1 = $predis1->client(); $this->assertSame('test_default_options_', $predisClient1->getOptions()->prefix->getPrefix()); $predis2 = new RedisManager(new Application, 'predis', [ 'cluster' => false, 'options' => [ 'prefix' => 'test_', ], 'default' => [ 'scheme' => 'tls', 'host' => $host, 'port' => $port, 'database' => 5, 'timeout' => 0.5, 'options' => [ 'prefix' => 'test_default_options_', ], 'prefix' => 'test_default_config_', ], ]); $predisClient2 = $predis2->client(); $this->assertSame('test_default_config_', $predisClient2->getOptions()->prefix->getPrefix()); $phpRedis1 = new RedisManager(new Application, 'phpredis', [ 'cluster' => false, 'options' => [ 'prefix' => 'test_', ], 'default' => [ 'scheme' => 'tcp', 'host' => $host, 'port' => $port, 'database' => 5, 'timeout' => 0.5, 'options' => [ 'prefix' => 'test_default_options_', ], ], ]); $phpRedisClient1 = $phpRedis1->connection()->client(); $this->assertSame('test_default_options_', $phpRedisClient1->getOption(Redis::OPT_PREFIX)); $phpRedis2 = new RedisManager(new Application, 'phpredis', [ 'cluster' => false, 'options' => [ 'prefix' => 'test_', ], 'default' => [ 'scheme' => 'tcp', 'host' => $host, 'port' => $port, 'database' => 5, 'timeout' => 0.5, 'options' => [ 'prefix' => 'test_default_options_', ], 'prefix' => 'test_default_config_', ], ]); $phpRedisClient2 = $phpRedis2->connection()->client(); $this->assertSame('test_default_config_', $phpRedisClient2->getOption(Redis::OPT_PREFIX)); } }