Skip to content

Commit

Permalink
Merge 887015c into 152c155
Browse files Browse the repository at this point in the history
  • Loading branch information
0livier committed Sep 30, 2017
2 parents 152c155 + 887015c commit 7670074
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Gelf/Transport/TcpTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TcpTransport extends AbstractTransport
{
const DEFAULT_HOST = "127.0.0.1";
const DEFAULT_PORT = 12201;
const DEFAULT_SCHEME = 'tcp';

/**
* @var StreamSocketClient
Expand All @@ -41,13 +42,13 @@ class TcpTransport extends AbstractTransport
* @param string $host when NULL or empty DEFAULT_HOST is used
* @param int $port when NULL or empty DEFAULT_PORT is used
*/
public function __construct($host = self::DEFAULT_HOST, $port = self::DEFAULT_PORT)
public function __construct($host = self::DEFAULT_HOST, $port = self::DEFAULT_PORT, $scheme = self::DEFAULT_SCHEME)
{
// allow NULL-like values for fallback on default
$host = $host ?: self::DEFAULT_HOST;
$port = $port ?: self::DEFAULT_PORT;

$this->socketClient = new StreamSocketClient('tcp', $host, $port);
$this->socketClient = new StreamSocketClient($scheme, $host, $port);
$this->messageEncoder = new DefaultEncoder();
}

Expand Down
26 changes: 26 additions & 0 deletions tests/Gelf/Test/Transport/TcpTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,30 @@ public function testConnectTimeout()

$this->transport->setConnectTimeout(123);
}

private function getScheme($transport)
{
$reflectedTransport = new \ReflectionObject($transport);
$reflectedClient = $reflectedTransport->getProperty('socketClient');
$reflectedClient->setAccessible(true);

$socketClient = $reflectedClient->getValue($transport);
$reflectedSocketClient = new \ReflectionObject($socketClient);
$reflectedScheme = $reflectedSocketClient->getProperty('scheme');
$reflectedScheme->setAccessible(true);

return $reflectedScheme->getValue($socketClient);
}

public function testCustomScheme()
{
$transport = new TcpTransport(null, null, 'custom');
$this->assertEquals('custom', $this->getScheme($transport));
}

public function testDefaultScheme()
{
$transport = new TcpTransport(null, null);
$this->assertEquals('tcp', $this->getScheme($transport));
}
}

0 comments on commit 7670074

Please sign in to comment.