Skip to content

Commit 229527b

Browse files
committed
test: refactor with data provider
1 parent a38ac8b commit 229527b

File tree

1 file changed

+69
-57
lines changed

1 file changed

+69
-57
lines changed

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

Lines changed: 69 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -50,63 +50,6 @@ protected function getInstance($options = [])
5050
return new RedisHandler($sessionConfig, $this->userIpAddress);
5151
}
5252

53-
public function testSavePathWithoutProtocol(): void
54-
{
55-
$handler = $this->getInstance(
56-
['savePath' => '127.0.0.1:6379']
57-
);
58-
59-
$savePath = $this->getPrivateProperty($handler, 'savePath');
60-
61-
$this->assertSame('tcp', $savePath['protocol']);
62-
}
63-
64-
public function testSavePathTLSAuth(): void
65-
{
66-
$handler = $this->getInstance(
67-
['savePath' => 'tls://127.0.0.1:6379?auth=password']
68-
);
69-
70-
$savePath = $this->getPrivateProperty($handler, 'savePath');
71-
72-
$this->assertSame('tls', $savePath['protocol']);
73-
$this->assertSame('password', $savePath['password']);
74-
}
75-
76-
public function testSavePathTCPAuth(): void
77-
{
78-
$handler = $this->getInstance(
79-
['savePath' => 'tcp://127.0.0.1:6379?auth=password']
80-
);
81-
82-
$savePath = $this->getPrivateProperty($handler, 'savePath');
83-
84-
$this->assertSame('tcp', $savePath['protocol']);
85-
$this->assertSame('password', $savePath['password']);
86-
}
87-
88-
public function testSavePathTimeoutFloat(): void
89-
{
90-
$handler = $this->getInstance(
91-
['savePath' => 'tcp://127.0.0.1:6379?timeout=2.5']
92-
);
93-
94-
$savePath = $this->getPrivateProperty($handler, 'savePath');
95-
96-
$this->assertEqualsWithDelta(2.5, $savePath['timeout'], PHP_FLOAT_EPSILON);
97-
}
98-
99-
public function testSavePathTimeoutInt(): void
100-
{
101-
$handler = $this->getInstance(
102-
['savePath' => 'tcp://127.0.0.1:6379?timeout=10']
103-
);
104-
105-
$savePath = $this->getPrivateProperty($handler, 'savePath');
106-
107-
$this->assertEqualsWithDelta(10.0, $savePath['timeout'], PHP_FLOAT_EPSILON);
108-
}
109-
11053
public function testOpen(): void
11154
{
11255
$handler = $this->getInstance();
@@ -190,4 +133,73 @@ public function testSecondaryReadAfterClose(): void
190133

191134
$handler->close();
192135
}
136+
137+
/**
138+
* @dataProvider provideSetSavePath
139+
*/
140+
public function testSetSavePath(string $savePath, array $expected): void
141+
{
142+
$option = ['savePath' => $savePath];
143+
$handler = $this->getInstance($option);
144+
145+
$savePath = $this->getPrivateProperty($handler, 'savePath');
146+
147+
$this->assertSame($expected, $savePath);
148+
}
149+
150+
public static function provideSetSavePath(): iterable
151+
{
152+
yield from [
153+
'w/o protocol' => [
154+
'127.0.0.1:6379',
155+
[
156+
'host' => 'tcp://127.0.0.1',
157+
'port' => 6379,
158+
'password' => null,
159+
'database' => 0,
160+
'timeout' => 0.0,
161+
],
162+
],
163+
'tls auth' => [
164+
'tls://127.0.0.1:6379?auth=password',
165+
[
166+
'host' => 'tls://127.0.0.1',
167+
'port' => 6379,
168+
'password' => 'password',
169+
'database' => 0,
170+
'timeout' => 0.0,
171+
],
172+
],
173+
'tcp auth' => [
174+
'tcp://127.0.0.1:6379?auth=password',
175+
[
176+
'host' => 'tcp://127.0.0.1',
177+
'port' => 6379,
178+
'password' => 'password',
179+
'database' => 0,
180+
'timeout' => 0.0,
181+
],
182+
],
183+
'timeout float' => [
184+
'tcp://127.0.0.1:6379?timeout=2.5',
185+
[
186+
'host' => 'tcp://127.0.0.1',
187+
'port' => 6379,
188+
'password' => null,
189+
'database' => 0,
190+
'timeout' => 2.5,
191+
],
192+
],
193+
'timeout int' => [
194+
'tcp://127.0.0.1:6379?timeout=10',
195+
[
196+
'host' => 'tcp://127.0.0.1',
197+
'port' => 6379,
198+
'password' => null,
199+
'database' => 0,
200+
'timeout' => 10.0,
201+
],
202+
],
203+
];
204+
}
193205
}

0 commit comments

Comments
 (0)