Skip to content

Commit 29164c3

Browse files
committed
Inject SocketClient via ConnectorInterface
1 parent 59dd121 commit 29164c3

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/Factory.php

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

55
use React\EventLoop\LoopInterface;
6+
use React\SocketClient\ConnectorInterface;
67
use React\SocketClient\Connector;
78
use React\SocketClient\SecureConnector;
89
use React\Dns\Resolver\Factory as ResolverFactory;
@@ -15,7 +16,7 @@ class Factory
1516
private $connector;
1617
private $secureConnector;
1718

18-
public function __construct(LoopInterface $loop, Connector $connector = null, SecureConnector $secureConnector = null)
19+
public function __construct(LoopInterface $loop, ConnectorInterface $connector = null, ConnectorInterface $secureConnector = null)
1920
{
2021
if ($connector === null) {
2122
$resolverFactory = new ResolverFactory();

tests/FactoryTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
use Clue\React\Ami\Factory;
4+
use React\Promise\Promise;
5+
class FactoryTest extends TestCase
6+
{
7+
private $loop;
8+
private $tcp;
9+
private $tls;
10+
private $factory;
11+
12+
public function setUp()
13+
{
14+
$this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
15+
$this->tcp = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
16+
$this->tls = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
17+
18+
$this->factory = new Factory($this->loop, $this->tcp, $this->tls);
19+
}
20+
21+
public function testDefaultCtor()
22+
{
23+
$this->factory = new Factory($this->loop);
24+
}
25+
26+
public function testCreateClientUsesTcpConnectorWithDefaultLocation()
27+
{
28+
$promise = new Promise(function () { });
29+
$this->tcp->expects($this->once())->method('create')->with('127.0.0.1', 5038)->willReturn($promise);
30+
31+
$this->factory->createClient();
32+
}
33+
34+
public function testCreateClientUsesTcpConnectorWithLocalhostLocation()
35+
{
36+
$promise = new Promise(function () { });
37+
$this->tcp->expects($this->once())->method('create')->with('127.0.0.1', 5038)->willReturn($promise);
38+
39+
$this->factory->createClient('localhost');
40+
}
41+
}

0 commit comments

Comments
 (0)