Skip to content

Commit 82ac345

Browse files
authored
Merge pull request #104 from SimonFrings/tests
Update PHPUnit configuration schema for PHPUnit 9.3
2 parents a9bbdbf + caabd13 commit 82ac345

File tree

8 files changed

+184
-48
lines changed

8 files changed

+184
-48
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/.travis.yml export-ignore
44
/examples/ export-ignore
55
/phpunit.xml.dist export-ignore
6+
/phpunit.xml.legacy export-ignore
67
/tests/ export-ignore

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ install:
2929
- composer install
3030

3131
script:
32-
- vendor/bin/phpunit --coverage-text
32+
- if [[ "$TRAVIS_PHP_VERSION" > "7.2" ]]; then vendor/bin/phpunit --coverage-text; fi
33+
- if [[ "$TRAVIS_PHP_VERSION" < "7.3" ]]; then vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy; fi

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"require-dev": {
2323
"clue/block-react": "^1.1",
24-
"phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35"
24+
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
2525
},
2626
"autoload": {
2727
"psr-4": { "Clue\\React\\Redis\\": "src/" }

phpunit.xml.dist

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit bootstrap="vendor/autoload.php" colors="true">
3+
<!-- PHPUnit configuration file with new format for PHPUnit 9.3+ -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
6+
bootstrap="vendor/autoload.php"
7+
colors="true"
8+
cacheResult="false">
49
<testsuites>
510
<testsuite name="Redis React Test Suite">
611
<directory>./tests/</directory>
712
</testsuite>
813
</testsuites>
9-
<filter>
10-
<whitelist>
14+
<coverage>
15+
<include>
1116
<directory>./src/</directory>
12-
</whitelist>
13-
</filter>
14-
</phpunit>
17+
</include>
18+
</coverage>
19+
</phpunit>

phpunit.xml.legacy

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
6+
bootstrap="vendor/autoload.php"
7+
colors="true">
8+
<testsuites>
9+
<testsuite name="Redis React Test Suite">
10+
<directory>./tests/</directory>
11+
</testsuite>
12+
</testsuites>
13+
<filter>
14+
<whitelist>
15+
<directory>./src/</directory>
16+
</whitelist>
17+
</filter>
18+
</phpunit>

tests/FactoryStreamingClientTest.php

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,27 +136,45 @@ public function testWillWriteAuthCommandIfRedisUnixUriContainsUserInfo()
136136

137137
public function testWillResolveWhenAuthCommandReceivesOkResponseIfRedisUriContainsUserInfo()
138138
{
139-
$stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('write'))->getMock();
139+
$dataHandler = null;
140+
$stream = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
140141
$stream->expects($this->once())->method('write')->with("*2\r\n$4\r\nauth\r\n$5\r\nworld\r\n");
142+
$stream->expects($this->exactly(2))->method('on')->withConsecutive(
143+
array('data', $this->callback(function ($arg) use (&$dataHandler) {
144+
$dataHandler = $arg;
145+
return true;
146+
})),
147+
array('close', $this->anything())
148+
);
141149

142150
$this->connector->expects($this->once())->method('connect')->willReturn(Promise\resolve($stream));
143151
$promise = $this->factory->createClient('redis://:world@localhost');
144152

145-
$stream->emit('data', array("+OK\r\n"));
153+
$this->assertTrue(is_callable($dataHandler));
154+
$dataHandler("+OK\r\n");
146155

147156
$promise->then($this->expectCallableOnceWith($this->isInstanceOf('Clue\React\Redis\Client')));
148157
}
149158

150159
public function testWillRejectAndCloseAutomaticallyWhenAuthCommandReceivesErrorResponseIfRedisUriContainsUserInfo()
151160
{
152-
$stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('write', 'close'))->getMock();
161+
$dataHandler = null;
162+
$stream = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
153163
$stream->expects($this->once())->method('write')->with("*2\r\n$4\r\nauth\r\n$5\r\nworld\r\n");
154164
$stream->expects($this->once())->method('close');
165+
$stream->expects($this->exactly(2))->method('on')->withConsecutive(
166+
array('data', $this->callback(function ($arg) use (&$dataHandler) {
167+
$dataHandler = $arg;
168+
return true;
169+
})),
170+
array('close', $this->anything())
171+
);
155172

156173
$this->connector->expects($this->once())->method('connect')->willReturn(Promise\resolve($stream));
157174
$promise = $this->factory->createClient('redis://:world@localhost');
158175

159-
$stream->emit('data', array("-ERR invalid password\r\n"));
176+
$this->assertTrue(is_callable($dataHandler));
177+
$dataHandler("-ERR invalid password\r\n");
160178

161179
$promise->then(null, $this->expectCallableOnceWith(
162180
$this->logicalAnd(
@@ -182,27 +200,45 @@ public function testWillWriteSelectCommandIfRedisUnixUriContainsDbQueryParameter
182200

183201
public function testWillResolveWhenSelectCommandReceivesOkResponseIfRedisUriContainsPath()
184202
{
185-
$stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('write'))->getMock();
203+
$dataHandler = null;
204+
$stream = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
186205
$stream->expects($this->once())->method('write')->with("*2\r\n$6\r\nselect\r\n$3\r\n123\r\n");
206+
$stream->expects($this->exactly(2))->method('on')->withConsecutive(
207+
array('data', $this->callback(function ($arg) use (&$dataHandler) {
208+
$dataHandler = $arg;
209+
return true;
210+
})),
211+
array('close', $this->anything())
212+
);
187213

188214
$this->connector->expects($this->once())->method('connect')->willReturn(Promise\resolve($stream));
189215
$promise = $this->factory->createClient('redis://localhost/123');
190216

191-
$stream->emit('data', array("+OK\r\n"));
217+
$this->assertTrue(is_callable($dataHandler));
218+
$dataHandler("+OK\r\n");
192219

193220
$promise->then($this->expectCallableOnceWith($this->isInstanceOf('Clue\React\Redis\Client')));
194221
}
195222

196223
public function testWillRejectAndCloseAutomaticallyWhenSelectCommandReceivesErrorResponseIfRedisUriContainsPath()
197224
{
198-
$stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('write', 'close'))->getMock();
225+
$dataHandler = null;
226+
$stream = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
199227
$stream->expects($this->once())->method('write')->with("*2\r\n$6\r\nselect\r\n$3\r\n123\r\n");
200228
$stream->expects($this->once())->method('close');
229+
$stream->expects($this->exactly(2))->method('on')->withConsecutive(
230+
array('data', $this->callback(function ($arg) use (&$dataHandler) {
231+
$dataHandler = $arg;
232+
return true;
233+
})),
234+
array('close', $this->anything())
235+
);
201236

202237
$this->connector->expects($this->once())->method('connect')->willReturn(Promise\resolve($stream));
203238
$promise = $this->factory->createClient('redis://localhost/123');
204239

205-
$stream->emit('data', array("-ERR DB index is out of range\r\n"));
240+
$this->assertTrue(is_callable($dataHandler));
241+
$dataHandler("-ERR DB index is out of range\r\n");
206242

207243
$promise->then(null, $this->expectCallableOnceWith(
208244
$this->logicalAnd(

tests/FunctionalTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ public function testPubSub()
149149
$deferred = new Deferred();
150150
$consumer->on('message', $this->expectCallableOnce());
151151
$consumer->on('message', array($deferred, 'resolve'));
152-
$consumer->subscribe($channel)->then($this->expectCallableOnce());
153-
154-
// producer sends a single message
155-
$producer->publish($channel, 'hello world')->then($this->expectCallableOnceWith(1));
152+
$once = $this->expectCallableOnceWith(1);
153+
$consumer->subscribe($channel)->then(function() use ($producer, $channel, $once){
154+
// producer sends a single message
155+
$producer->publish($channel, 'hello world')->then($once);
156+
})->then($this->expectCallableOnce());
156157

157158
// expect "message" event to take no longer than 0.1s
158159
Block\await($deferred->promise(), $this->loop, 0.1);

0 commit comments

Comments
 (0)