Skip to content

Commit 73b9460

Browse files
committed
Update PHPUnit and PHP syntax for tests
1 parent 15ac1e9 commit 73b9460

8 files changed

+263
-273
lines changed

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.3 || ^5.7"
24+
"phpunit/phpunit": "^9.3 || ^7.5"
2525
},
2626
"autoload": {
2727
"psr-4": { "Clue\\React\\Redis\\": "src/" }

phpunit.xml.legacy

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

3-
<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
3+
<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
44
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
66
bootstrap="vendor/autoload.php"
77
colors="true">
88
<testsuites>

tests/FactoryLazyClientTest.php

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
namespace Clue\Tests\React\Redis;
44

5+
use Clue\React\Redis\Client;
56
use Clue\React\Redis\Factory;
6-
use React\Promise;
7+
use React\EventLoop\LoopInterface;
8+
use React\Socket\ConnectionInterface;
9+
use React\Socket\ConnectorInterface;
10+
use function React\Promise\reject;
11+
use function React\Promise\resolve;
712

813
class FactoryLazyClientTest extends TestCase
914
{
@@ -16,8 +21,8 @@ class FactoryLazyClientTest extends TestCase
1621
*/
1722
public function setUpFactory()
1823
{
19-
$this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
20-
$this->connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
24+
$this->loop = $this->createMock(LoopInterface::class);
25+
$this->connector = $this->createMock(ConnectorInterface::class);
2126
$this->factory = new Factory($this->loop, $this->connector);
2227
}
2328

@@ -29,134 +34,134 @@ public function testConstructWithoutLoopAssignsLoopAutomatically()
2934
$ref->setAccessible(true);
3035
$loop = $ref->getValue($factory);
3136

32-
$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
37+
$this->assertInstanceOf(LoopInterface::class, $loop);
3338
}
3439

3540
public function testWillConnectWithDefaultPort()
3641
{
37-
$this->connector->expects($this->never())->method('connect')->with('redis.example.com:6379')->willReturn(Promise\reject(new \RuntimeException()));
42+
$this->connector->expects($this->never())->method('connect')->with('redis.example.com:6379')->willReturn(reject(new \RuntimeException()));
3843
$this->factory->createLazyClient('redis.example.com');
3944
}
4045

4146
public function testWillConnectToLocalhost()
4247
{
43-
$this->connector->expects($this->never())->method('connect')->with('localhost:1337')->willReturn(Promise\reject(new \RuntimeException()));
48+
$this->connector->expects($this->never())->method('connect')->with('localhost:1337')->willReturn(reject(new \RuntimeException()));
4449
$this->factory->createLazyClient('localhost:1337');
4550
}
4651

4752
public function testWillResolveIfConnectorResolves()
4853
{
49-
$stream = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
54+
$stream = $this->createMock(ConnectionInterface::class);
5055
$stream->expects($this->never())->method('write');
5156

52-
$this->connector->expects($this->never())->method('connect')->willReturn(Promise\resolve($stream));
57+
$this->connector->expects($this->never())->method('connect')->willReturn(resolve($stream));
5358
$redis = $this->factory->createLazyClient('localhost');
5459

55-
$this->assertInstanceOf('Clue\React\Redis\Client', $redis);
60+
$this->assertInstanceOf(Client::class, $redis);
5661
}
5762

5863
public function testWillWriteSelectCommandIfTargetContainsPath()
5964
{
60-
$stream = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
65+
$stream = $this->createMock(ConnectionInterface::class);
6166
$stream->expects($this->never())->method('write')->with("*2\r\n$6\r\nselect\r\n$4\r\ndemo\r\n");
6267

63-
$this->connector->expects($this->never())->method('connect')->willReturn(Promise\resolve($stream));
68+
$this->connector->expects($this->never())->method('connect')->willReturn(resolve($stream));
6469
$this->factory->createLazyClient('redis://127.0.0.1/demo');
6570
}
6671

6772
public function testWillWriteSelectCommandIfTargetContainsDbQueryParameter()
6873
{
69-
$stream = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
74+
$stream = $this->createMock(ConnectionInterface::class);
7075
$stream->expects($this->never())->method('write')->with("*2\r\n$6\r\nselect\r\n$1\r\n4\r\n");
7176

72-
$this->connector->expects($this->never())->method('connect')->willReturn(Promise\resolve($stream));
77+
$this->connector->expects($this->never())->method('connect')->willReturn(resolve($stream));
7378
$this->factory->createLazyClient('redis://127.0.0.1?db=4');
7479
}
7580

7681
public function testWillWriteAuthCommandIfRedisUriContainsUserInfo()
7782
{
78-
$stream = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
83+
$stream = $this->createMock(ConnectionInterface::class);
7984
$stream->expects($this->never())->method('write')->with("*2\r\n$4\r\nauth\r\n$5\r\nworld\r\n");
8085

81-
$this->connector->expects($this->never())->method('connect')->with('example.com:6379')->willReturn(Promise\resolve($stream));
86+
$this->connector->expects($this->never())->method('connect')->with('example.com:6379')->willReturn(resolve($stream));
8287
$this->factory->createLazyClient('redis://hello:[email protected]');
8388
}
8489

8590
public function testWillWriteAuthCommandIfRedisUriContainsEncodedUserInfo()
8691
{
87-
$stream = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
92+
$stream = $this->createMock(ConnectionInterface::class);
8893
$stream->expects($this->never())->method('write')->with("*2\r\n$4\r\nauth\r\n$5\r\nh@llo\r\n");
8994

90-
$this->connector->expects($this->never())->method('connect')->with('example.com:6379')->willReturn(Promise\resolve($stream));
95+
$this->connector->expects($this->never())->method('connect')->with('example.com:6379')->willReturn(resolve($stream));
9196
$this->factory->createLazyClient('redis://:h%[email protected]');
9297
}
9398

9499
public function testWillWriteAuthCommandIfTargetContainsPasswordQueryParameter()
95100
{
96-
$stream = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
101+
$stream = $this->createMock(ConnectionInterface::class);
97102
$stream->expects($this->never())->method('write')->with("*2\r\n$4\r\nauth\r\n$6\r\nsecret\r\n");
98103

99-
$this->connector->expects($this->never())->method('connect')->with('example.com:6379')->willReturn(Promise\resolve($stream));
104+
$this->connector->expects($this->never())->method('connect')->with('example.com:6379')->willReturn(resolve($stream));
100105
$this->factory->createLazyClient('redis://example.com?password=secret');
101106
}
102107

103108
public function testWillWriteAuthCommandIfTargetContainsEncodedPasswordQueryParameter()
104109
{
105-
$stream = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
110+
$stream = $this->createMock(ConnectionInterface::class);
106111
$stream->expects($this->never())->method('write')->with("*2\r\n$4\r\nauth\r\n$5\r\nh@llo\r\n");
107112

108-
$this->connector->expects($this->never())->method('connect')->with('example.com:6379')->willReturn(Promise\resolve($stream));
113+
$this->connector->expects($this->never())->method('connect')->with('example.com:6379')->willReturn(resolve($stream));
109114
$this->factory->createLazyClient('redis://example.com?password=h%40llo');
110115
}
111116

112117
public function testWillWriteAuthCommandIfRedissUriContainsUserInfo()
113118
{
114-
$stream = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
119+
$stream = $this->createMock(ConnectionInterface::class);
115120
$stream->expects($this->never())->method('write')->with("*2\r\n$4\r\nauth\r\n$5\r\nworld\r\n");
116121

117-
$this->connector->expects($this->never())->method('connect')->with('tls://example.com:6379')->willReturn(Promise\resolve($stream));
122+
$this->connector->expects($this->never())->method('connect')->with('tls://example.com:6379')->willReturn(resolve($stream));
118123
$this->factory->createLazyClient('rediss://hello:[email protected]');
119124
}
120125

121126
public function testWillWriteAuthCommandIfRedisUnixUriContainsPasswordQueryParameter()
122127
{
123-
$stream = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
128+
$stream = $this->createMock(ConnectionInterface::class);
124129
$stream->expects($this->never())->method('write')->with("*2\r\n$4\r\nauth\r\n$5\r\nworld\r\n");
125130

126-
$this->connector->expects($this->never())->method('connect')->with('unix:///tmp/redis.sock')->willReturn(Promise\resolve($stream));
131+
$this->connector->expects($this->never())->method('connect')->with('unix:///tmp/redis.sock')->willReturn(resolve($stream));
127132
$this->factory->createLazyClient('redis+unix:///tmp/redis.sock?password=world');
128133
}
129134

130135
public function testWillWriteAuthCommandIfRedisUnixUriContainsUserInfo()
131136
{
132-
$stream = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
137+
$stream = $this->createMock(ConnectionInterface::class);
133138
$stream->expects($this->never())->method('write')->with("*2\r\n$4\r\nauth\r\n$5\r\nworld\r\n");
134139

135-
$this->connector->expects($this->never())->method('connect')->with('unix:///tmp/redis.sock')->willReturn(Promise\resolve($stream));
140+
$this->connector->expects($this->never())->method('connect')->with('unix:///tmp/redis.sock')->willReturn(resolve($stream));
136141
$this->factory->createLazyClient('redis+unix://hello:world@/tmp/redis.sock');
137142
}
138143

139144
public function testWillWriteSelectCommandIfRedisUnixUriContainsDbQueryParameter()
140145
{
141-
$stream = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
146+
$stream = $this->createMock(ConnectionInterface::class);
142147
$stream->expects($this->never())->method('write')->with("*2\r\n$6\r\nselect\r\n$4\r\ndemo\r\n");
143148

144-
$this->connector->expects($this->never())->method('connect')->with('unix:///tmp/redis.sock')->willReturn(Promise\resolve($stream));
149+
$this->connector->expects($this->never())->method('connect')->with('unix:///tmp/redis.sock')->willReturn(resolve($stream));
145150
$this->factory->createLazyClient('redis+unix:///tmp/redis.sock?db=demo');
146151
}
147152

148153
public function testWillRejectIfConnectorRejects()
149154
{
150-
$this->connector->expects($this->never())->method('connect')->with('127.0.0.1:2')->willReturn(Promise\reject(new \RuntimeException()));
155+
$this->connector->expects($this->never())->method('connect')->with('127.0.0.1:2')->willReturn(reject(new \RuntimeException()));
151156
$redis = $this->factory->createLazyClient('redis://127.0.0.1:2');
152157

153-
$this->assertInstanceOf('Clue\React\Redis\Client', $redis);
158+
$this->assertInstanceOf(Client::class, $redis);
154159
}
155160

156161
public function testWillRejectIfTargetIsInvalid()
157162
{
158163
$redis = $this->factory->createLazyClient('http://invalid target');
159164

160-
$this->assertInstanceOf('Clue\React\Redis\Client', $redis);
165+
$this->assertInstanceOf(Client::class, $redis);
161166
}
162167
}

0 commit comments

Comments
 (0)