diff --git a/composer.json b/composer.json index 88734f2..e09cd7d 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": ">=5.3", "react/promise": "^2.0 || ^1.1", - "react/socket-client": "^0.5 || ^0.4 || ^0.3", + "react/socket-client": "^0.7", "react/event-loop": "0.3.*|0.4.*", "clue/redis-protocol": "0.3.*", "evenement/evenement": "~1.0|~2.0" diff --git a/src/Factory.php b/src/Factory.php index af4c199..c4b4a94 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -7,7 +7,6 @@ use Clue\React\Redis\StreamingClient; use Clue\Redis\Protocol\Factory as ProtocolFactory; use React\SocketClient\Connector; -use React\Dns\Resolver\Factory as ResolverFactory; use InvalidArgumentException; use React\EventLoop\LoopInterface; use React\Promise; @@ -20,8 +19,7 @@ class Factory public function __construct(LoopInterface $loop, ConnectorInterface $connector = null, ProtocolFactory $protocol = null) { if ($connector === null) { - $resolverFactory = new ResolverFactory(); - $connector = new Connector($loop, $resolverFactory->create('8.8.8.8', $loop)); + $connector = new Connector($loop); } if ($protocol === null) { @@ -48,7 +46,7 @@ public function createClient($target = null) $protocol = $this->protocol; - $promise = $this->connector->create($parts['host'], $parts['port'])->then(function (Stream $stream) use ($protocol) { + $promise = $this->connector->connect($parts['host'] . ':' . $parts['port'])->then(function (Stream $stream) use ($protocol) { return new StreamingClient($stream, $protocol->createResponseParser(), $protocol->createSerializer()); }); diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index 4d17a07..4c059fd 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -23,19 +23,19 @@ public function testCtor() public function testWillConnectToLocalIpWithDefaultPortIfTargetIsNotGiven() { - $this->connector->expects($this->once())->method('create')->with('127.0.0.1', 6379)->willReturn(Promise\reject(new \RuntimeException())); + $this->connector->expects($this->once())->method('connect')->with('127.0.0.1:6379')->willReturn(Promise\reject(new \RuntimeException())); $this->factory->createClient(); } public function testWillConnectWithDefaultPort() { - $this->connector->expects($this->once())->method('create')->with('redis.example.com', 6379)->willReturn(Promise\reject(new \RuntimeException())); + $this->connector->expects($this->once())->method('connect')->with('redis.example.com:6379')->willReturn(Promise\reject(new \RuntimeException())); $this->factory->createClient('redis.example.com'); } public function testWillConnectToLocalIpWhenTargetIsLocalhost() { - $this->connector->expects($this->once())->method('create')->with('127.0.0.1', 1337)->willReturn(Promise\reject(new \RuntimeException())); + $this->connector->expects($this->once())->method('connect')->with('127.0.0.1:1337')->willReturn(Promise\reject(new \RuntimeException())); $this->factory->createClient('tcp://localhost:1337'); } @@ -44,7 +44,7 @@ public function testWillResolveIfConnectorResolves() $stream = $this->getMockBuilder('React\Stream\Stream')->disableOriginalConstructor()->getMock(); $stream->expects($this->never())->method('write'); - $this->connector->expects($this->once())->method('create')->willReturn(Promise\resolve($stream)); + $this->connector->expects($this->once())->method('connect')->willReturn(Promise\resolve($stream)); $promise = $this->factory->createClient(); $this->expectPromiseResolve($promise); @@ -55,7 +55,7 @@ public function testWillWriteSelectCommandIfTargetContainsPath() $stream = $this->getMockBuilder('React\Stream\Stream')->disableOriginalConstructor()->getMock(); $stream->expects($this->once())->method('write')->with("*2\r\n$6\r\nselect\r\n$4\r\ndemo\r\n"); - $this->connector->expects($this->once())->method('create')->willReturn(Promise\resolve($stream)); + $this->connector->expects($this->once())->method('connect')->willReturn(Promise\resolve($stream)); $this->factory->createClient('tcp://127.0.0.1/demo'); } @@ -64,13 +64,13 @@ public function testWillWriteAuthCommandIfTargetContainsUserInfo() $stream = $this->getMockBuilder('React\Stream\Stream')->disableOriginalConstructor()->getMock(); $stream->expects($this->once())->method('write')->with("*2\r\n$4\r\nauth\r\n$11\r\nhello:world\r\n"); - $this->connector->expects($this->once())->method('create')->willReturn(Promise\resolve($stream)); + $this->connector->expects($this->once())->method('connect')->willReturn(Promise\resolve($stream)); $this->factory->createClient('tcp://hello:world@127.0.0.1'); } public function testWillRejectIfConnectorRejects() { - $this->connector->expects($this->once())->method('create')->with('127.0.0.1', 2)->willReturn(Promise\reject(new \RuntimeException())); + $this->connector->expects($this->once())->method('connect')->with('127.0.0.1:2')->willReturn(Promise\reject(new \RuntimeException())); $promise = $this->factory->createClient('tcp://127.0.0.1:2'); $this->expectPromiseReject($promise);