Skip to content

Commit ff572f6

Browse files
committed
make default protocol property and test set savePath without protocol
1 parent b547b22 commit ff572f6

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

system/Session/Handlers/RedisHandler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
*/
2525
class RedisHandler extends BaseHandler
2626
{
27-
private const DEFAULT_PORT = 6379;
27+
private const DEFAULT_PORT = 6379;
28+
private const DEFAULT_PROTOCOL = 'tcp';
2829

2930
/**
3031
* phpRedis instance
@@ -108,7 +109,7 @@ protected function setSavePath(): void
108109
}
109110

110111
$this->savePath = [
111-
'protocol' => in_array($matches[1], ['tcp', 'tls'], true) ? $matches[1] : 'tcp',
112+
'protocol' => in_array($matches[1], ['tcp', 'tls'], true) ? $matches[1] : self::DEFAULT_PROTOCOL,
112113
'host' => $matches[2],
113114
'port' => empty($matches[3]) ? self::DEFAULT_PORT : $matches[3],
114115
'password' => preg_match('#auth=([^\s&]+)#', $matches[4], $match) ? $match[1] : null,

tests/system/Session/Handlers/Database/RedisHandlerTest.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,39 @@ protected function getInstance($options = [])
5454
return new RedisHandler(new AppConfig(), $this->userIpAddress);
5555
}
5656

57+
public function testSavePathWithoutProtocol()
58+
{
59+
$handler = $this->getInstance(
60+
['savePath' => '127.0.0.1:6379']
61+
);
62+
63+
$savePath = $this->getPrivateProperty($handler, 'savePath');
64+
65+
$this->assertSame('tcp', $savePath['protocol']);
66+
}
67+
5768
public function testSavePathTLSAuth()
5869
{
5970
$handler = $this->getInstance(
60-
['savePath' => 'tls://127.0.0.1:6379?auth=password&timeout=2.5']
71+
['savePath' => 'tls://127.0.0.1:6379?auth=password']
6172
);
6273

6374
$savePath = $this->getPrivateProperty($handler, 'savePath');
6475

76+
$this->assertSame('tls', $savePath['protocol']);
6577
$this->assertSame('password', $savePath['password']);
66-
$this->assertSame(2.5, $savePath['timeout']);
6778
}
6879

6980
public function testSavePathTCPAuth()
7081
{
7182
$handler = $this->getInstance(
72-
['savePath' => 'tcp://127.0.0.1:6379?auth=password&timeout=2.5']
83+
['savePath' => 'tcp://127.0.0.1:6379?auth=password']
7384
);
7485

7586
$savePath = $this->getPrivateProperty($handler, 'savePath');
7687

88+
$this->assertSame('tcp', $savePath['protocol']);
7789
$this->assertSame('password', $savePath['password']);
78-
$this->assertSame(2.5, $savePath['timeout']);
7990
}
8091

8192
public function testSavePathTimeoutFloat()

0 commit comments

Comments
 (0)