Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 2 additions & 4 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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());
});

Expand Down
14 changes: 7 additions & 7 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -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);
Expand All @@ -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');
}

Expand All @@ -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);
Expand Down