Skip to content
Closed
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
28 changes: 28 additions & 0 deletions src/StaticTargetConnector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace React\SocketClient;

use React\SocketClient\ConnectorInterface;

/**
* The host/port to connect to is set once during instantiation, the actual
* target host/port is then ignored.
*/
class StaticTargetConnector implements ConnectorInterface
{
private $connector;
private $host;
private $port;

public function __construct(ConnectorInterface $connector, $host, $port)
{
$this->connector = $connector;
$this->host = $host;
$this->port = $port;
}

public function create($unusedHost, $unusedPort)
{
return $this->connector->create($this->host, $this->port);
}
}
24 changes: 24 additions & 0 deletions tests/StaticTargetConnectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace React\Tests\SocketClient;

use React\SocketClient\StaticTargetConnector;
use React\Promise;

class StaticTargetConnectorTest extends TestCase
{
public function testPassCtorArgsToUnderlyingConnector()
{
$connector = $this->getMock('React\SocketClient\ConnectorInterface');
$connector->expects($this->once())
->method('create')
->with($this->equalTo('proxy.example.com'), $this->equalTo(8080))
->will($this->returnValue(Promise\reject(new \Exception())));

$static = new StaticTargetConnector($connector, 'proxy.example.com', 8080);

$promise = $static->create('reactphp.org', 80);

$promise->then(null, $this->expectCallableOnce());
}
}