forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedisManagerExtensionTest.php
More file actions
122 lines (109 loc) · 3.07 KB
/
RedisManagerExtensionTest.php
File metadata and controls
122 lines (109 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace Illuminate\Tests\Redis;
use Illuminate\Contracts\Redis\Connector;
use Illuminate\Foundation\Application;
use Illuminate\Redis\RedisManager;
use Mockery as m;
use PHPUnit\Framework\TestCase;
class RedisManagerExtensionTest extends TestCase
{
/**
* Redis manager instance.
*
* @var RedisManager
*/
protected $redis;
protected function setUp(): void
{
parent::setUp();
$this->redis = new RedisManager(new Application(), 'my_custom_driver', [
'default' => [
'host' => 'some-host',
'port' => 'some-port',
'database' => 5,
'timeout' => 0.5,
],
'clusters' => [
'my-cluster' => [
[
'host' => 'some-host',
'port' => 'some-port',
'database' => 5,
'timeout' => 0.5,
],
],
],
]);
$this->redis->extend('my_custom_driver', function () {
return new FakeRedisConnnector();
});
}
protected function tearDown(): void
{
m::close();
}
public function testUsingCustomRedisConnectorWithSingleRedisInstance()
{
$this->assertSame(
'my-redis-connection', $this->redis->resolve()
);
}
public function testUsingCustomRedisConnectorWithRedisClusterInstance()
{
$this->assertSame(
'my-redis-cluster-connection', $this->redis->resolve('my-cluster')
);
}
public function test_parse_connection_configuration_for_cluster()
{
$name = 'my-cluster';
$config = [
[
'url1',
'url2',
'url3',
],
];
$redis = new RedisManager(new Application(), 'my_custom_driver', [
'clusters' => [
$name => $config,
],
]);
$redis->extend('my_custom_driver', function () use ($config) {
return m::mock(Connector::class)
->shouldReceive('connectToCluster')
->once()
->withArgs(function ($configArg) use ($config) {
return $config === $configArg;
})
->getMock();
});
$redis->resolve($name);
}
}
class FakeRedisConnnector implements Connector
{
/**
* Create a new clustered Predis connection.
*
* @param array $config
* @param array $options
* @return \Illuminate\Contracts\Redis\Connection
*/
public function connect(array $config, array $options)
{
return 'my-redis-connection';
}
/**
* Create a new clustered Predis connection.
*
* @param array $config
* @param array $clusterOptions
* @param array $options
* @return \Illuminate\Contracts\Redis\Connection
*/
public function connectToCluster(array $config, array $clusterOptions, array $options)
{
return 'my-redis-cluster-connection';
}
}