Skip to content

Commit

Permalink
Replace deprecated SocketClient with new Socket component
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Apr 10, 2017
1 parent ecbef14 commit 890afd7
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 35 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# clue/connection-manager-extra [![Build Status](https://travis-ci.org/clue/php-connection-manager-extra.svg?branch=master)](https://travis-ci.org/clue/php-connection-manager-extra)

This project provides _extra_ (in terms of "additional", "extraordinary", "special" and "unusual") decorators,
built on top of [ReactPHP's SocketClient](https://github.com/reactphp/socket-client).
built on top of [ReactPHP's Socket](https://github.com/reactphp/socket).

**Table of Contents**

Expand All @@ -22,12 +22,12 @@ built on top of [ReactPHP's SocketClient](https://github.com/reactphp/socket-cli

## Introduction

If you're not already familar with [react/socket-client](https://github.com/reactphp/socket-client),
If you're not already familar with [react/socket](https://github.com/reactphp/socket),
think of it as an async (non-blocking) version of [`fsockopen()`](http://php.net/manual/en/function.fsockopen.php)
or [`stream_socket_client()`](http://php.net/manual/en/function.stream-socket-client.php).
I.e. before you can send and receive data to/from a remote server, you first have to establish a connection - which
takes its time because it involves several steps.
In order to be able to establish several connections at the same time, [react/socket-client](https://github.com/reactphp/socket-client) provides a simple
In order to be able to establish several connections at the same time, [react/socket](https://github.com/reactphp/socket) provides a simple
API to establish simple connections in an async (non-blocking) way.

This project includes several classes that extend this base functionality by implementing the same simple `ConnectorInterface`.
Expand Down Expand Up @@ -55,7 +55,7 @@ any combination thereof.

This section lists all this libraries' features along with some examples.
The examples assume you've [installed](#install) this library and
already [set up a `SocketClient/Connector` instance `$connector`](https://github.com/reactphp/socket-client#async-tcpip-connections).
already [set up a `Socket/Connector` instance `$connector`](https://github.com/reactphp/socket#connector).

All classes are located in the `ConnectionManager\Extra` namespace.

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "clue/connection-manager-extra",
"description": "Extra decorators for creating async TCP/IP connections, built on top of ReactPHP's SocketClient",
"keywords": ["SocketClient", "network", "connection", "timeout", "delay", "reject", "repeat", "retry", "random", "acl", "firewall", "ReactPHP"],
"description": "Extra decorators for creating async TCP/IP connections, built on top of ReactPHP's Socket component",
"keywords": ["Socket", "network", "connection", "timeout", "delay", "reject", "repeat", "retry", "random", "acl", "firewall", "ReactPHP"],
"homepage": "https://github.com/clue/php-connection-manager-extra",
"license": "MIT",
"authors": [
Expand All @@ -15,7 +15,7 @@
},
"require": {
"php": ">=5.3",
"react/socket-client": "^0.7 || ^0.6",
"react/socket": "^0.7",
"react/event-loop": "^0.4 || ^0.3",
"react/promise": "^2.1 || ^1.2",
"react/promise-timer": "^1.1"
Expand Down
2 changes: 1 addition & 1 deletion src/ConnectionManagerDelay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ConnectionManager\Extra;

use React\SocketClient\ConnectorInterface;
use React\Socket\ConnectorInterface;
use React\EventLoop\LoopInterface;
use React\Promise\Timer;

Expand Down
2 changes: 1 addition & 1 deletion src/ConnectionManagerReject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ConnectionManager\Extra;

use React\SocketClient\ConnectorInterface;
use React\Socket\ConnectorInterface;
use React\Promise;
use Exception;

Expand Down
2 changes: 1 addition & 1 deletion src/ConnectionManagerRepeat.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ConnectionManager\Extra;

use React\SocketClient\ConnectorInterface;
use React\Socket\ConnectorInterface;
use InvalidArgumentException;
use Exception;
use React\Promise\Promise;
Expand Down
2 changes: 1 addition & 1 deletion src/ConnectionManagerSwappable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ConnectionManager\Extra;

use React\SocketClient\ConnectorInterface;
use React\Socket\ConnectorInterface;

// connection manager decorator which simplifies exchanging the actual connection manager during runtime
class ConnectionManagerSwappable implements ConnectorInterface
Expand Down
2 changes: 1 addition & 1 deletion src/ConnectionManagerTimeout.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ConnectionManager\Extra;

use React\SocketClient\ConnectorInterface;
use React\Socket\ConnectorInterface;
use React\EventLoop\LoopInterface;
use React\Promise\Timer;
use Exception;
Expand Down
2 changes: 1 addition & 1 deletion src/Multiple/ConnectionManagerConsecutive.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ConnectionManager\Extra\Multiple;

use React\SocketClient\ConnectorInterface;
use React\Socket\ConnectorInterface;
use React\Promise;
use UnderflowException;
use React\Promise\CancellablePromiseInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Multiple/ConnectionManagerSelective.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ConnectionManager\Extra\Multiple;

use React\SocketClient\ConnectorInterface;
use React\Socket\ConnectorInterface;
use React\Promise;
use UnderflowException;
use InvalidArgumentException;
Expand Down
2 changes: 1 addition & 1 deletion tests/ConnectionManagerDelayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testDelayTenth()

public function testCancellationOfPromiseBeforeDelayDoesNotStartConnection()
{
$unused = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$unused = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$unused->expects($this->never())->method('connect');

$cm = new ConnectionManagerDelay($unused, 1.0, $this->loop);
Expand Down
6 changes: 3 additions & 3 deletions tests/ConnectionManagerRepeatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testTwoTriesWillStartTwoConnectionAttempts()
{
$promise = Promise\reject(new \RuntimeException('nope'));

$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector->expects($this->exactly(2))->method('connect')->with('google.com:80')->willReturn($promise);

$cm = new ConnectionManagerRepeat($connector, 2);
Expand All @@ -44,7 +44,7 @@ public function testCancellationWillNotStartAnyFurtherConnections()
{
$pending = new Promise\Promise(function () { }, $this->expectCallableOnce());

$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('connect')->with('google.com:80')->willReturn($pending);

$cm = new ConnectionManagerRepeat($connector, 3);
Expand All @@ -59,7 +59,7 @@ public function testCancellationWillNotStartAnyFurtherConnectionsIfPromiseReject
throw new \RuntimeException('cancelled');
});

$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('connect')->with('google.com:80')->willReturn($pending);

$cm = new ConnectionManagerRepeat($connector, 3);
Expand Down
4 changes: 2 additions & 2 deletions tests/ConnectionManagerTimeoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testWillEndConnectionIfConnectionResolvesDespiteTimeout()
});
});

$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('connect')->with('www.google.com:80')->willReturn($promise);

$cm = new ConnectionManagerTimeout($connector, 0.001, $this->loop);
Expand All @@ -86,7 +86,7 @@ public function testCancellationOfPromiseWillCancelConnectionAttempt()
throw new \RuntimeException();
});

$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('connect')->with('www.google.com:80')->willReturn($promise);

$cm = new ConnectionManagerTimeout($connector, 5.0, $this->loop);
Expand Down
10 changes: 5 additions & 5 deletions tests/Multiple/ConnectionManagerConcurrentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testWillForwardToInnerConnector()
{
$pending = new Promise\Promise(function() { });

$only = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$only = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$only->expects($this->once())->method('connect')->with('google.com:80')->willReturn($pending);

$connector = new ConnectionManagerConcurrent(array($only));
Expand All @@ -30,11 +30,11 @@ public function testWillForwardToInnerConnector()
public function testWillCancelOtherIfOneResolves()
{
$resolved = Promise\resolve($this->getMockBuilder('React\Stream\DuplexStreamInterface')->getMock());
$first = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$first = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$first->expects($this->once())->method('connect')->with('google.com:80')->willReturn($resolved);

$pending = new Promise\Promise(function() { }, $this->expectCallableOnce());
$second = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$second = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$second->expects($this->once())->method('connect')->with('google.com:80')->willReturn($pending);

$connector = new ConnectionManagerConcurrent(array($first, $second));
Expand All @@ -47,12 +47,12 @@ public function testWillCancelOtherIfOneResolves()
public function testWillCloseOtherIfOneResolves()
{
$resolved = Promise\resolve($this->getMockBuilder('React\Stream\DuplexStreamInterface')->getMock());
$first = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$first = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$first->expects($this->once())->method('connect')->with('google.com:80')->willReturn($resolved);

$slower = $this->getMockBuilder('React\Stream\DuplexStreamInterface')->getMock();
$slower->expects($this->once())->method('close');
$second = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$second = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$second->expects($this->once())->method('connect')->with('google.com:80')->willReturn(Promise\resolve($slower));

$connector = new ConnectionManagerConcurrent(array($first, $second));
Expand Down
4 changes: 2 additions & 2 deletions tests/Multiple/ConnectionManagerConsecutiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testWillTryAllIfEachRejects()
{
$rejected = Promise\reject(new \RuntimeException('nope'));

$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector->expects($this->exactly(2))->method('connect')->with('google.com:80')->willReturn($rejected);

$cm = new ConnectionManagerConsecutive(array($connector, $connector));
Expand All @@ -45,7 +45,7 @@ public function testCancellationWillNotStartAnyFurtherConnections()
{
$pending = new Promise\Promise(function () { }, $this->expectCallableOnce());

$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('connect')->with('google.com:80')->willReturn($pending);

$cm = new ConnectionManagerConsecutive(array($connector, $connector));
Expand Down
4 changes: 2 additions & 2 deletions tests/Multiple/ConnectionManagerRandomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testWillTryAllIfEachRejects()
{
$rejected = Promise\reject(new \RuntimeException('nope'));

$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector->expects($this->exactly(2))->method('connect')->with('google.com:80')->willReturn($rejected);

$cm = new ConnectionManagerRandom(array($connector, $connector));
Expand All @@ -45,7 +45,7 @@ public function testCancellationWillNotStartAnyFurtherConnections()
{
$pending = new Promise\Promise(function () { }, $this->expectCallableOnce());

$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('connect')->with('google.com:80')->willReturn($pending);

$cm = new ConnectionManagerRandom(array($connector, $connector));
Expand Down
10 changes: 5 additions & 5 deletions tests/Multiple/ConnectionManagerSelectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function provideInvalidMatcher()
*/
public function testInvalidMatcherThrowsException($matcher)
{
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();

new ConnectionManagerSelective(array(
$matcher => $connector
Expand All @@ -80,7 +80,7 @@ public function testExactDomainMatchForwardsToConnector()
{
$promise = $this->getMockBuilder('React\Promise\PromiseInterface')->getMock();

$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('connect')->with('example.com:80')->willReturn($promise);

$cm = new ConnectionManagerSelective(array(
Expand All @@ -96,7 +96,7 @@ public function testExactIpv6MatchForwardsToConnector()
{
$promise = $this->getMockBuilder('React\Promise\PromiseInterface')->getMock();

$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('connect')->with('[::1]:80')->willReturn($promise);

$cm = new ConnectionManagerSelective(array(
Expand All @@ -112,7 +112,7 @@ public function testExactIpv6WithPortMatchForwardsToConnector()
{
$promise = $this->getMockBuilder('React\Promise\PromiseInterface')->getMock();

$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector->expects($this->once())->method('connect')->with('[::1]:80')->willReturn($promise);

$cm = new ConnectionManagerSelective(array(
Expand All @@ -126,7 +126,7 @@ public function testExactIpv6WithPortMatchForwardsToConnector()

public function testNotMatchingDomainWillReject()
{
$connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$connector->expects($this->never())->method('connect');

$cm = new ConnectionManagerSelective(array(
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function createCallableMock()

protected function createConnectionManagerMock($ret)
{
$mock = $this->getMockBuilder('React\SocketClient\ConnectorInterface')
$mock = $this->getMockBuilder('React\Socket\ConnectorInterface')
->getMock();

$deferred = new Deferred();
Expand Down

0 comments on commit 890afd7

Please sign in to comment.