1
|
<?php
|
2
|
|
3
|
/*
|
4
|
* This file is part of the Predis package.
|
5
|
*
|
6
|
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
7
|
*
|
8
|
* For the full copyright and license information, please view the LICENSE
|
9
|
* file that was distributed with this source code.
|
10
|
*/
|
11
|
|
12
|
namespace Predis\Command\Processor;
|
13
|
|
14
|
use PredisTestCase;
|
15
|
|
16
|
/**
|
17
|
*
|
18
|
*/
|
19
|
class ProcessorChainTest extends PredisTestCase
|
20
|
{
|
21
|
/**
|
22
|
* @group disconnected
|
23
|
*/
|
24
|
public function testConstructor()
|
25
|
{
|
26
|
$chain = new ProcessorChain();
|
27
|
|
28
|
$this->assertInstanceOf('Predis\Command\Processor\CommandProcessorInterface', $chain);
|
29
|
$this->assertInstanceOf('Predis\Command\Processor\CommandProcessorChainInterface', $chain);
|
30
|
$this->assertEmpty($chain->getProcessors());
|
31
|
}
|
32
|
|
33
|
/**
|
34
|
* @group disconnected
|
35
|
*/
|
36
|
public function testConstructorWithProcessorsArray()
|
37
|
{
|
38
|
$processors = array(
|
39
|
$this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
|
40
|
$this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
|
41
|
);
|
42
|
|
43
|
$chain = new ProcessorChain($processors);
|
44
|
|
45
|
$this->assertSame($processors, $chain->getProcessors());
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* @group disconnected
|
50
|
*/
|
51
|
public function testCountProcessors()
|
52
|
{
|
53
|
$processors = array(
|
54
|
$this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
|
55
|
$this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
|
56
|
);
|
57
|
|
58
|
$chain = new ProcessorChain($processors);
|
59
|
|
60
|
$this->assertEquals(2, $chain->count());
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* @group disconnected
|
65
|
*/
|
66
|
public function testAddProcessors()
|
67
|
{
|
68
|
$processors = array(
|
69
|
$this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
|
70
|
$this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
|
71
|
);
|
72
|
|
73
|
$chain = new ProcessorChain();
|
74
|
$chain->add($processors[0]);
|
75
|
$chain->add($processors[1]);
|
76
|
|
77
|
$this->assertSame($processors, $chain->getProcessors());
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* @group disconnected
|
82
|
*/
|
83
|
public function testAddMoreProcessors()
|
84
|
{
|
85
|
$processors1 = array(
|
86
|
$this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
|
87
|
$this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
|
88
|
);
|
89
|
|
90
|
$processors2 = array(
|
91
|
$this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
|
92
|
$this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
|
93
|
);
|
94
|
|
95
|
$chain = new ProcessorChain($processors1);
|
96
|
$chain->add($processors2[0]);
|
97
|
$chain->add($processors2[1]);
|
98
|
|
99
|
$this->assertSame(array_merge($processors1, $processors2), $chain->getProcessors());
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* @group disconnected
|
104
|
*/
|
105
|
public function testRemoveProcessors()
|
106
|
{
|
107
|
$processors = array(
|
108
|
$this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
|
109
|
$this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
|
110
|
);
|
111
|
|
112
|
$chain = new ProcessorChain($processors);
|
113
|
|
114
|
$chain->remove($processors[0]);
|
115
|
$this->assertSame(array($processors[1]), $chain->getProcessors());
|
116
|
|
117
|
$chain->remove($processors[1]);
|
118
|
$this->assertEmpty($chain->getProcessors());
|
119
|
}
|
120
|
|
121
|
/**
|
122
|
* @group disconnected
|
123
|
*/
|
124
|
public function testRemoveProcessorNotInChain()
|
125
|
{
|
126
|
$processor = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
|
127
|
$processors = array(
|
128
|
$this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
|
129
|
$this->getMock('Predis\Command\Processor\CommandProcessorInterface'),
|
130
|
);
|
131
|
|
132
|
$chain = new ProcessorChain($processors);
|
133
|
$chain->remove($processor);
|
134
|
|
135
|
$this->assertSame($processors, $chain->getProcessors());
|
136
|
}
|
137
|
|
138
|
/**
|
139
|
* @group disconnected
|
140
|
*/
|
141
|
public function testRemoveProcessorFromEmptyChain()
|
142
|
{
|
143
|
$processor = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
|
144
|
|
145
|
$chain = new ProcessorChain();
|
146
|
$this->assertEmpty($chain->getProcessors());
|
147
|
|
148
|
$chain->remove($processor);
|
149
|
$this->assertEmpty($chain->getProcessors());
|
150
|
}
|
151
|
|
152
|
/**
|
153
|
* @group disconnected
|
154
|
*/
|
155
|
public function testProcessChain()
|
156
|
{
|
157
|
$command = $this->getMock('Predis\Command\CommandInterface');
|
158
|
|
159
|
$processor1 = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
|
160
|
$processor1->expects($this->once())->method('process')->with($command);
|
161
|
|
162
|
$processor2 = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
|
163
|
$processor2->expects($this->once())->method('process')->with($command);
|
164
|
|
165
|
$processors = array($processor1, $processor2);
|
166
|
|
167
|
$chain = new ProcessorChain($processors);
|
168
|
$chain->process($command);
|
169
|
}
|
170
|
}
|