Skip to content

Commit 8e1d0ef

Browse files
committed
Avoid mocked dependencies between tests, fix PHPUnit 5.3+ (PHP 7)
1 parent e9464d8 commit 8e1d0ef

File tree

2 files changed

+47
-75
lines changed

2 files changed

+47
-75
lines changed

tests/FunctionalTest.php

Lines changed: 32 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@
99

1010
class FunctionalTest extends TestCase
1111
{
12-
protected static $loop;
13-
protected static $factory;
12+
private $loop;
13+
private $factory;
14+
private $client;
1415

15-
public static function setUpBeforeClass()
16+
public function setUp()
1617
{
17-
self::$loop = new React\EventLoop\StreamSelectLoop();
18-
self::$factory = new Factory(self::$loop);
18+
$this->loop = new React\EventLoop\StreamSelectLoop();
19+
$this->factory = new Factory($this->loop);
20+
$this->client = $this->createClient();
1921
}
2022

2123
public function testPing()
2224
{
23-
$client = $this->createClient();
25+
$client = $this->client;
2426

2527
$promise = $client->ping();
2628
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
@@ -35,7 +37,7 @@ public function testPing()
3537

3638
public function testMgetIsNotInterpretedAsSubMessage()
3739
{
38-
$client = $this->createClient();
40+
$client = $this->client;
3941

4042
$client->mset('message', 'message', 'channel', 'channel', 'payload', 'payload');
4143

@@ -45,14 +47,9 @@ public function testMgetIsNotInterpretedAsSubMessage()
4547
$this->waitFor($client);
4648
}
4749

48-
/**
49-
*
50-
* @param StreamingClient $client
51-
* @depends testPing
52-
*/
53-
public function testPipeline(StreamingClient $client)
50+
public function testPipeline()
5451
{
55-
$this->assertFalse($client->isBusy());
52+
$client = $this->client;
5653

5754
$client->set('a', 1)->then($this->expectCallableOnce('OK'));
5855
$client->incr('a')->then($this->expectCallableOnce(2));
@@ -62,46 +59,27 @@ public function testPipeline(StreamingClient $client)
6259
$this->assertTrue($client->isBusy());
6360

6461
$this->waitFor($client);
65-
66-
return $client;
6762
}
6863

69-
/**
70-
*
71-
* @param StreamingClient $client
72-
* @depends testPipeline
73-
*/
74-
public function testInvalidCommand(StreamingClient $client)
64+
public function testInvalidCommand()
7565
{
76-
$client->doesnotexist(1, 2, 3)->then($this->expectCallableNever());
66+
$this->client->doesnotexist(1, 2, 3)->then($this->expectCallableNever());
7767

78-
$this->waitFor($client);
79-
80-
return $client;
68+
$this->waitFor($this->client);
8169
}
8270

83-
/**
84-
*
85-
* @param StreamingClient $client
86-
* @depends testInvalidCommand
87-
*/
88-
public function testMultiExecEmpty(StreamingClient $client)
71+
public function testMultiExecEmpty()
8972
{
90-
$client->multi()->then($this->expectCallableOnce('OK'));
91-
$client->exec()->then($this->expectCallableOnce(array()));
73+
$this->client->multi()->then($this->expectCallableOnce('OK'));
74+
$this->client->exec()->then($this->expectCallableOnce(array()));
9275

93-
$this->waitFor($client);
94-
95-
return $client;
76+
$this->waitFor($this->client);
9677
}
9778

98-
/**
99-
*
100-
* @param StreamingClient $client
101-
* @depends testMultiExecEmpty
102-
*/
103-
public function testMultiExecQueuedExecHasValues(StreamingClient $client)
79+
public function testMultiExecQueuedExecHasValues()
10480
{
81+
$client = $this->client;
82+
10583
$client->multi()->then($this->expectCallableOnce('OK'));
10684
$client->set('b', 10)->then($this->expectCallableOnce('QUEUED'));
10785
$client->expire('b', 20)->then($this->expectCallableOnce('QUEUED'));
@@ -110,17 +88,12 @@ public function testMultiExecQueuedExecHasValues(StreamingClient $client)
11088
$client->exec()->then($this->expectCallableOnce(array('OK', 1, 12, 20)));
11189

11290
$this->waitFor($client);
113-
114-
return $client;
11591
}
11692

117-
/**
118-
*
119-
* @param StreamingClient $client
120-
* @depends testPipeline
121-
*/
122-
public function testMonitorPing(StreamingClient $client)
93+
public function testMonitorPing()
12394
{
95+
$client = $this->client;
96+
12497
$client->on('monitor', $this->expectCallableOnce());
12598

12699
$client->monitor()->then($this->expectCallableOnce('OK'));
@@ -131,7 +104,7 @@ public function testMonitorPing(StreamingClient $client)
131104

132105
public function testPubSub()
133106
{
134-
$consumer = $this->createClient();
107+
$consumer = $this->client;
135108
$producer = $this->createClient();
136109

137110
$channel = 'channel:test:' . mt_rand();
@@ -148,18 +121,16 @@ public function testPubSub()
148121
$this->waitFor($producer);
149122

150123
// expect "message" event to take no longer than 0.1s
151-
Block\await($deferred->promise(), self::$loop, 0.1);
124+
Block\await($deferred->promise(), $this->loop, 0.1);
152125
}
153126

154127
public function testClose()
155128
{
156-
$client = $this->createClient();
157-
158-
$client->get('willBeCanceledAnyway')->then(null, $this->expectCallableOnce());
129+
$this->client->get('willBeCanceledAnyway')->then(null, $this->expectCallableOnce());
159130

160-
$client->close();
131+
$this->client->close();
161132

162-
$client->get('willBeRejectedRightAway')->then(null, $this->expectCallableOnce());
133+
$this->client->get('willBeRejectedRightAway')->then(null, $this->expectCallableOnce());
163134
}
164135

165136
public function testInvalidProtocol()
@@ -191,7 +162,7 @@ public function testInvalidServerRepliesWithDuplicateMessages()
191162
*/
192163
protected function createClient()
193164
{
194-
return Block\await(self::$factory->createClient(), self::$loop);
165+
return Block\await($this->factory->createClient(), $this->loop);
195166
}
196167

197168
protected function createClientResponse($response)
@@ -200,7 +171,7 @@ protected function createClientResponse($response)
200171
fwrite($fp, $response);
201172
fseek($fp, 0);
202173

203-
$stream = new Stream($fp, self::$loop);
174+
$stream = new Stream($fp, $this->loop);
204175

205176
return new StreamingClient($stream);
206177
}
@@ -217,7 +188,7 @@ protected function waitFor(StreamingClient $client)
217188
$this->assertTrue($client->isBusy());
218189

219190
while ($client->isBusy()) {
220-
self::$loop->tick();
191+
$this->loop->tick();
221192
}
222193
}
223194
}

tests/StreamingClientTest.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,29 +112,30 @@ public function testMonitor()
112112

113113
$this->expectPromiseResolve($promise);
114114
$promise->then($this->expectCallableOnce('OK'));
115-
116-
return $this->client;
117115
}
118116

119-
/**
120-
* @depends testMonitor
121-
* @param StreamingClient $client
122-
*/
123-
public function testMonitorEvent(StreamingClient $client)
117+
public function testMonitorEventFromOtherConnection()
124118
{
125-
$client->on('monitor', $this->expectCallableOnce());
119+
// enter MONITOR mode
120+
$client = $this->client;
121+
$client->monitor();
122+
$client->handleMessage(new StatusReply('OK'));
126123

124+
// expect a single "monitor" event when a matching status reply comes in
125+
$client->on('monitor', $this->expectCallableOnce());
127126
$client->handleMessage(new StatusReply('1409171800.312243 [0 127.0.0.1:58542] "ping"'));
128127
}
129128

130-
/**
131-
* @depends testMonitor
132-
* @param StreamingClient $client
133-
*/
134-
public function testMonitorPing(StreamingClient $client)
129+
public function testMonitorEventFromPingMessage()
135130
{
136-
$client->on('monitor', $this->expectCallableOnce());
131+
// enter MONITOR mode
132+
$client = $this->client;
133+
$client->monitor();
134+
$client->handleMessage(new StatusReply('OK'));
137135

136+
// expect a single "monitor" event when a matching status reply comes in
137+
// ignore the status reply for the command executed (ping)
138+
$client->on('monitor', $this->expectCallableOnce());
138139
$client->ping();
139140
$client->handleMessage(new StatusReply('1409171800.312243 [0 127.0.0.1:58542] "ping"'));
140141
$client->handleMessage(new StatusReply('PONG'));

0 commit comments

Comments
 (0)