diff --git a/src/Elasticsearch/Client.php b/src/Elasticsearch/Client.php index 8b3f0faeb..0b9d64b64 100644 --- a/src/Elasticsearch/Client.php +++ b/src/Elasticsearch/Client.php @@ -1323,10 +1323,7 @@ private function extractURIParts($host) $parts['port'] = 9200; } - return array( - 'host' => $parts['host'], - 'port' => $parts['port'], - ); + return $parts; } diff --git a/src/Elasticsearch/Common/DICBuilder.php b/src/Elasticsearch/Common/DICBuilder.php index 6eeb9ffdb..81545c8f3 100644 --- a/src/Elasticsearch/Common/DICBuilder.php +++ b/src/Elasticsearch/Common/DICBuilder.php @@ -188,10 +188,9 @@ private function setEndpointDICObjects() private function setConnectionObj() { $this->dic['connection'] = function ($dicParams) { - return function ($host, $port = null) use ($dicParams) { + return function ($hostDetails) use ($dicParams) { return new $dicParams['connectionClass']( - $host, - $port, + $hostDetails, $dicParams['connectionParamsShared'], $dicParams['logObject'], $dicParams['traceObject'] diff --git a/src/Elasticsearch/ConnectionPool/SniffingConnectionPool.php b/src/Elasticsearch/ConnectionPool/SniffingConnectionPool.php index 46446c90a..cc751cd15 100644 --- a/src/Elasticsearch/ConnectionPool/SniffingConnectionPool.php +++ b/src/Elasticsearch/ConnectionPool/SniffingConnectionPool.php @@ -124,10 +124,11 @@ private function sniffConnection(AbstractConnection $connection) $this->connections = array(); foreach ($nodes as $node) { - $this->connections[] = $this->connectionFactory->create( - $node['host'], - $node['port'] + $nodeDetails = array( + 'host' => $node['host'], + 'port' => $node['port'] ); + $this->connections[] = $this->connectionFactory->create($nodeDetails); } $this->nextSniff = time() + $this->sniffingInterval; diff --git a/src/Elasticsearch/Connections/AbstractConnection.php b/src/Elasticsearch/Connections/AbstractConnection.php index 192459d63..f46856847 100644 --- a/src/Elasticsearch/Connections/AbstractConnection.php +++ b/src/Elasticsearch/Connections/AbstractConnection.php @@ -79,15 +79,18 @@ abstract public function getTransportSchema(); /** * Constructor * - * @param string $host Host string - * @param string $port Host port + * @param array $hostDetails * @param array $connectionParams Array of connection-specific parameters * @param \Psr\Log\LoggerInterface $log Logger object * @param \Psr\Log\LoggerInterface $trace */ - public function __construct($host, $port, $connectionParams, LoggerInterface $log, LoggerInterface $trace) + public function __construct($hostDetails, $connectionParams, LoggerInterface $log, LoggerInterface $trace) { - $this->host = $this->transportSchema . '://' . $host . ':' . $port; + $host = $this->transportSchema.'://'.$hostDetails['host'].':'.$hostDetails['port']; + if (isset($hostDetails['path']) === true) { + $host .= $hostDetails['path']; + } + $this->host = $host; $this->log = $log; $this->trace = $trace; $this->connectionParams = $connectionParams; @@ -272,6 +275,15 @@ public function getPingFailures() } + /** + * @return string + */ + public function getHost() + { + return $this->host; + } + + /** * @param $curlErrorNumber * @param $message diff --git a/src/Elasticsearch/Connections/ConnectionFactory.php b/src/Elasticsearch/Connections/ConnectionFactory.php index 92f7ebd5e..46d0e7c54 100644 --- a/src/Elasticsearch/Connections/ConnectionFactory.php +++ b/src/Elasticsearch/Connections/ConnectionFactory.php @@ -12,16 +12,14 @@ class ConnectionFactory extends AbstractFactory { /** - * @param string $host - * @param int $port + * @param $hostDetails * * @return AbstractConnection */ - public function create($host, $port) + public function create($hostDetails) { return $this->container['connection']( - $host, - $port, + $hostDetails, $this->container['connectionParamsShared'], $this->container['logObject'], $this->container['traceObject'] diff --git a/src/Elasticsearch/Connections/ConnectionInterface.php b/src/Elasticsearch/Connections/ConnectionInterface.php index d63ef8f24..d4e0c6a37 100644 --- a/src/Elasticsearch/Connections/ConnectionInterface.php +++ b/src/Elasticsearch/Connections/ConnectionInterface.php @@ -20,7 +20,7 @@ */ interface ConnectionInterface { - public function __construct($host, $port, $connectionParams, LoggerInterface $log, LoggerInterface $trace); + public function __construct($hostDetails, $connectionParams, LoggerInterface $log, LoggerInterface $trace); public function getTransportSchema(); diff --git a/src/Elasticsearch/Connections/CurlMultiConnection.php b/src/Elasticsearch/Connections/CurlMultiConnection.php index c99135f45..83c824443 100644 --- a/src/Elasticsearch/Connections/CurlMultiConnection.php +++ b/src/Elasticsearch/Connections/CurlMultiConnection.php @@ -48,8 +48,7 @@ class CurlMultiConnection extends AbstractConnection implements ConnectionInterf /** * Constructor * - * @param string $host Host string - * @param int $port Host port + * @param array $hostDetails * @param array $connectionParams Array of connection parameters * @param \Psr\Log\LoggerInterface $log logger object * @param \Psr\Log\LoggerInterface $trace logger object (for curl traces) @@ -58,7 +57,7 @@ class CurlMultiConnection extends AbstractConnection implements ConnectionInterf * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException * @return CurlMultiConnection */ - public function __construct($host, $port, $connectionParams, LoggerInterface $log, LoggerInterface $trace) + public function __construct($hostDetails, $connectionParams, LoggerInterface $log, LoggerInterface $trace) { if (extension_loaded('curl') !== true) { $log->critical('Curl library/extension is required for CurlMultiConnection.'); @@ -70,15 +69,15 @@ public function __construct($host, $port, $connectionParams, LoggerInterface $lo throw new InvalidArgumentException('curlMultiHandle must be set in connectionParams'); } - if (isset($port) !== true) { - $port = 9200; + if (isset($hostDetails['port']) !== true) { + $hostDetails['port'] = 9200; } $connectionParams = $this->transformAuth($connectionParams); $this->curlOpts = $this->generateCurlOpts($connectionParams); $this->multiHandle = $connectionParams['curlMultiHandle']; - return parent::__construct($host, $port, $connectionParams, $log, $trace); + return parent::__construct($hostDetails, $connectionParams, $log, $trace); } diff --git a/src/Elasticsearch/Connections/GuzzleConnection.php b/src/Elasticsearch/Connections/GuzzleConnection.php index 7a34d0f56..2c37aff37 100644 --- a/src/Elasticsearch/Connections/GuzzleConnection.php +++ b/src/Elasticsearch/Connections/GuzzleConnection.php @@ -37,8 +37,7 @@ class GuzzleConnection extends AbstractConnection implements ConnectionInterface /** - * @param string $host Host string - * @param int $port Host port + * @param array $hostDetails * @param array $connectionParams Array of connection parameters * @param \Psr\Log\LoggerInterface $log logger object * @param \Psr\Log\LoggerInterface $trace logger object (for curl traces) @@ -46,15 +45,15 @@ class GuzzleConnection extends AbstractConnection implements ConnectionInterface * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException * @return \Elasticsearch\Connections\GuzzleConnection */ - public function __construct($host, $port, $connectionParams, LoggerInterface $log, LoggerInterface $trace) + public function __construct($hostDetails, $connectionParams, LoggerInterface $log, LoggerInterface $trace) { if (isset($connectionParams['guzzleClient']) !== true) { $log->critical('guzzleClient must be set in connectionParams'); throw new InvalidArgumentException('guzzleClient must be set in connectionParams'); } - if (isset($port) !== true) { - $port = 9200; + if (isset($hostDetails['port']) !== true) { + $hostDetails['port'] = 9200; } $this->guzzle = $connectionParams['guzzleClient']; @@ -62,7 +61,7 @@ public function __construct($host, $port, $connectionParams, LoggerInterface $lo $this->connectionOpts = $connectionParams['connectionParams']; } - return parent::__construct($host, $port, $connectionParams, $log, $trace); + return parent::__construct($hostDetails, $connectionParams, $log, $trace); } diff --git a/src/Elasticsearch/Transport.php b/src/Elasticsearch/Transport.php index 246a2c42d..e8e93e630 100644 --- a/src/Elasticsearch/Transport.php +++ b/src/Elasticsearch/Transport.php @@ -231,14 +231,9 @@ private function hostsToConnections($hosts) { $connections = array(); foreach ($hosts as $host) { - if (isset($host['port']) === true) { - $connections[] = $this->params['connection']( - $host['host'], - $host['port'] - ); - } else { - $connections[] = $this->params['connection']($host['host']); - } + $connections[] = $this->params['connection']( + $host + ); } return $connections; diff --git a/tests/Elasticsearch/Tests/ClientTest.php b/tests/Elasticsearch/Tests/ClientTest.php index 9207b37f8..fec9f134c 100644 --- a/tests/Elasticsearch/Tests/ClientTest.php +++ b/tests/Elasticsearch/Tests/ClientTest.php @@ -66,7 +66,7 @@ public function testOneGoodOneBadHostNoException() public function testOneGoodOneBadHostNoRetryException() { $params = array('hosts' => array ( - '127.0.0.1:80', + '127.0.0.1:1', $_SERVER['ES_TEST_HOST'], )); $params['retries'] = 0; @@ -132,7 +132,7 @@ public function testConstructorEmptyPort() 'hosts' => array('localhost:'), 'dic' => function ($hosts, $params) use ($mockDIC, $that) { - $expected = array(array('host' => 'localhost', 'port' => 9200)); + $expected = array(array('scheme' => 'http', 'host' => 'localhost', 'port' => 9200)); $that->assertEquals($expected, $hosts); return $mockDIC; } @@ -152,7 +152,7 @@ public function testConstructorNoPort() 'hosts' => array('localhost'), 'dic' => function ($hosts, $params) use ($mockDIC, $that) { - $expected = array(array('host' => 'localhost', 'port' => 9200)); + $expected = array(array('scheme' => 'http', 'host' => 'localhost', 'port' => 9200)); $that->assertEquals($expected, $hosts); return $mockDIC; } @@ -172,7 +172,7 @@ public function testConstructorWithPort() 'hosts' => array('localhost:9200'), 'dic' => function ($hosts, $params) use ($mockDIC, $that) { - $expected = array(array('host' => 'localhost', 'port' => 9200)); + $expected = array(array('scheme' => 'http', 'host' => 'localhost', 'port' => 9200)); $that->assertEquals($expected, $hosts); return $mockDIC; } @@ -192,7 +192,7 @@ public function testConstructorWithSchemeAndPort() 'hosts' => array('http://localhost:9200'), 'dic' => function ($hosts, $params) use ($mockDIC, $that) { - $expected = array(array('host' => 'localhost', 'port' => 9200)); + $expected = array(array('scheme' => 'http', 'host' => 'localhost', 'port' => 9200)); $that->assertEquals($expected, $hosts); return $mockDIC; } diff --git a/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolTest.php b/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolTest.php index 26d994eab..28877e831 100644 --- a/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolTest.php +++ b/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolTest.php @@ -74,7 +74,7 @@ public function testAddOneHostAndTriggerSniff() ->getMock(); $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory') - ->shouldReceive('create')->with('192.168.1.119', 9200)->andReturn($mockNewConnection)->getMock(); + ->shouldReceive('create')->with(array('host' => '192.168.1.119', 'port' => 9200))->andReturn($mockNewConnection)->getMock(); $connectionPoolParams = array( 'randomizeHosts' => false, @@ -106,7 +106,7 @@ public function testAddOneHostAndForceNext() ->shouldReceive('select')->once()->andReturn($mockNewConnection)->getMock(); $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory') - ->shouldReceive('create')->with('192.168.1.119', 9200)->andReturn($mockNewConnection)->getMock(); + ->shouldReceive('create')->with(array('host' => '192.168.1.119', 'port' => 9200))->andReturn($mockNewConnection)->getMock(); $connectionPoolParams = array( 'randomizeHosts' => false @@ -258,8 +258,8 @@ public function testAddOneHostSniffTwo() ->getMock(); $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory') - ->shouldReceive('create')->with('192.168.1.119', 9200)->andReturn($newConnections[0])->getMock() - ->shouldReceive('create')->with('192.168.1.119', 9201)->andReturn($newConnections[1])->getMock(); + ->shouldReceive('create')->with(array('host' => '192.168.1.119', 'port' => 9200))->andReturn($newConnections[0])->getMock() + ->shouldReceive('create')->with(array('host' => '192.168.1.119', 'port' => 9201))->andReturn($newConnections[1])->getMock(); $connectionPoolParams = array( 'randomizeHosts' => false, @@ -308,8 +308,8 @@ public function testAddSeed_SniffTwo_TimeoutTwo() ->getMock(); $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory') - ->shouldReceive('create')->with('192.168.1.119', 9200)->andReturn($newConnections[0])->getMock() - ->shouldReceive('create')->with('192.168.1.119', 9201)->andReturn($newConnections[1])->getMock(); + ->shouldReceive('create')->with(array('host' => '192.168.1.119', 'port' => 9200))->andReturn($newConnections[0])->getMock() + ->shouldReceive('create')->with(array('host' => '192.168.1.119', 'port' => 9201))->andReturn($newConnections[1])->getMock(); $connectionPoolParams = array( 'randomizeHosts' => false, @@ -361,8 +361,8 @@ public function testTen_TimeoutNine_SniffTenth_AddTwoAlive() ->getMock(); $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory') - ->shouldReceive('create')->with('192.168.1.119', 9200)->andReturn($newConnections[10])->getMock() - ->shouldReceive('create')->with('192.168.1.119', 9201)->andReturn($newConnections[11])->getMock(); + ->shouldReceive('create')->with(array('host' => '192.168.1.119', 'port' => 9200))->andReturn($newConnections[10])->getMock() + ->shouldReceive('create')->with(array('host' => '192.168.1.119', 'port' => 9201))->andReturn($newConnections[11])->getMock(); $connectionPoolParams = array( 'randomizeHosts' => false, @@ -424,8 +424,8 @@ public function testTen_TimeoutNine_SniffTenth_AddTwoDead_TimeoutEveryone() $RRConnections = $newConnections; //array_push($connections); $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory') - ->shouldReceive('create')->with('192.168.1.119', 9200)->andReturn($newConnections[10])->getMock() - ->shouldReceive('create')->with('192.168.1.119', 9201)->andReturn($newConnections[11])->getMock(); + ->shouldReceive('create')->with(array('host' => '192.168.1.119', 'port' => 9200))->andReturn($newConnections[10])->getMock() + ->shouldReceive('create')->with(array('host' => '192.168.1.119', 'port' => 9201))->andReturn($newConnections[11])->getMock(); $connectionPoolParams = array( 'randomizeHosts' => false, diff --git a/tests/Elasticsearch/Tests/Connections/AbstractConnectionTest.php b/tests/Elasticsearch/Tests/Connections/AbstractConnectionTest.php index b71d53796..33b42422c 100644 --- a/tests/Elasticsearch/Tests/Connections/AbstractConnectionTest.php +++ b/tests/Elasticsearch/Tests/Connections/AbstractConnectionTest.php @@ -36,8 +36,7 @@ public function testPing() $stub = $this->getMockForAbstractClass( 'Elasticsearch\Connections\AbstractConnection', array( - 'localhost', - 9200, + array('host' => 'localhost', 'port' => 9200), array(), $logger, $logger @@ -65,8 +64,7 @@ public function testPingBadCode() $stub = $this->getMockForAbstractClass( 'Elasticsearch\Connections\AbstractConnection', array( - 'localhost', - 9200, + array('host' => 'localhost', 'port' => 9200), array(), $logger, $logger @@ -94,8 +92,7 @@ public function testPingTimeout() $stub = $this->getMockForAbstractClass( 'Elasticsearch\Connections\AbstractConnection', array( - 'localhost', - 9200, + array('host' => 'localhost', 'port' => 9200), array(), $logger, $logger @@ -116,5 +113,23 @@ public function testPingTimeout() $this->assertFalse($ret); } + public function testURLPrefix() + { + $logger = new Elasticsearch\Common\EmptyLogger(); + + $stub = $this->getMockForAbstractClass( + 'Elasticsearch\Connections\AbstractConnection', + array( + array('host' => 'localhost', 'port' => 9200, 'path' => '/prefix'), + array(), + $logger, + $logger + ) + ); + + /** @var AbstractConnection $stub */ + $this->assertEquals('http://localhost:9200/prefix', $stub->getHost()); + } + } diff --git a/tests/Elasticsearch/Tests/Connections/ConnectionFactoryTest.php b/tests/Elasticsearch/Tests/Connections/ConnectionFactoryTest.php index 1f86712a5..d1943589d 100644 --- a/tests/Elasticsearch/Tests/Connections/ConnectionFactoryTest.php +++ b/tests/Elasticsearch/Tests/Connections/ConnectionFactoryTest.php @@ -24,7 +24,7 @@ public function tearDown() { public function testCreate() { $mockConnection = m::mock('\Elasticsearch\Connections\AbstractConnection'); - $mockFunction = function($host, $port, $params, $log, $trace) use ($mockConnection) { + $mockFunction = function($hostDetails, $params, $log, $trace) use ($mockConnection) { return $mockConnection; }; @@ -35,11 +35,13 @@ public function testCreate() ->shouldReceive('offsetGet')->with('logObject')->andReturn(array())->getMock() ->shouldReceive('offsetGet')->with('traceObject')->andReturn(array())->getMock(); - $host = 'localhost'; - $port = 9200; + $hostDetails = array( + 'host' => 'localhost', + 'port' => 9200 + ); $factory = new ConnectionFactory($mockPimple); - $connection = $factory->create($host, $port); + $connection = $factory->create($hostDetails); $this->assertEquals($mockConnection, $connection); } diff --git a/tests/Elasticsearch/Tests/Connections/CurlMultiConnectionTest.php b/tests/Elasticsearch/Tests/Connections/CurlMultiConnectionTest.php index bd63ce3a7..d0dc364e3 100644 --- a/tests/Elasticsearch/Tests/Connections/CurlMultiConnectionTest.php +++ b/tests/Elasticsearch/Tests/Connections/CurlMultiConnectionTest.php @@ -38,14 +38,13 @@ public function tearDown() */ public function testNoMultihandle() { - $host = 'localhost'; - $port = 9200; + $hostDetails = array('host' => 'localhost', 'port' => 9200); $connectionParams = null; $log = $this->getMockBuilder('\Monolog\Logger') ->disableOriginalConstructor() ->getMock(); - $connection = new Elasticsearch\Connections\CurlMultiConnection($host, $port, $connectionParams, $log, $log); + $connection = new Elasticsearch\Connections\CurlMultiConnection($hostDetails, $connectionParams, $log, $log); }//end testNoMultihandle() @@ -60,14 +59,13 @@ public function testNoMultihandle() */ public function testBadHost() { - $host = 'localhost5'; - $port = 9200; + $hostDetails = array('host' => 'localhost5', 'port' => 9200); $connectionParams['curlMultiHandle'] = curl_multi_init(); $log = $this->getMockBuilder('\Monolog\Logger') ->disableOriginalConstructor() ->getMock(); - $connection = new Elasticsearch\Connections\CurlMultiConnection($host, $port, $connectionParams, $log, $log); + $connection = new Elasticsearch\Connections\CurlMultiConnection($hostDetails, $connectionParams, $log, $log); $ret = $connection->performRequest('GET', '/'); }//end testBadHost() @@ -83,14 +81,13 @@ public function testBadHost() */ public function testBadPort() { - $host = 'localhost'; - $port = 9800; + $hostDetails = array('host' => 'localhost', 'port' => 9800); $connectionParams['curlMultiHandle'] = curl_multi_init(); $log = $this->getMockBuilder('\Monolog\Logger') ->disableOriginalConstructor() ->getMock(); - $connection = new Elasticsearch\Connections\CurlMultiConnection($host, $port, $connectionParams, $log, $log); + $connection = new Elasticsearch\Connections\CurlMultiConnection($hostDetails, $connectionParams, $log, $log); $ret = $connection->performRequest('GET', '/'); } @@ -98,8 +95,7 @@ public function testBadPort() public function testPingTimeout() { - $host = 'localhost'; - $port = 9800; + $hostDetails = array('host' => 'localhost', 'port' => 9800); $opts = array(); $connectionParams['curlMultiHandle'] = curl_multi_init(); @@ -115,7 +111,7 @@ public function testPingTimeout() $log = m::mock('Psr\Log\LoggerInterface')->shouldReceive('debug')->with("Curl Options:", \Mockery::on($argsValidator))->getMock(); $trace = m::mock('Psr\Log\LoggerInterface'); - $connection = new Elasticsearch\Connections\CurlMultiConnection($host, $port, $connectionParams, $log, $trace); + $connection = new Elasticsearch\Connections\CurlMultiConnection($hostDetails, $connectionParams, $log, $trace); try{ $ret = $connection->performRequest('GET', '/', null, null, array('timeout' => 5000)); } catch (\Exception $e) { diff --git a/tests/Elasticsearch/Tests/Connections/GuzzleConnectionIntegrationTest.php b/tests/Elasticsearch/Tests/Connections/GuzzleConnectionIntegrationTest.php index ee796620c..29d7c1286 100644 --- a/tests/Elasticsearch/Tests/Connections/GuzzleConnectionIntegrationTest.php +++ b/tests/Elasticsearch/Tests/Connections/GuzzleConnectionIntegrationTest.php @@ -36,14 +36,13 @@ public function tearDown() */ public function test5xxErrorBadHost() { - $host = 'localhost5'; - $port = 9200; + $hostDetails = array('host' => 'localhost5', 'port' => 9200); $connectionParams['guzzleClient'] = new Client(); $log = m::mock('\Monolog\Logger')->shouldReceive('error')->once()->getMock(); - $connection = new GuzzleConnection($host, $port, $connectionParams, $log, $log); + $connection = new GuzzleConnection($hostDetails, $connectionParams, $log, $log); $ret = $connection->performRequest('GET', '/'); } @@ -54,12 +53,11 @@ public function test5xxErrorBadHost() */ public function test5xxErrorBadPort() { - $host = 'localhost'; - $port = 9800; + $hostDetails = array('host' => 'localhost', 'port' => 9800); $connectionParams['guzzleClient'] = new Client(); $log = m::mock('\Monolog\Logger')->shouldReceive('error')->once()->getMock(); - $connection = new GuzzleConnection($host, $port, $connectionParams, $log, $log); + $connection = new GuzzleConnection($hostDetails, $connectionParams, $log, $log); $ret = $connection->performRequest('GET', '/'); } @@ -70,8 +68,7 @@ public function test5xxErrorBadPort() */ public function test4xxErrorNonexistantEndpoint() { - $host = 'localhost'; - $port = 9200; + $hostDetails = array('host' => 'localhost', 'port' => 9200); $connectionParams['guzzleClient'] = new Client(); $log = m::mock('\Monolog\Logger') ->shouldReceive('debug') @@ -79,7 +76,7 @@ public function test4xxErrorNonexistantEndpoint() ->shouldReceive('info') ->times(4)->getMock(); - $connection = new GuzzleConnection($host, $port, $connectionParams, $log, $log); + $connection = new GuzzleConnection($hostDetails, $connectionParams, $log, $log); $ret = $connection->performRequest('GET', '/abc'); $this->assertEquals(400, $ret['status']); @@ -91,8 +88,7 @@ public function test4xxErrorNonexistantEndpoint() */ public function testQueryParams() { - $host = 'localhost'; - $port = 9200; + $hostDetails = array('host' => 'localhost', 'port' => 9200); $connectionParams['guzzleClient'] = new Client(); $log = m::mock('\Monolog\Logger') ->shouldReceive('debug') @@ -100,7 +96,7 @@ public function testQueryParams() ->shouldReceive('info') ->times(2)->getMock(); - $connection = new GuzzleConnection($host, $port, $connectionParams, $log, $log); + $connection = new GuzzleConnection($hostDetails, $connectionParams, $log, $log); $params['pretty'] = 'true'; $ret = $connection->performRequest('GET', '/', $params); @@ -117,8 +113,7 @@ public function testQueryParams() */ public function testQueryURI() { - $host = 'localhost'; - $port = 9200; + $hostDetails = array('host' => 'localhost', 'port' => 9200); $connectionParams['guzzleClient'] = new Client(); $log = m::mock('\Monolog\Logger') ->shouldReceive('debug') @@ -126,7 +121,7 @@ public function testQueryURI() ->shouldReceive('info') ->times(2)->getMock(); - $connection = new GuzzleConnection($host, $port, $connectionParams, $log, $log); + $connection = new GuzzleConnection($hostDetails, $connectionParams, $log, $log); $ret = $connection->performRequest('GET', '/_cluster/nodes/'); @@ -140,8 +135,7 @@ public function testQueryURI() */ public function test4xxErrorInvalidIndexAndQueryBody() { - $host = 'localhost'; - $port = 9200; + $hostDetails = array('host' => 'localhost', 'port' => 9200); $connectionParams['guzzleClient'] = new Client(); $log = m::mock('\Monolog\Logger') ->shouldReceive('debug') @@ -149,7 +143,7 @@ public function test4xxErrorInvalidIndexAndQueryBody() ->shouldReceive('info') ->times(4)->getMock(); - $connection = new GuzzleConnection($host, $port, $connectionParams, $log, $log); + $connection = new GuzzleConnection($hostDetails, $connectionParams, $log, $log); $body = '{"testsetting":"123"}'; diff --git a/tests/Elasticsearch/Tests/Connections/GuzzleConnectionTest.php b/tests/Elasticsearch/Tests/Connections/GuzzleConnectionTest.php index 060fa19ea..4630b100a 100644 --- a/tests/Elasticsearch/Tests/Connections/GuzzleConnectionTest.php +++ b/tests/Elasticsearch/Tests/Connections/GuzzleConnectionTest.php @@ -33,13 +33,12 @@ public function tearDown() */ public function testNoGuzzleClient() { - $host = 'localhost'; - $port = 9200; + $hostDetails = array('host' => 'localhost', 'port' => 9200); $connectionParams = null; $log = m::mock('\Monolog\Logger')->shouldReceive('critical')->once()->getMock(); - $connection = new GuzzleConnection($host, $port, $connectionParams, $log, $log); + $connection = new GuzzleConnection($hostDetails, $connectionParams, $log, $log); }