Skip to content

Commit 40c0559

Browse files
authored
Merge pull request #58 from clue-labs/socket-client
Update SocketClient to latest version
2 parents 2e7f79a + 4a9741b commit 40c0559

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"require": {
1414
"php": ">=5.3",
1515
"react/promise": "^2.0 || ^1.1",
16-
"react/socket-client": "^0.5 || ^0.4 || ^0.3",
16+
"react/socket-client": "^0.7",
1717
"react/event-loop": "0.3.*|0.4.*",
1818
"clue/redis-protocol": "0.3.*",
1919
"evenement/evenement": "~1.0|~2.0"

src/Factory.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Clue\React\Redis\StreamingClient;
88
use Clue\Redis\Protocol\Factory as ProtocolFactory;
99
use React\SocketClient\Connector;
10-
use React\Dns\Resolver\Factory as ResolverFactory;
1110
use InvalidArgumentException;
1211
use React\EventLoop\LoopInterface;
1312
use React\Promise;
@@ -20,8 +19,7 @@ class Factory
2019
public function __construct(LoopInterface $loop, ConnectorInterface $connector = null, ProtocolFactory $protocol = null)
2120
{
2221
if ($connector === null) {
23-
$resolverFactory = new ResolverFactory();
24-
$connector = new Connector($loop, $resolverFactory->create('8.8.8.8', $loop));
22+
$connector = new Connector($loop);
2523
}
2624

2725
if ($protocol === null) {
@@ -48,7 +46,7 @@ public function createClient($target = null)
4846

4947
$protocol = $this->protocol;
5048

51-
$promise = $this->connector->create($parts['host'], $parts['port'])->then(function (Stream $stream) use ($protocol) {
49+
$promise = $this->connector->connect($parts['host'] . ':' . $parts['port'])->then(function (Stream $stream) use ($protocol) {
5250
return new StreamingClient($stream, $protocol->createResponseParser(), $protocol->createSerializer());
5351
});
5452

tests/FactoryTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ public function testCtor()
2323

2424
public function testWillConnectToLocalIpWithDefaultPortIfTargetIsNotGiven()
2525
{
26-
$this->connector->expects($this->once())->method('create')->with('127.0.0.1', 6379)->willReturn(Promise\reject(new \RuntimeException()));
26+
$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:6379')->willReturn(Promise\reject(new \RuntimeException()));
2727
$this->factory->createClient();
2828
}
2929

3030
public function testWillConnectWithDefaultPort()
3131
{
32-
$this->connector->expects($this->once())->method('create')->with('redis.example.com', 6379)->willReturn(Promise\reject(new \RuntimeException()));
32+
$this->connector->expects($this->once())->method('connect')->with('redis.example.com:6379')->willReturn(Promise\reject(new \RuntimeException()));
3333
$this->factory->createClient('redis.example.com');
3434
}
3535

3636
public function testWillConnectToLocalIpWhenTargetIsLocalhost()
3737
{
38-
$this->connector->expects($this->once())->method('create')->with('127.0.0.1', 1337)->willReturn(Promise\reject(new \RuntimeException()));
38+
$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:1337')->willReturn(Promise\reject(new \RuntimeException()));
3939
$this->factory->createClient('tcp://localhost:1337');
4040
}
4141

@@ -44,7 +44,7 @@ public function testWillResolveIfConnectorResolves()
4444
$stream = $this->getMockBuilder('React\Stream\Stream')->disableOriginalConstructor()->getMock();
4545
$stream->expects($this->never())->method('write');
4646

47-
$this->connector->expects($this->once())->method('create')->willReturn(Promise\resolve($stream));
47+
$this->connector->expects($this->once())->method('connect')->willReturn(Promise\resolve($stream));
4848
$promise = $this->factory->createClient();
4949

5050
$this->expectPromiseResolve($promise);
@@ -55,7 +55,7 @@ public function testWillWriteSelectCommandIfTargetContainsPath()
5555
$stream = $this->getMockBuilder('React\Stream\Stream')->disableOriginalConstructor()->getMock();
5656
$stream->expects($this->once())->method('write')->with("*2\r\n$6\r\nselect\r\n$4\r\ndemo\r\n");
5757

58-
$this->connector->expects($this->once())->method('create')->willReturn(Promise\resolve($stream));
58+
$this->connector->expects($this->once())->method('connect')->willReturn(Promise\resolve($stream));
5959
$this->factory->createClient('tcp://127.0.0.1/demo');
6060
}
6161

@@ -64,13 +64,13 @@ public function testWillWriteAuthCommandIfTargetContainsUserInfo()
6464
$stream = $this->getMockBuilder('React\Stream\Stream')->disableOriginalConstructor()->getMock();
6565
$stream->expects($this->once())->method('write')->with("*2\r\n$4\r\nauth\r\n$11\r\nhello:world\r\n");
6666

67-
$this->connector->expects($this->once())->method('create')->willReturn(Promise\resolve($stream));
67+
$this->connector->expects($this->once())->method('connect')->willReturn(Promise\resolve($stream));
6868
$this->factory->createClient('tcp://hello:[email protected]');
6969
}
7070

7171
public function testWillRejectIfConnectorRejects()
7272
{
73-
$this->connector->expects($this->once())->method('create')->with('127.0.0.1', 2)->willReturn(Promise\reject(new \RuntimeException()));
73+
$this->connector->expects($this->once())->method('connect')->with('127.0.0.1:2')->willReturn(Promise\reject(new \RuntimeException()));
7474
$promise = $this->factory->createClient('tcp://127.0.0.1:2');
7575

7676
$this->expectPromiseReject($promise);

0 commit comments

Comments
 (0)