Skip to content

Commit 14f173f

Browse files
committed
add tests for rediss connection
1 parent 3e8355a commit 14f173f

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

RedisConnectionFactory.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,18 @@ public function __construct($config = 'redis:')
5050
}
5151

5252
$this->config = array_replace($this->defaultConfig(), $config);
53+
if (isset($this->config['vendor'])) {
54+
$vendor = $this->config['vendor'];
55+
} else {
56+
$vendor = "";
57+
}
5358

5459
$supportedVendors = ['predis', 'phpredis', 'custom'];
55-
if (false == in_array($this->config['vendor'], $supportedVendors, true)) {
60+
if (false == in_array($vendor, $supportedVendors, true)) {
5661
throw new \LogicException(sprintf(
5762
'Unsupported redis vendor given. It must be either "%s". Got "%s"',
5863
implode('", "', $supportedVendors),
59-
$this->config['vendor']
64+
$vendor
6065
));
6166
}
6267
}
@@ -133,8 +138,15 @@ private function parseDsn($dsn)
133138
$config = array_replace($queryConfig, $config);
134139
}
135140

141+
if (isset($config['vendor'])) {
142+
$vendor = $config['vendor'];
143+
} else {
144+
$vendor = "";
145+
}
146+
147+
136148
//predis additionaly supports tls as scheme, but it must remain in the $config array
137-
if ($config['vendor']!='predis') {
149+
if ($vendor!='predis') {
138150
if ($config['scheme']!='redis') throw new \LogicException(sprintf($unsupportedError, $dsn));
139151
unset($config['scheme']);
140152
}

Tests/RedisConnectionFactoryConfigTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,46 @@ public static function provideConfigs()
125125
],
126126
];
127127

128+
//check normal redis connection for predis library
129+
yield [
130+
'redis://localhost:1234?foo=bar&lazy=0&vendor=predis',
131+
[
132+
'host' => 'localhost',
133+
'port' => 1234,
134+
'timeout' => null,
135+
'reserved' => null,
136+
'retry_interval' => null,
137+
'vendor' => 'predis',
138+
'persisted' => false,
139+
'lazy' => false,
140+
'foo' => 'bar',
141+
'database' => 0,
142+
'scheme' => 'redis',
143+
'redis' => null,
144+
],
145+
];
146+
147+
//check tls connection for predis library
148+
yield [
149+
'rediss://localhost:1234?foo=bar&lazy=0&vendor=predis',
150+
[
151+
'host' => 'localhost',
152+
'port' => 1234,
153+
'timeout' => null,
154+
'reserved' => null,
155+
'retry_interval' => null,
156+
'vendor' => 'predis',
157+
'persisted' => false,
158+
'lazy' => false,
159+
'foo' => 'bar',
160+
'database' => 0,
161+
'scheme' => 'rediss',
162+
'redis' => null,
163+
],
164+
];
165+
166+
167+
128168
yield [
129169
['host' => 'localhost', 'port' => 1234, 'foo' => 'bar'],
130170
[

0 commit comments

Comments
 (0)