Skip to content

Commit 17a9471

Browse files
committed
Update SocketClient to v0.6
1 parent a499a45 commit 17a9471

6 files changed

Lines changed: 18 additions & 20 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"php": ">=5.3",
1515
"evenement/evenement": "~1.0|~2.0",
1616
"react/promise": "~1.0|~2.0",
17-
"react/socket-client": "^0.5 || ^0.4 || ^0.3",
17+
"react/socket-client": "^0.6",
1818
"react/event-loop": "0.3.*|0.4.*"
1919
},
2020
"require-dev": {

src/Client.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
namespace Clue\React\Ami;
44

5-
use Clue\React\Ami\Protocol\Event;
65
use Clue\React\Ami\Protocol\Action;
7-
use Evenement\EventEmitter;
8-
use React\Stream\Stream;
6+
use Clue\React\Ami\Protocol\ErrorException;
7+
use Clue\React\Ami\Protocol\Event;
8+
use Clue\React\Ami\Protocol\Message;
99
use Clue\React\Ami\Protocol\Parser;
10+
use Clue\React\Ami\Protocol\UnexpectedMessageException;
11+
use Evenement\EventEmitter;
1012
use React\Promise\Deferred;
13+
use React\SocketClient\ConnectionInterface;
1114
use Exception;
1215
use UnexpectedValueException;
13-
use Clue\React\Ami\Protocol\Message;
14-
use Clue\React\Ami\Protocol\ErrorException;
15-
use Clue\React\Ami\Protocol\UnexpectedMessageException;
1616

1717
class Client extends EventEmitter
1818
{
@@ -23,7 +23,7 @@ class Client extends EventEmitter
2323

2424
private $actionId = 0;
2525

26-
public function __construct(Stream $stream, Parser $parser = null)
26+
public function __construct(ConnectionInterface $stream, Parser $parser = null)
2727
{
2828
if ($parser === null) {
2929
$parser = new Parser();
@@ -47,8 +47,6 @@ public function __construct(Stream $stream, Parser $parser = null)
4747
$this->on('error', array($that, 'close'));
4848

4949
$this->stream->on('close', array ($that, 'close'));
50-
51-
$this->stream->resume();
5250
}
5351

5452
public function request(Action $message)

src/Factory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
namespace Clue\React\Ami;
44

55
use React\EventLoop\LoopInterface;
6+
use React\SocketClient\ConnectionInterface;
67
use React\SocketClient\ConnectorInterface;
78
use React\SocketClient\Connector;
89
use React\SocketClient\SecureConnector;
910
use React\Dns\Resolver\Factory as ResolverFactory;
10-
use React\Stream\Stream;
1111
use InvalidArgumentException;
1212

1313
class Factory
@@ -38,7 +38,7 @@ public function createClient($address = null)
3838
$secure = (isset($parts['scheme']) && $parts['scheme'] !== 'tcp');
3939
$connector = $secure ? $this->secureConnector : $this->connector;
4040

41-
$promise = $connector->create($parts['host'], $parts['port'])->then(function (Stream $stream) {
41+
$promise = $connector->connect($parts['host'] . ':' . $parts['port'])->then(function (ConnectionInterface $stream) {
4242
return new Client($stream);
4343
});
4444

tests/ClientTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ public function testClosingStreamClosesClient()
1616

1717
$client->on('close', $this->expectCallableOnce());
1818

19-
$stream->close();
20-
//$stream->emit('close', array($this));
19+
$stream->emit('close');
2120
}
2221

2322
public function testParserExceptionForwardsErrorAndClosesClient()
2423
{
2524
$stream = $this->createStreamMock();
25+
$stream->expects($this->once())->method('close');
26+
2627
$parser = new Parser();
2728

2829
$client = new Client($stream, $parser);
2930

3031
$client->on('error', $this->expectCallableOnce());
31-
$client->on('close', $this->expectCallableOnce());
3232

3333
$stream->emit('data', array("invalid chunk\r\n\r\ninvalid chunk\r\n\r\n"));
3434
}
@@ -45,6 +45,6 @@ public function testUnexpectedResponseEmitsErrorAndClosesClient()
4545

4646
private function createStreamMock()
4747
{
48-
return new Stream(fopen('php://memory', 'r+'), $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock());
48+
return $this->getMockBuilder('React\SocketClient\StreamConnection')->disableOriginalConstructor()->setMethods(array('write', 'close'))->getMock();
4949
}
5050
}

tests/CollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testCollectingSIPEvents()
5151

5252
private function createClientMock()
5353
{
54-
$stream = $this->getMockBuilder('React\Stream\Stream')->disableOriginalConstructor()->getMock();
54+
$stream = $this->getMockBuilder('React\SocketClient\StreamConnection')->disableOriginalConstructor()->getMock();
5555

5656
$client = $this->getMockBuilder('Clue\React\Ami\Client')->setMethods(array('createAction'))->setConstructorArgs(array($stream))->getMock();
5757

tests/FactoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ public function testDefaultCtor()
2626
public function testCreateClientUsesTcpConnectorWithDefaultLocation()
2727
{
2828
$promise = new Promise(function () { });
29-
$this->tcp->expects($this->once())->method('create')->with('127.0.0.1', 5038)->willReturn($promise);
29+
$this->tcp->expects($this->once())->method('connect')->with('127.0.0.1:5038')->willReturn($promise);
3030

3131
$this->factory->createClient();
3232
}
3333

3434
public function testCreateClientUsesTcpConnectorWithLocalhostLocation()
3535
{
3636
$promise = new Promise(function () { });
37-
$this->tcp->expects($this->once())->method('create')->with('127.0.0.1', 5038)->willReturn($promise);
37+
$this->tcp->expects($this->once())->method('connect')->with('127.0.0.1:5038')->willReturn($promise);
3838

3939
$this->factory->createClient('localhost');
4040
}
4141

4242
public function testCreateClientUsesTlsConnectorWithTlsLocation()
4343
{
4444
$promise = new Promise(function () { });
45-
$this->tls->expects($this->once())->method('create')->with('ami.local', 1234)->willReturn($promise);
45+
$this->tls->expects($this->once())->method('connect')->with('ami.local:1234')->willReturn($promise);
4646

4747
$this->factory->createClient('tls://ami.local:1234');
4848
}

0 commit comments

Comments
 (0)