From aef38214fa38b77e85b8e7e93ef65afde872ad76 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Fri, 11 Aug 2017 23:26:30 +0200 Subject: [PATCH] [TEST] convert array() to [] syntax --- tests/Elasticsearch/Tests/ClientTest.php | 12 +-- .../Selectors/RoundRobinSelectorTest.php | 4 +- .../StickyRoundRobinSelectorTest.php | 4 +- .../SniffingConnectionPoolTest.php | 84 +++++++++---------- .../StaticConnectionPoolTest.php | 10 +-- .../Iterators/SearchResponseIteratorTest.php | 26 +++--- .../Serializers/ArrayToJSONSerializerTest.php | 4 +- .../EverythingToJSONSerializerTest.php | 4 +- 8 files changed, 74 insertions(+), 74 deletions(-) diff --git a/tests/Elasticsearch/Tests/ClientTest.php b/tests/Elasticsearch/Tests/ClientTest.php index 05fc7b049..adda8e86b 100644 --- a/tests/Elasticsearch/Tests/ClientTest.php +++ b/tests/Elasticsearch/Tests/ClientTest.php @@ -36,18 +36,18 @@ public function testConstructorIllegalPort() public function testCustomQueryParams() { - $params = array(); + $params = []; $client = Elasticsearch\ClientBuilder::create()->setHosts([$_SERVER['ES_TEST_HOST']])->build(); - $getParams = array( + $getParams = [ 'index' => 'test', 'type' => 'test', 'id' => 1, 'parent' => 'abc', - 'custom' => array('customToken' => 'abc', 'otherToken' => 123), + 'custom' => ['customToken' => 'abc', 'otherToken' => 123], 'client' => ['ignore' => 400] - ); + ]; $exists = $client->exists($getParams); } @@ -227,7 +227,7 @@ public function testMaxRetriesException() ->setRetries(0) ->build(); - $searchParams = array( + $searchParams = [ 'index' => 'test', 'type' => 'test', 'body' => [ @@ -235,7 +235,7 @@ public function testMaxRetriesException() 'match_all' => [] ] ] - ); + ]; $client = Elasticsearch\ClientBuilder::create() ->setHosts(["localhost:1"]) diff --git a/tests/Elasticsearch/Tests/ConnectionPool/Selectors/RoundRobinSelectorTest.php b/tests/Elasticsearch/Tests/ConnectionPool/Selectors/RoundRobinSelectorTest.php index 72f3caa1d..3491e23f5 100644 --- a/tests/Elasticsearch/Tests/ConnectionPool/Selectors/RoundRobinSelectorTest.php +++ b/tests/Elasticsearch/Tests/ConnectionPool/Selectors/RoundRobinSelectorTest.php @@ -29,7 +29,7 @@ public function testTenConnections() { $roundRobin = new Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector(); - $mockConnections = array(); + $mockConnections = []; foreach (range(0, 10) as $index) { $mockConnections[$index] = $this->getMockBuilder('\Elasticsearch\Connections\CurlMultiConnection') ->disableOriginalConstructor() @@ -56,7 +56,7 @@ public function testAddTenConnectionsestFiveTRemoveThree() { $roundRobin = new Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector(); - $mockConnections = array(); + $mockConnections = []; foreach (range(0, 10) as $index) { $mockConnections[$index] = $this->getMockBuilder('\Elasticsearch\Connections\CurlMultiConnection') ->disableOriginalConstructor() diff --git a/tests/Elasticsearch/Tests/ConnectionPool/Selectors/StickyRoundRobinSelectorTest.php b/tests/Elasticsearch/Tests/ConnectionPool/Selectors/StickyRoundRobinSelectorTest.php index 69ea7262f..b16623c62 100644 --- a/tests/Elasticsearch/Tests/ConnectionPool/Selectors/StickyRoundRobinSelectorTest.php +++ b/tests/Elasticsearch/Tests/ConnectionPool/Selectors/StickyRoundRobinSelectorTest.php @@ -28,7 +28,7 @@ public function testTenConnections() { $roundRobin = new Elasticsearch\ConnectionPool\Selectors\StickyRoundRobinSelector(); - $mockConnections = array(); + $mockConnections = []; $mockConnections[] = m::mock('\Elasticsearch\Connections\GuzzleConnection') ->shouldReceive('isAlive')->times(16)->andReturn(true)->getMock(); @@ -47,7 +47,7 @@ public function testTenConnectionsFirstDies() { $roundRobin = new Elasticsearch\ConnectionPool\Selectors\StickyRoundRobinSelector(); - $mockConnections = array(); + $mockConnections = []; $mockConnections[] = m::mock('\Elasticsearch\Connections\GuzzleConnection') ->shouldReceive('isAlive')->once()->andReturn(false)->getMock(); diff --git a/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolTest.php b/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolTest.php index 53376b274..720bd90d6 100644 --- a/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolTest.php +++ b/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolTest.php @@ -38,7 +38,7 @@ public function testAddOneHostThenGetConnection() ->andReturn(true) ->getMock(); - $connections = array($mockConnection); + $connections = [$mockConnection]; $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select') @@ -47,7 +47,7 @@ public function testAddOneHostThenGetConnection() $connectionFactory = m::mock(ConnectionFactory::class); - $connectionPoolParams = array('randomizeHosts' => false); + $connectionPoolParams = ['randomizeHosts' => false]; $connectionPool = new SniffingConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); $retConnection = $connectionPool->nextConnection(); @@ -65,7 +65,7 @@ public function testAddOneHostAndTriggerSniff() ->shouldReceive('getTransportSchema')->once()->andReturn('http')->getMock() ->shouldReceive('sniff')->once()->andReturn($clusterState)->getMock(); - $connections = array($mockConnection); + $connections = [$mockConnection]; $mockNewConnection = m::mock(Connection::class) ->shouldReceive('isAlive')->andReturn(true)->getMock(); @@ -75,12 +75,12 @@ public function testAddOneHostAndTriggerSniff() ->getMock(); $connectionFactory = m::mock(ConnectionFactory::class) - ->shouldReceive('create')->with(array('host' => '192.168.1.119', 'port' => 9200))->andReturn($mockNewConnection)->getMock(); + ->shouldReceive('create')->with(['host' => '192.168.1.119', 'port' => 9200])->andReturn($mockNewConnection)->getMock(); - $connectionPoolParams = array( + $connectionPoolParams = [ 'randomizeHosts' => false, 'sniffingInterval' => -1 - ); + ]; $connectionPool = new SniffingConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); $retConnection = $connectionPool->nextConnection(); @@ -98,7 +98,7 @@ public function testAddOneHostAndForceNext() ->shouldReceive('getTransportSchema')->once()->andReturn('http')->getMock() ->shouldReceive('sniff')->once()->andReturn($clusterState)->getMock(); - $connections = array($mockConnection); + $connections = [$mockConnection]; $mockNewConnection = m::mock(Connection::class) ->shouldReceive('isAlive')->andReturn(true)->getMock(); @@ -107,11 +107,11 @@ public function testAddOneHostAndForceNext() ->shouldReceive('select')->once()->andReturn($mockNewConnection)->getMock(); $connectionFactory = m::mock(ConnectionFactory::class) - ->shouldReceive('create')->with(array('host' => '192.168.1.119', 'port' => 9200))->andReturn($mockNewConnection)->getMock(); + ->shouldReceive('create')->with(['host' => '192.168.1.119', 'port' => 9200])->andReturn($mockNewConnection)->getMock(); - $connectionPoolParams = array( + $connectionPoolParams = [ 'randomizeHosts' => false - ); + ]; $connectionPool = new SniffingConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); $retConnection = $connectionPool->nextConnection(true); @@ -121,7 +121,7 @@ public function testAddOneHostAndForceNext() public function testAddTenNodesThenGetConnection() { - $connections = array(); + $connections = []; foreach (range(1, 10) as $index) { $mockConnection = m::mock(Connection::class) @@ -142,7 +142,7 @@ public function testAddTenNodesThenGetConnection() $connectionFactory = m::mock(ConnectionFactory::class); - $connectionPoolParams = array('randomizeHosts' => false); + $connectionPoolParams = ['randomizeHosts' => false]; $connectionPool = new SniffingConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); $retConnection = $connectionPool->nextConnection(); @@ -152,7 +152,7 @@ public function testAddTenNodesThenGetConnection() public function testAddTenNodesTimeoutAllButLast() { - $connections = array(); + $connections = []; foreach (range(1, 9) as $index) { $mockConnection = m::mock(Connection::class) @@ -183,7 +183,7 @@ public function testAddTenNodesTimeoutAllButLast() $connectionFactory = m::mock(ConnectionFactory::class); - $connectionPoolParams = array('randomizeHosts' => false); + $connectionPoolParams = ['randomizeHosts' => false]; $connectionPool = new SniffingConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); $retConnection = $connectionPool->nextConnection(); @@ -196,7 +196,7 @@ public function testAddTenNodesTimeoutAllButLast() */ public function testAddTenNodesAllTimeout() { - $connections = array(); + $connections = []; foreach (range(1, 10) as $index) { $mockConnection = m::mock(Connection::class) @@ -217,7 +217,7 @@ public function testAddTenNodesAllTimeout() $connectionFactory = m::mock(ConnectionFactory::class); - $connectionPoolParams = array('randomizeHosts' => false); + $connectionPoolParams = ['randomizeHosts' => false]; $connectionPool = new SniffingConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); $retConnection = $connectionPool->nextConnection(); @@ -233,9 +233,9 @@ public function testAddOneHostSniffTwo() ->shouldReceive('getTransportSchema')->twice()->andReturn('http')->getMock() ->shouldReceive('sniff')->twice()->andReturn($clusterState)->getMock(); - $connections = array($mockConnection); + $connections = [$mockConnection]; - $newConnections = array(); + $newConnections = []; $newConnections[] = m::mock(Connection::class) ->shouldReceive('isAlive')->andReturn(true)->getMock(); @@ -244,21 +244,21 @@ public function testAddOneHostSniffTwo() $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select') - ->andReturnValues(array( //selects provided node first, then the new cluster list + ->andReturnValues([ //selects provided node first, then the new cluster list $mockConnection, $newConnections[0], $newConnections[1] - )) + ]) ->getMock(); $connectionFactory = m::mock(ConnectionFactory::class) - ->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(); + ->shouldReceive('create')->with(['host' => '192.168.1.119', 'port' => 9200])->andReturn($newConnections[0])->getMock() + ->shouldReceive('create')->with(['host' => '192.168.1.119', 'port' => 9201])->andReturn($newConnections[1])->getMock(); - $connectionPoolParams = array( + $connectionPoolParams = [ 'randomizeHosts' => false, 'sniffingInterval' => -1 - ); + ]; $connectionPool = new SniffingConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); $retConnection = $connectionPool->nextConnection(); @@ -281,9 +281,9 @@ public function testAddSeed_SniffTwo_TimeoutTwo() ->shouldReceive('getTransportSchema')->once()->andReturn('http')->getMock() ->shouldReceive('sniff')->once()->andReturn($clusterState)->getMock(); - $connections = array($mockConnection); + $connections = [$mockConnection]; - $newConnections = array(); + $newConnections = []; $newConnections[] = m::mock(Connection::class) ->shouldReceive('isAlive')->andReturn(false)->getMock() ->shouldReceive('ping')->andReturn(false)->getMock(); @@ -294,21 +294,21 @@ public function testAddSeed_SniffTwo_TimeoutTwo() $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select') - ->andReturnValues(array( //selects provided node first, then the new cluster list + ->andReturnValues([ //selects provided node first, then the new cluster list $mockConnection, $newConnections[0], $newConnections[1] - )) + ]) ->getMock(); $connectionFactory = m::mock(ConnectionFactory::class) - ->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(); + ->shouldReceive('create')->with(['host' => '192.168.1.119', 'port' => 9200])->andReturn($newConnections[0])->getMock() + ->shouldReceive('create')->with(['host' => '192.168.1.119', 'port' => 9201])->andReturn($newConnections[1])->getMock(); - $connectionPoolParams = array( + $connectionPoolParams = [ 'randomizeHosts' => false, 'sniffingInterval' => -1 - ); + ]; $connectionPool = new SniffingConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); $retConnection = $connectionPool->nextConnection(); @@ -319,7 +319,7 @@ public function testTen_TimeoutNine_SniffTenth_AddTwoAlive() { $clusterState = json_decode('{"ok":true,"cluster_name":"elasticsearch_zach","nodes":{"node1":{"name":"Vesta","transport_address":"inet[/192.168.1.119:9300]","hostname":"zach-ThinkPad-W530","version":"0.90.5","http_address":"inet[/192.168.1.119:9200]"}, "node2":{"name":"Vesta","transport_address":"inet[/192.168.1.119:9301]","hostname":"zach-ThinkPad-W530","version":"0.90.5","http_address":"inet[/192.168.1.119:9201]"}}}', true); - $connections = array(); + $connections = []; foreach (range(1, 10) as $index) { $mockConnection = m::mock(Connection::class) @@ -353,13 +353,13 @@ public function testTen_TimeoutNine_SniffTenth_AddTwoAlive() ->getMock(); $connectionFactory = m::mock(ConnectionFactory::class) - ->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(); + ->shouldReceive('create')->with(['host' => '192.168.1.119', 'port' => 9200])->andReturn($newConnections[10])->getMock() + ->shouldReceive('create')->with(['host' => '192.168.1.119', 'port' => 9201])->andReturn($newConnections[11])->getMock(); - $connectionPoolParams = array( + $connectionPoolParams = [ 'randomizeHosts' => false, 'sniffingInterval' => -1 - ); + ]; $connectionPool = new SniffingConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); $retConnection = $connectionPool->nextConnection(); @@ -376,7 +376,7 @@ public function testTen_TimeoutNine_SniffTenth_AddTwoDead_TimeoutEveryone() { $clusterState = json_decode('{"ok":true,"cluster_name":"elasticsearch_zach","nodes":{"node1":{"name":"Vesta","transport_address":"inet[/192.168.1.119:9300]","hostname":"zach-ThinkPad-W530","version":"0.90.5","http_address":"inet[/192.168.1.119:9200]"}, "node2":{"name":"Vesta","transport_address":"inet[/192.168.1.119:9301]","hostname":"zach-ThinkPad-W530","version":"0.90.5","http_address":"inet[/192.168.1.119:9201]"}}}', true); - $connections = array(); + $connections = []; foreach (range(1, 10) as $index) { $mockConnection = m::mock(Connection::class) @@ -415,13 +415,13 @@ public function testTen_TimeoutNine_SniffTenth_AddTwoDead_TimeoutEveryone() $RRConnections = $newConnections; //array_push($connections); $connectionFactory = m::mock(ConnectionFactory::class) - ->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(); + ->shouldReceive('create')->with(['host' => '192.168.1.119', 'port' => 9200])->andReturn($newConnections[10])->getMock() + ->shouldReceive('create')->with(['host' => '192.168.1.119', 'port' => 9201])->andReturn($newConnections[11])->getMock(); - $connectionPoolParams = array( + $connectionPoolParams = [ 'randomizeHosts' => false, 'sniffingInterval' => -1 - ); + ]; $connectionPool = new SniffingConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); $retConnection = $connectionPool->nextConnection(); diff --git a/tests/Elasticsearch/Tests/ConnectionPool/StaticConnectionPoolTest.php b/tests/Elasticsearch/Tests/ConnectionPool/StaticConnectionPoolTest.php index 092644a80..118225fbc 100644 --- a/tests/Elasticsearch/Tests/ConnectionPool/StaticConnectionPoolTest.php +++ b/tests/Elasticsearch/Tests/ConnectionPool/StaticConnectionPoolTest.php @@ -39,7 +39,7 @@ public function testAddOneHostThenGetConnection() ->getMock() ->shouldReceive('markDead')->once()->getMock(); - $connections = array($mockConnection); + $connections = [$mockConnection]; $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select') @@ -58,7 +58,7 @@ public function testAddOneHostThenGetConnection() public function testAddMultipleHostsThenGetFirst() { - $connections = array(); + $connections = []; foreach (range(1, 10) as $index) { $mockConnection = m::mock(Connection::class) @@ -93,7 +93,7 @@ public function testAddMultipleHostsThenGetFirst() */ public function testAllHostsFailPing() { - $connections = array(); + $connections = []; foreach (range(1, 10) as $index) { $mockConnection = m::mock(Connection::class) @@ -125,7 +125,7 @@ public function testAllHostsFailPing() public function testAllExceptLastHostFailPingRevivesInSkip() { - $connections = array(); + $connections = []; foreach (range(1, 9) as $index) { $mockConnection = m::mock(Connection::class) @@ -171,7 +171,7 @@ public function testAllExceptLastHostFailPingRevivesInSkip() public function testAllExceptLastHostFailPingRevivesPreSkip() { - $connections = array(); + $connections = []; foreach (range(1, 9) as $index) { $mockConnection = m::mock(Connection::class) diff --git a/tests/Elasticsearch/Tests/Helper/Iterators/SearchResponseIteratorTest.php b/tests/Elasticsearch/Tests/Helper/Iterators/SearchResponseIteratorTest.php index 447df456c..20d03ddf8 100644 --- a/tests/Elasticsearch/Tests/Helper/Iterators/SearchResponseIteratorTest.php +++ b/tests/Elasticsearch/Tests/Helper/Iterators/SearchResponseIteratorTest.php @@ -25,16 +25,16 @@ public function tearDown() public function testWithNoResults() { - $search_params = array( + $search_params = [ 'scroll' => '5m', 'index' => 'twitter', 'size' => 1000, - 'body' => array( - 'query' => array( + 'body' => [ + 'query' => [ 'match_all' => new \StdClass - ) - ) - ); + ] + ] + ]; $mock_client = m::mock(Client::class); @@ -42,7 +42,7 @@ public function testWithNoResults() ->once() ->ordered() ->with($search_params) - ->andReturn(array('_scroll_id' => 'scroll_id_01')); + ->andReturn(['_scroll_id' => 'scroll_id_01']); $mock_client->shouldReceive('scroll') ->never(); @@ -60,16 +60,16 @@ public function testWithNoResults() public function testWithHits() { - $search_params = array( + $search_params = [ 'scroll' => '5m', 'index' => 'twitter', 'size' => 1000, - 'body' => array( - 'query' => array( + 'body' => [ + 'query' => [ 'match_all' => new \StdClass - ) - ) - ); + ] + ] + ]; $mock_client = m::mock(Client::class); diff --git a/tests/Elasticsearch/Tests/Serializers/ArrayToJSONSerializerTest.php b/tests/Elasticsearch/Tests/Serializers/ArrayToJSONSerializerTest.php index 4913df781..d66860574 100644 --- a/tests/Elasticsearch/Tests/Serializers/ArrayToJSONSerializerTest.php +++ b/tests/Elasticsearch/Tests/Serializers/ArrayToJSONSerializerTest.php @@ -22,7 +22,7 @@ public function tearDown() public function testSerializeArray() { $serializer = new ArrayToJSONSerializer(); - $body = array('value' => 'field'); + $body = ['value' => 'field']; $ret = $serializer->serialize($body); @@ -45,7 +45,7 @@ public function testDeserializeJSON() $serializer = new ArrayToJSONSerializer(); $body = '{"field":"value"}'; - $ret = $serializer->deserialize($body, array()); + $ret = $serializer->deserialize($body, []); $body = json_decode($body, true); $this->assertSame($body, $ret); diff --git a/tests/Elasticsearch/Tests/Serializers/EverythingToJSONSerializerTest.php b/tests/Elasticsearch/Tests/Serializers/EverythingToJSONSerializerTest.php index 15a4f2a02..1fcd9f598 100644 --- a/tests/Elasticsearch/Tests/Serializers/EverythingToJSONSerializerTest.php +++ b/tests/Elasticsearch/Tests/Serializers/EverythingToJSONSerializerTest.php @@ -22,7 +22,7 @@ public function tearDown() public function testSerializeArray() { $serializer = new EverythingToJSONSerializer(); - $body = array('value' => 'field'); + $body = ['value' => 'field']; $ret = $serializer->serialize($body); @@ -46,7 +46,7 @@ public function testDeserializeJSON() $serializer = new EverythingToJSONSerializer(); $body = '{"field":"value"}'; - $ret = $serializer->deserialize($body, array()); + $ret = $serializer->deserialize($body, []); $body = json_decode($body, true); $this->assertSame($body, $ret);