From dc5d18ca4869fd16839f66adbc5880d1a408fca1 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Mon, 21 Aug 2017 20:22:33 +0200 Subject: [PATCH] [TEST] tests code cleanup (#618) * [TEST] use ::class instead of classname string Reason - when the class is renamed or removed, it will be detected much faster. It helps with the static analysis of the code (also used by IDEs) * [TEST] use assertSame() instead of assertEquals() assertEquals() means == assertSame() is === Can cause tests not detecting issues, because different instances of same class with same data are equal, but not the same. * [TEST] convert array() to [] syntax * [TEST] $this->assert* should be used See https://github.com/sebastianbergmann/phpunit/issues/1914#issuecomment-148407321 --- tests/Elasticsearch/Tests/ClientTest.php | 73 +++--- .../SniffingConnectionPoolIntegrationTest.php | 3 +- .../SniffingConnectionPoolTest.php | 208 +++++++++--------- .../StaticConnectionPoolTest.php | 68 +++--- .../Iterators/SearchResponseIteratorTest.php | 31 +-- .../Tests/RegisteredNamespaceTest.php | 4 +- .../Serializers/ArrayToJSONSerializerTest.php | 10 +- .../EverythingToJSONSerializerTest.php | 10 +- tests/Elasticsearch/Tests/YamlRunnerTest.php | 52 ++--- 9 files changed, 235 insertions(+), 224 deletions(-) diff --git a/tests/Elasticsearch/Tests/ClientTest.php b/tests/Elasticsearch/Tests/ClientTest.php index bebf412db..adda8e86b 100644 --- a/tests/Elasticsearch/Tests/ClientTest.php +++ b/tests/Elasticsearch/Tests/ClientTest.php @@ -6,6 +6,7 @@ use Elasticsearch; use Elasticsearch\ClientBuilder; +use Elasticsearch\Common\Exceptions\MaxRetriesException; use Mockery as m; /** @@ -35,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); } @@ -226,7 +227,7 @@ public function testMaxRetriesException() ->setRetries(0) ->build(); - $searchParams = array( + $searchParams = [ 'index' => 'test', 'type' => 'test', 'body' => [ @@ -234,7 +235,7 @@ public function testMaxRetriesException() 'match_all' => [] ] ] - ); + ]; $client = Elasticsearch\ClientBuilder::create() ->setHosts(["localhost:1"]) @@ -247,7 +248,7 @@ public function testMaxRetriesException() } catch (Elasticsearch\Common\Exceptions\Curl\CouldNotConnectToHost $e) { // All good $previous = $e->getPrevious(); - $this->assertInstanceOf('Elasticsearch\Common\Exceptions\MaxRetriesException', $previous); + $this->assertInstanceOf(MaxRetriesException::class, $previous); } catch (\Exception $e) { throw $e; } @@ -264,7 +265,7 @@ public function testMaxRetriesException() } catch (Elasticsearch\Common\Exceptions\TransportException $e) { // All good $previous = $e->getPrevious(); - $this->assertInstanceOf('Elasticsearch\Common\Exceptions\MaxRetriesException', $previous); + $this->assertInstanceOf(MaxRetriesException::class, $previous); } catch (\Exception $e) { throw $e; } @@ -276,39 +277,39 @@ public function testInlineHosts() 'localhost:9200' ])->build(); $host = $client->transport->getConnection(); - $this->assertEquals("localhost:9200", $host->getHost()); - $this->assertEquals("http", $host->getTransportSchema()); + $this->assertSame("localhost:9200", $host->getHost()); + $this->assertSame("http", $host->getTransportSchema()); $client = Elasticsearch\ClientBuilder::create()->setHosts([ 'http://localhost:9200' ])->build(); $host = $client->transport->getConnection(); - $this->assertEquals("localhost:9200", $host->getHost()); - $this->assertEquals("http", $host->getTransportSchema()); + $this->assertSame("localhost:9200", $host->getHost()); + $this->assertSame("http", $host->getTransportSchema()); $client = Elasticsearch\ClientBuilder::create()->setHosts([ 'http://foo.com:9200' ])->build(); $host = $client->transport->getConnection(); - $this->assertEquals("foo.com:9200", $host->getHost()); - $this->assertEquals("http", $host->getTransportSchema()); + $this->assertSame("foo.com:9200", $host->getHost()); + $this->assertSame("http", $host->getTransportSchema()); $client = Elasticsearch\ClientBuilder::create()->setHosts([ 'https://foo.com:9200' ])->build(); $host = $client->transport->getConnection(); - $this->assertEquals("foo.com:9200", $host->getHost()); - $this->assertEquals("https", $host->getTransportSchema()); + $this->assertSame("foo.com:9200", $host->getHost()); + $this->assertSame("https", $host->getTransportSchema()); $client = Elasticsearch\ClientBuilder::create()->setHosts([ 'https://user:pass@foo.com:9200' ])->build(); $host = $client->transport->getConnection(); - $this->assertEquals("foo.com:9200", $host->getHost()); - $this->assertEquals("https", $host->getTransportSchema()); - $this->assertEquals("user:pass", $host->getUserPass()); + $this->assertSame("foo.com:9200", $host->getHost()); + $this->assertSame("https", $host->getTransportSchema()); + $this->assertSame("user:pass", $host->getUserPass()); } public function testExtendedHosts() @@ -321,8 +322,8 @@ public function testExtendedHosts() ] ])->build(); $host = $client->transport->getConnection(); - $this->assertEquals("localhost:9200", $host->getHost()); - $this->assertEquals("http", $host->getTransportSchema()); + $this->assertSame("localhost:9200", $host->getHost()); + $this->assertSame("http", $host->getTransportSchema()); $client = Elasticsearch\ClientBuilder::create()->setHosts([ @@ -333,8 +334,8 @@ public function testExtendedHosts() ] ])->build(); $host = $client->transport->getConnection(); - $this->assertEquals("foo.com:9200", $host->getHost()); - $this->assertEquals("http", $host->getTransportSchema()); + $this->assertSame("foo.com:9200", $host->getHost()); + $this->assertSame("http", $host->getTransportSchema()); $client = Elasticsearch\ClientBuilder::create()->setHosts([ @@ -345,8 +346,8 @@ public function testExtendedHosts() ] ])->build(); $host = $client->transport->getConnection(); - $this->assertEquals("foo.com:9200", $host->getHost()); - $this->assertEquals("https", $host->getTransportSchema()); + $this->assertSame("foo.com:9200", $host->getHost()); + $this->assertSame("https", $host->getTransportSchema()); $client = Elasticsearch\ClientBuilder::create()->setHosts([ @@ -356,8 +357,8 @@ public function testExtendedHosts() ] ])->build(); $host = $client->transport->getConnection(); - $this->assertEquals("foo.com:9200", $host->getHost()); - $this->assertEquals("http", $host->getTransportSchema()); + $this->assertSame("foo.com:9200", $host->getHost()); + $this->assertSame("http", $host->getTransportSchema()); $client = Elasticsearch\ClientBuilder::create()->setHosts([ @@ -366,8 +367,8 @@ public function testExtendedHosts() ] ])->build(); $host = $client->transport->getConnection(); - $this->assertEquals("foo.com:9200", $host->getHost()); - $this->assertEquals("http", $host->getTransportSchema()); + $this->assertSame("foo.com:9200", $host->getHost()); + $this->assertSame("http", $host->getTransportSchema()); $client = Elasticsearch\ClientBuilder::create()->setHosts([ @@ -378,8 +379,8 @@ public function testExtendedHosts() ] ])->build(); $host = $client->transport->getConnection(); - $this->assertEquals("foo.com:9500", $host->getHost()); - $this->assertEquals("https", $host->getTransportSchema()); + $this->assertSame("foo.com:9500", $host->getHost()); + $this->assertSame("https", $host->getTransportSchema()); try { @@ -401,8 +402,8 @@ public function testExtendedHosts() ] ])->build(); $host = $client->transport->getConnection(); - $this->assertEquals("the_foo.com:9200", $host->getHost()); - $this->assertEquals("http", $host->getTransportSchema()); + $this->assertSame("the_foo.com:9200", $host->getHost()); + $this->assertSame("http", $host->getTransportSchema()); // Special characters in user/pass, would break inline @@ -414,8 +415,8 @@ public function testExtendedHosts() ] ])->build(); $host = $client->transport->getConnection(); - $this->assertEquals("foo.com:9200", $host->getHost()); - $this->assertEquals("http", $host->getTransportSchema()); - $this->assertEquals("user:abc#$@?%!abc", $host->getUserPass()); + $this->assertSame("foo.com:9200", $host->getHost()); + $this->assertSame("http", $host->getTransportSchema()); + $this->assertSame("user:abc#$@?%!abc", $host->getUserPass()); } } diff --git a/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolIntegrationTest.php b/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolIntegrationTest.php index 586a79e48..f6659f40b 100644 --- a/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolIntegrationTest.php +++ b/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolIntegrationTest.php @@ -5,6 +5,7 @@ namespace Elasticsearch\Tests\ConnectionPool; use Elasticsearch\ClientBuilder; +use Elasticsearch\ConnectionPool\SniffingConnectionPool; /** * Class SniffingConnectionPoolIntegrationTest @@ -22,7 +23,7 @@ public function testSniff() { $client = ClientBuilder::create() ->setHosts([$_SERVER['ES_TEST_HOST']]) - ->setConnectionPool('\Elasticsearch\ConnectionPool\SniffingConnectionPool', ['sniffingInterval' => -10]) + ->setConnectionPool(SniffingConnectionPool::class, ['sniffingInterval' => -10]) ->build(); $client->ping(); diff --git a/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolTest.php b/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolTest.php index 00e4bd7bb..720bd90d6 100644 --- a/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolTest.php +++ b/tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolTest.php @@ -4,8 +4,12 @@ namespace Elasticsearch\Tests\ConnectionPool; +use Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector; use Elasticsearch\ConnectionPool\SniffingConnectionPool; +use Elasticsearch\Connections\Connection; +use Elasticsearch\Connections\ConnectionFactory; use Mockery as m; +use Elasticsearch\Common\Exceptions\Curl\OperationTimeoutException; /** * Class SniffingConnectionPoolTest @@ -26,7 +30,7 @@ public function tearDown() public function testAddOneHostThenGetConnection() { - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping') ->andReturn(true) ->getMock() @@ -34,93 +38,93 @@ public function testAddOneHostThenGetConnection() ->andReturn(true) ->getMock(); - $connections = array($mockConnection); + $connections = [$mockConnection]; - $selector = m::mock('\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector') + $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select') ->andReturn($connections[0]) ->getMock(); - $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory'); + $connectionFactory = m::mock(ConnectionFactory::class); - $connectionPoolParams = array('randomizeHosts' => false); + $connectionPoolParams = ['randomizeHosts' => false]; $connectionPool = new SniffingConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); $retConnection = $connectionPool->nextConnection(); - $this->assertEquals($mockConnection, $retConnection); + $this->assertSame($mockConnection, $retConnection); } public function testAddOneHostAndTriggerSniff() { $clusterState = json_decode('{"ok":true,"cluster_name":"elasticsearch_zach","nodes":{"Bl2ihSr7TcuUHxhu1GA_YQ":{"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]"}}}', true); - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping')->andReturn(true)->getMock() ->shouldReceive('isAlive')->andReturn(true)->getMock() ->shouldReceive('getTransportSchema')->once()->andReturn('http')->getMock() ->shouldReceive('sniff')->once()->andReturn($clusterState)->getMock(); - $connections = array($mockConnection); - $mockNewConnection = m::mock('\Elasticsearch\Connections\Connection') + $connections = [$mockConnection]; + $mockNewConnection = m::mock(Connection::class) ->shouldReceive('isAlive')->andReturn(true)->getMock(); - $selector = m::mock('\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector') + $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select')->twice() ->andReturn($mockNewConnection) ->getMock(); - $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory') - ->shouldReceive('create')->with(array('host' => '192.168.1.119', 'port' => 9200))->andReturn($mockNewConnection)->getMock(); + $connectionFactory = m::mock(ConnectionFactory::class) + ->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(); - $this->assertEquals($mockNewConnection, $retConnection); + $this->assertSame($mockNewConnection, $retConnection); } public function testAddOneHostAndForceNext() { $clusterState = json_decode('{"ok":true,"cluster_name":"elasticsearch_zach","nodes":{"Bl2ihSr7TcuUHxhu1GA_YQ":{"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]"}}}', true); - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping')->andReturn(true)->getMock() ->shouldReceive('isAlive')->andReturn(true)->getMock() ->shouldReceive('getTransportSchema')->once()->andReturn('http')->getMock() ->shouldReceive('sniff')->once()->andReturn($clusterState)->getMock(); - $connections = array($mockConnection); - $mockNewConnection = m::mock('\Elasticsearch\Connections\Connection') + $connections = [$mockConnection]; + $mockNewConnection = m::mock(Connection::class) ->shouldReceive('isAlive')->andReturn(true)->getMock(); - $selector = m::mock('\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector') + $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select')->once()->andReturn($mockConnection)->getMock() ->shouldReceive('select')->once()->andReturn($mockNewConnection)->getMock(); - $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory') - ->shouldReceive('create')->with(array('host' => '192.168.1.119', 'port' => 9200))->andReturn($mockNewConnection)->getMock(); + $connectionFactory = m::mock(ConnectionFactory::class) + ->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); - $this->assertEquals($mockNewConnection, $retConnection); + $this->assertSame($mockNewConnection, $retConnection); } public function testAddTenNodesThenGetConnection() { - $connections = array(); + $connections = []; foreach (range(1, 10) as $index) { - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping') ->andReturn(true) ->getMock() @@ -131,27 +135,27 @@ public function testAddTenNodesThenGetConnection() $connections[] = $mockConnection; } - $selector = m::mock('\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector') + $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select') ->andReturn($connections[0]) ->getMock(); - $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory'); + $connectionFactory = m::mock(ConnectionFactory::class); - $connectionPoolParams = array('randomizeHosts' => false); + $connectionPoolParams = ['randomizeHosts' => false]; $connectionPool = new SniffingConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); $retConnection = $connectionPool->nextConnection(); - $this->assertEquals($connections[0], $retConnection); + $this->assertSame($connections[0], $retConnection); } public function testAddTenNodesTimeoutAllButLast() { - $connections = array(); + $connections = []; foreach (range(1, 9) as $index) { - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping') ->andReturn(false) ->getMock() @@ -162,7 +166,7 @@ public function testAddTenNodesTimeoutAllButLast() $connections[] = $mockConnection; } - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping') ->andReturn(true) ->getMock() @@ -172,19 +176,19 @@ public function testAddTenNodesTimeoutAllButLast() $connections[] = $mockConnection; - $selector = m::mock('\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector') + $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select') ->andReturnValues($connections) ->getMock(); - $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory'); + $connectionFactory = m::mock(ConnectionFactory::class); - $connectionPoolParams = array('randomizeHosts' => false); + $connectionPoolParams = ['randomizeHosts' => false]; $connectionPool = new SniffingConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); $retConnection = $connectionPool->nextConnection(); - $this->assertEquals($connections[9], $retConnection); + $this->assertSame($connections[9], $retConnection); } /** @@ -192,10 +196,10 @@ public function testAddTenNodesTimeoutAllButLast() */ public function testAddTenNodesAllTimeout() { - $connections = array(); + $connections = []; foreach (range(1, 10) as $index) { - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping') ->andReturn(false) ->getMock() @@ -206,14 +210,14 @@ public function testAddTenNodesAllTimeout() $connections[] = $mockConnection; } - $selector = m::mock('\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector') + $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select') ->andReturnValues($connections) ->getMock(); - $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory'); + $connectionFactory = m::mock(ConnectionFactory::class); - $connectionPoolParams = array('randomizeHosts' => false); + $connectionPoolParams = ['randomizeHosts' => false]; $connectionPool = new SniffingConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); $retConnection = $connectionPool->nextConnection(); @@ -223,45 +227,45 @@ public function testAddOneHostSniffTwo() { $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); - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping')->andReturn(true)->getMock() ->shouldReceive('isAlive')->andReturn(true)->getMock() ->shouldReceive('getTransportSchema')->twice()->andReturn('http')->getMock() ->shouldReceive('sniff')->twice()->andReturn($clusterState)->getMock(); - $connections = array($mockConnection); + $connections = [$mockConnection]; - $newConnections = array(); - $newConnections[] = m::mock('\Elasticsearch\Connections\Connection') + $newConnections = []; + $newConnections[] = m::mock(Connection::class) ->shouldReceive('isAlive')->andReturn(true)->getMock(); - $newConnections[] = m::mock('\Elasticsearch\Connections\Connection') + $newConnections[] = m::mock(Connection::class) ->shouldReceive('isAlive')->andReturn(true)->getMock(); - $selector = m::mock('\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector') + $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('\Elasticsearch\Connections\ConnectionFactory') - ->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(); + $connectionFactory = m::mock(ConnectionFactory::class) + ->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(); - $this->assertEquals($newConnections[0], $retConnection); + $this->assertSame($newConnections[0], $retConnection); $retConnection = $connectionPool->nextConnection(); - $this->assertEquals($newConnections[1], $retConnection); + $this->assertSame($newConnections[1], $retConnection); } /** @@ -271,62 +275,62 @@ public function testAddSeed_SniffTwo_TimeoutTwo() { $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); - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping')->andReturn(true)->getMock() ->shouldReceive('isAlive')->andReturn(true)->getMock() ->shouldReceive('getTransportSchema')->once()->andReturn('http')->getMock() ->shouldReceive('sniff')->once()->andReturn($clusterState)->getMock(); - $connections = array($mockConnection); + $connections = [$mockConnection]; - $newConnections = array(); - $newConnections[] = m::mock('\Elasticsearch\Connections\Connection') + $newConnections = []; + $newConnections[] = m::mock(Connection::class) ->shouldReceive('isAlive')->andReturn(false)->getMock() ->shouldReceive('ping')->andReturn(false)->getMock(); - $newConnections[] = m::mock('\Elasticsearch\Connections\Connection') + $newConnections[] = m::mock(Connection::class) ->shouldReceive('isAlive')->andReturn(false)->getMock() ->shouldReceive('ping')->andReturn(false)->getMock(); - $selector = m::mock('\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector') + $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('\Elasticsearch\Connections\ConnectionFactory') - ->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(); + $connectionFactory = m::mock(ConnectionFactory::class) + ->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(); - $this->assertEquals($mockConnection, $retConnection); + $this->assertSame($mockConnection, $retConnection); } 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('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping')->andReturn(false)->getMock() ->shouldReceive('isAlive')->andReturn(true)->getMock() - ->shouldReceive('sniff')->andThrow('Elasticsearch\Common\Exceptions\Curl\OperationTimeoutException')->getMock(); + ->shouldReceive('sniff')->andThrow(OperationTimeoutException::class)->getMock(); $connections[] = $mockConnection; } - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping')->andReturn(true)->getMock() ->shouldReceive('isAlive')->andReturn(true)->getMock() ->shouldReceive('sniff')->andReturn($clusterState)->getMock() @@ -335,34 +339,34 @@ public function testTen_TimeoutNine_SniffTenth_AddTwoAlive() $connections[] = $mockConnection; $newConnections = $connections; - $newConnections[] = m::mock('\Elasticsearch\Connections\Connection') + $newConnections[] = m::mock(Connection::class) ->shouldReceive('isAlive')->andReturn(true)->getMock() ->shouldReceive('ping')->andReturn(true)->getMock(); - $newConnections[] = m::mock('\Elasticsearch\Connections\Connection') + $newConnections[] = m::mock(Connection::class) ->shouldReceive('isAlive')->andReturn(true)->getMock() ->shouldReceive('ping')->andReturn(true)->getMock(); - $selector = m::mock('\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector') + $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select') ->andReturnValues($newConnections) ->getMock(); - $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory') - ->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(); + $connectionFactory = m::mock(ConnectionFactory::class) + ->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(); - $this->assertEquals($newConnections[11], $retConnection); + $this->assertSame($newConnections[11], $retConnection); $retConnection = $connectionPool->nextConnection(); - $this->assertEquals($newConnections[12], $retConnection); + $this->assertSame($newConnections[12], $retConnection); } /** @@ -372,58 +376,58 @@ 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('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping')->andReturn(false)->getMock() ->shouldReceive('isAlive')->andReturn(true)->getMock() - ->shouldReceive('sniff')->andThrow('Elasticsearch\Common\Exceptions\Curl\OperationTimeoutException')->getMock(); + ->shouldReceive('sniff')->andThrow(OperationTimeoutException::class)->getMock(); $connections[] = $mockConnection; } - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping')->andReturn(true)->getMock() ->shouldReceive('isAlive')->andReturn(true)->getMock() ->shouldReceive('sniff')->andReturn($clusterState)->getMock() ->shouldReceive('getTransportSchema')->once()->andReturn('http')->getMock() - ->shouldReceive('sniff')->andThrow('Elasticsearch\Common\Exceptions\Curl\OperationTimeoutException')->getMock(); + ->shouldReceive('sniff')->andThrow(OperationTimeoutException::class)->getMock(); $connections[] = $mockConnection; $newConnections = $connections; - $newConnections[] = m::mock('\Elasticsearch\Connections\Connection') + $newConnections[] = m::mock(Connection::class) ->shouldReceive('isAlive')->andReturn(false)->getMock() ->shouldReceive('ping')->andReturn(false)->getMock() - ->shouldReceive('sniff')->andThrow('Elasticsearch\Common\Exceptions\Curl\OperationTimeoutException')->getMock(); + ->shouldReceive('sniff')->andThrow(OperationTimeoutException::class)->getMock(); - $newConnections[] = m::mock('\Elasticsearch\Connections\Connection') + $newConnections[] = m::mock(Connection::class) ->shouldReceive('isAlive')->andReturn(false)->getMock() ->shouldReceive('ping')->andReturn(false)->getMock() - ->shouldReceive('sniff')->andThrow('Elasticsearch\Common\Exceptions\Curl\OperationTimeoutException')->getMock(); + ->shouldReceive('sniff')->andThrow(OperationTimeoutException::class)->getMock(); - $selector = m::mock('\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector') + $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select') ->andReturnValues($newConnections) ->getMock(); $RRConnections = $newConnections; //array_push($connections); - $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory') - ->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(); + $connectionFactory = m::mock(ConnectionFactory::class) + ->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(); - $this->assertEquals($newConnections[11], $retConnection); + $this->assertSame($newConnections[11], $retConnection); $retConnection = $connectionPool->nextConnection(); - $this->assertEquals($newConnections[12], $retConnection); + $this->assertSame($newConnections[12], $retConnection); } } diff --git a/tests/Elasticsearch/Tests/ConnectionPool/StaticConnectionPoolTest.php b/tests/Elasticsearch/Tests/ConnectionPool/StaticConnectionPoolTest.php index 251160b1e..118225fbc 100644 --- a/tests/Elasticsearch/Tests/ConnectionPool/StaticConnectionPoolTest.php +++ b/tests/Elasticsearch/Tests/ConnectionPool/StaticConnectionPoolTest.php @@ -5,6 +5,10 @@ namespace Elasticsearch\Tests\ConnectionPool; use Elasticsearch; +use Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector; +use Elasticsearch\ConnectionPool\StaticConnectionPool; +use Elasticsearch\Connections\Connection; +use Elasticsearch\Connections\ConnectionFactory; use Mockery as m; /** @@ -26,7 +30,7 @@ public function tearDown() public function testAddOneHostThenGetConnection() { - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping') ->andReturn(true) ->getMock() @@ -35,29 +39,29 @@ public function testAddOneHostThenGetConnection() ->getMock() ->shouldReceive('markDead')->once()->getMock(); - $connections = array($mockConnection); + $connections = [$mockConnection]; - $selector = m::mock('\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector') + $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select') ->andReturn($connections[0]) ->getMock(); - $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory'); + $connectionFactory = m::mock(ConnectionFactory::class); $randomizeHosts = false; - $connectionPool = new Elasticsearch\ConnectionPool\StaticConnectionPool($connections, $selector, $connectionFactory, $randomizeHosts); + $connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $randomizeHosts); $retConnection = $connectionPool->nextConnection(); - $this->assertEquals($mockConnection, $retConnection); + $this->assertSame($mockConnection, $retConnection); } public function testAddMultipleHostsThenGetFirst() { - $connections = array(); + $connections = []; foreach (range(1, 10) as $index) { - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping') ->andReturn(true) ->getMock() @@ -69,19 +73,19 @@ public function testAddMultipleHostsThenGetFirst() $connections[] = $mockConnection; } - $selector = m::mock('\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector') + $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select') ->andReturn($connections[0]) ->getMock(); - $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory'); + $connectionFactory = m::mock(ConnectionFactory::class); $randomizeHosts = false; - $connectionPool = new Elasticsearch\ConnectionPool\StaticConnectionPool($connections, $selector, $connectionFactory, $randomizeHosts); + $connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $randomizeHosts); $retConnection = $connectionPool->nextConnection(); - $this->assertEquals($connections[0], $retConnection); + $this->assertSame($connections[0], $retConnection); } /** @@ -89,10 +93,10 @@ public function testAddMultipleHostsThenGetFirst() */ public function testAllHostsFailPing() { - $connections = array(); + $connections = []; foreach (range(1, 10) as $index) { - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping') ->andReturn(false) ->getMock() @@ -106,25 +110,25 @@ public function testAllHostsFailPing() $connections[] = $mockConnection; } - $selector = m::mock('\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector') + $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select') ->andReturnValues($connections) ->getMock(); - $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory'); + $connectionFactory = m::mock(ConnectionFactory::class); $randomizeHosts = false; - $connectionPool = new Elasticsearch\ConnectionPool\StaticConnectionPool($connections, $selector, $connectionFactory, $randomizeHosts); + $connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $randomizeHosts); $connectionPool->nextConnection(); } public function testAllExceptLastHostFailPingRevivesInSkip() { - $connections = array(); + $connections = []; foreach (range(1, 9) as $index) { - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping') ->andReturn(false) ->getMock() @@ -138,7 +142,7 @@ public function testAllExceptLastHostFailPingRevivesInSkip() $connections[] = $mockConnection; } - $goodConnection = m::mock('\Elasticsearch\Connections\Connection') + $goodConnection = m::mock(Connection::class) ->shouldReceive('ping')->once() ->andReturn(true) ->getMock() @@ -151,26 +155,26 @@ public function testAllExceptLastHostFailPingRevivesInSkip() $connections[] = $goodConnection; - $selector = m::mock('\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector') + $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select') ->andReturnValues($connections) ->getMock(); - $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory'); + $connectionFactory = m::mock(ConnectionFactory::class); $randomizeHosts = false; - $connectionPool = new Elasticsearch\ConnectionPool\StaticConnectionPool($connections, $selector, $connectionFactory, $randomizeHosts); + $connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $randomizeHosts); $ret = $connectionPool->nextConnection(); - $this->assertEquals($goodConnection, $ret); + $this->assertSame($goodConnection, $ret); } public function testAllExceptLastHostFailPingRevivesPreSkip() { - $connections = array(); + $connections = []; foreach (range(1, 9) as $index) { - $mockConnection = m::mock('\Elasticsearch\Connections\Connection') + $mockConnection = m::mock(Connection::class) ->shouldReceive('ping') ->andReturn(false) ->getMock() @@ -184,7 +188,7 @@ public function testAllExceptLastHostFailPingRevivesPreSkip() $connections[] = $mockConnection; } - $goodConnection = m::mock('\Elasticsearch\Connections\Connection') + $goodConnection = m::mock(Connection::class) ->shouldReceive('ping')->once() ->andReturn(true) ->getMock() @@ -197,18 +201,18 @@ public function testAllExceptLastHostFailPingRevivesPreSkip() $connections[] = $goodConnection; - $selector = m::mock('\Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector') + $selector = m::mock(RoundRobinSelector::class) ->shouldReceive('select') ->andReturnValues($connections) ->getMock(); - $connectionFactory = m::mock('\Elasticsearch\Connections\ConnectionFactory'); + $connectionFactory = m::mock(ConnectionFactory::class); $randomizeHosts = false; - $connectionPool = new Elasticsearch\ConnectionPool\StaticConnectionPool($connections, $selector, $connectionFactory, $randomizeHosts); + $connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $randomizeHosts); $ret = $connectionPool->nextConnection(); - $this->assertEquals($goodConnection, $ret); + $this->assertSame($goodConnection, $ret); } public function testCustomConnectionPoolIT() @@ -217,7 +221,7 @@ public function testCustomConnectionPoolIT() $clientBuilder->setHosts(['localhost:1']); $client = $clientBuilder ->setRetries(0) - ->setConnectionPool('\Elasticsearch\ConnectionPool\StaticConnectionPool', []) + ->setConnectionPool(StaticConnectionPool::class, []) ->build(); try { diff --git a/tests/Elasticsearch/Tests/Helper/Iterators/SearchResponseIteratorTest.php b/tests/Elasticsearch/Tests/Helper/Iterators/SearchResponseIteratorTest.php index 9c0b1a155..20d03ddf8 100644 --- a/tests/Elasticsearch/Tests/Helper/Iterators/SearchResponseIteratorTest.php +++ b/tests/Elasticsearch/Tests/Helper/Iterators/SearchResponseIteratorTest.php @@ -4,6 +4,7 @@ namespace Elasticsearch\Tests\Helper\Iterators; +use Elasticsearch\Client; use Elasticsearch\Helper\Iterators\SearchResponseIterator; use Mockery as m; @@ -24,24 +25,24 @@ 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('\Elasticsearch\Client'); + $mock_client = m::mock(Client::class); $mock_client->shouldReceive('search') ->once() ->ordered() ->with($search_params) - ->andReturn(array('_scroll_id' => 'scroll_id_01')); + ->andReturn(['_scroll_id' => 'scroll_id_01']); $mock_client->shouldReceive('scroll') ->never(); @@ -59,18 +60,18 @@ 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('\Elasticsearch\Client'); + $mock_client = m::mock(Client::class); $mock_client->shouldReceive('search') ->once() diff --git a/tests/Elasticsearch/Tests/RegisteredNamespaceTest.php b/tests/Elasticsearch/Tests/RegisteredNamespaceTest.php index 144eba59c..4e9faa5ea 100644 --- a/tests/Elasticsearch/Tests/RegisteredNamespaceTest.php +++ b/tests/Elasticsearch/Tests/RegisteredNamespaceTest.php @@ -31,7 +31,7 @@ public function testRegisteringNamespace() { $builder = new FooNamespaceBuilder(); $client = ClientBuilder::create()->registerNamespace($builder)->build(); - $this->assertEquals("123", $client->foo()->fooMethod()); + $this->assertSame("123", $client->foo()->fooMethod()); } /** @@ -41,7 +41,7 @@ public function testNonExistingNamespace() { $builder = new FooNamespaceBuilder(); $client = ClientBuilder::create()->registerNamespace($builder)->build(); - $this->assertEquals("123", $client->bar()->fooMethod()); + $this->assertSame("123", $client->bar()->fooMethod()); } } diff --git a/tests/Elasticsearch/Tests/Serializers/ArrayToJSONSerializerTest.php b/tests/Elasticsearch/Tests/Serializers/ArrayToJSONSerializerTest.php index c6cafe92c..d66860574 100644 --- a/tests/Elasticsearch/Tests/Serializers/ArrayToJSONSerializerTest.php +++ b/tests/Elasticsearch/Tests/Serializers/ArrayToJSONSerializerTest.php @@ -22,12 +22,12 @@ public function tearDown() public function testSerializeArray() { $serializer = new ArrayToJSONSerializer(); - $body = array('value' => 'field'); + $body = ['value' => 'field']; $ret = $serializer->serialize($body); $body = json_encode($body, JSON_PRESERVE_ZERO_FRACTION); - $this->assertEquals($body, $ret); + $this->assertSame($body, $ret); } public function testSerializeString() @@ -37,7 +37,7 @@ public function testSerializeString() $ret = $serializer->serialize($body); - $this->assertEquals($body, $ret); + $this->assertSame($body, $ret); } public function testDeserializeJSON() @@ -45,9 +45,9 @@ public function testDeserializeJSON() $serializer = new ArrayToJSONSerializer(); $body = '{"field":"value"}'; - $ret = $serializer->deserialize($body, array()); + $ret = $serializer->deserialize($body, []); $body = json_decode($body, true); - $this->assertEquals($body, $ret); + $this->assertSame($body, $ret); } } diff --git a/tests/Elasticsearch/Tests/Serializers/EverythingToJSONSerializerTest.php b/tests/Elasticsearch/Tests/Serializers/EverythingToJSONSerializerTest.php index d1771e6e9..1fcd9f598 100644 --- a/tests/Elasticsearch/Tests/Serializers/EverythingToJSONSerializerTest.php +++ b/tests/Elasticsearch/Tests/Serializers/EverythingToJSONSerializerTest.php @@ -22,12 +22,12 @@ public function tearDown() public function testSerializeArray() { $serializer = new EverythingToJSONSerializer(); - $body = array('value' => 'field'); + $body = ['value' => 'field']; $ret = $serializer->serialize($body); $body = json_encode($body, JSON_PRESERVE_ZERO_FRACTION); - $this->assertEquals($body, $ret); + $this->assertSame($body, $ret); } public function testSerializeString() @@ -38,7 +38,7 @@ public function testSerializeString() $ret = $serializer->serialize($body); $body = '"abc"'; - $this->assertEquals($body, $ret); + $this->assertSame($body, $ret); } public function testDeserializeJSON() @@ -46,9 +46,9 @@ public function testDeserializeJSON() $serializer = new EverythingToJSONSerializer(); $body = '{"field":"value"}'; - $ret = $serializer->deserialize($body, array()); + $ret = $serializer->deserialize($body, []); $body = json_decode($body, true); - $this->assertEquals($body, $ret); + $this->assertSame($body, $ret); } } diff --git a/tests/Elasticsearch/Tests/YamlRunnerTest.php b/tests/Elasticsearch/Tests/YamlRunnerTest.php index fbeec2127..fae41032d 100644 --- a/tests/Elasticsearch/Tests/YamlRunnerTest.php +++ b/tests/Elasticsearch/Tests/YamlRunnerTest.php @@ -462,10 +462,10 @@ public function checkForWarnings($expectedWarnings) { } // Check to make sure we're adding headers - static::assertArrayHasKey('Content-type', $last['request']['headers'], print_r($last['request']['headers'], true)); - static::assertEquals('application/json', $last['request']['headers']['Content-type'][0], print_r($last['request']['headers'], true)); - static::assertArrayHasKey('Accept', $last['request']['headers'], print_r($last['request']['headers'], true)); - static::assertEquals('application/json', $last['request']['headers']['Accept'][0], print_r($last['request']['headers'], true)); + $this->assertArrayHasKey('Content-type', $last['request']['headers'], print_r($last['request']['headers'], true)); + $this->assertSame('application/json', $last['request']['headers']['Content-type'][0], print_r($last['request']['headers'], true)); + $this->assertArrayHasKey('Accept', $last['request']['headers'], print_r($last['request']['headers'], true)); + $this->assertSame('application/json', $last['request']['headers']['Accept'][0], print_r($last['request']['headers'], true)); } @@ -482,7 +482,7 @@ public function operationIsFalse($operation, $lastOperationResult, &$context, $t $msg = "Failed to assert that a value is false in test \"$testName\"\n" ."$operation was [".print_r($value, true)."]" .var_export($lastOperationResult, true); - static::assertFalse($value, $msg); + $this->assertFalse($value, $msg); return $lastOperationResult; } @@ -501,10 +501,10 @@ public function operationIsTrue($operation, $lastOperationResult, &$context, $te $msg = "Failed to assert that a value is true in test \"$testName\"\n" ."$operation was [".print_r($value, true)."]" .var_export($lastOperationResult, true); - static::assertNotEquals(0, $value, $msg); - static::assertNotFalse($value, $msg); - static::assertNotNull($value, $msg); - static::assertNotEquals('', $msg); + $this->assertNotEquals(0, $value, $msg); + $this->assertNotFalse($value, $msg); + $this->assertNotNull($value, $msg); + $this->assertNotEquals('', $msg); return $lastOperationResult; } @@ -535,11 +535,11 @@ public function operationMatch($operation, $lastOperationResult, &$context, $tes $expected = json_decode(json_encode($expected), true); $match = json_decode(json_encode($match), true); - static::assertEquals($expected, $match, $msg); + $this->assertEquals($expected, $match, $msg); } elseif (is_string($expected) && preg_match('#^/.+?/$#s', $expected)) { - static::assertRegExp($this->formatRegex($expected), $match, $msg); + $this->assertRegExp($this->formatRegex($expected), $match, $msg); } else { - static::assertEquals($expected, $match, $msg); + $this->assertEquals($expected, $match, $msg); } return $lastOperationResult; @@ -557,7 +557,7 @@ public function operationGreaterThanOrEqual($operation, $lastOperationResult, &$ $value = $this->resolveValue($lastOperationResult, key($operation), $context); $expected = current($operation); - static::assertGreaterThanOrEqual($expected, $value, 'Failed to gte in test ' . $testName); + $this->assertGreaterThanOrEqual($expected, $value, 'Failed to gte in test ' . $testName); return $lastOperationResult; } @@ -574,7 +574,7 @@ public function operationGreaterThan($operation, $lastOperationResult, &$context $value = $this->resolveValue($lastOperationResult, key($operation), $context); $expected = current($operation); - static::assertGreaterThan($expected, $value, 'Failed to gt in test ' . $testName); + $this->assertGreaterThan($expected, $value, 'Failed to gt in test ' . $testName); return $lastOperationResult; } @@ -591,7 +591,7 @@ public function operationLessThanOrEqual($operation, $lastOperationResult, &$con $value = $this->resolveValue($lastOperationResult, key($operation), $context); $expected = current($operation); - static::assertLessThanOrEqual($expected, $value, 'Failed to lte in test ' . $testName); + $this->assertLessThanOrEqual($expected, $value, 'Failed to lte in test ' . $testName); return $lastOperationResult; } @@ -608,7 +608,7 @@ public function operationLessThan($operation, $lastOperationResult, &$context, $ $value = $this->resolveValue($lastOperationResult, key($operation), $context); $expected = current($operation); - static::assertLessThan($expected, $value, 'Failed to lt in test ' . $testName); + $this->assertLessThan($expected, $value, 'Failed to lt in test ' . $testName); return $lastOperationResult; } @@ -625,7 +625,7 @@ public function operationLength($operation, $lastOperationResult, &$context, $te $value = $this->resolveValue($lastOperationResult, key($operation), $context); $expected = current($operation); - static::assertCount($expected, $value, 'Failed to gte in test ' . $testName); + $this->assertCount($expected, $value, 'Failed to gte in test ' . $testName); return $lastOperationResult; } @@ -711,23 +711,23 @@ public function operationSkip($operation, $lastOperationResult, $testName) private function assertException(\Exception $exception, $expectedError, $testName) { if (is_string($expectedError) && preg_match('#^/.+?/$#', $expectedError)) { - static::assertRegExp($expectedError, $exception->getMessage(), 'Failed to catch error in test ' . $testName); + $this->assertRegExp($expectedError, $exception->getMessage(), 'Failed to catch error in test ' . $testName); } elseif ($exception instanceof Missing404Exception && $expectedError === 'missing') { - static::assertTrue(true); + $this->assertTrue(true); } elseif ($exception instanceof Conflict409Exception && $expectedError === 'conflict') { - static::assertTrue(true); + $this->assertTrue(true); } elseif ($exception instanceof Forbidden403Exception && $expectedError === 'forbidden') { - static::assertTrue(true); + $this->assertTrue(true); } elseif ($exception instanceof RequestTimeout408Exception && $expectedError === 'request_timeout') { - static::assertTrue(true); + $this->assertTrue(true); } elseif ($exception instanceof BadRequest400Exception && $expectedError === 'request') { - static::assertTrue(true); + $this->assertTrue(true); } elseif ($exception instanceof ServerErrorResponseException && $expectedError === 'request') { - static::assertTrue(true); + $this->assertTrue(true); } elseif ($exception instanceof \RuntimeException && $expectedError === 'param') { - static::assertTrue(true); + $this->assertTrue(true); } else { - static::assertContains($expectedError, $exception->getMessage()); + $this->assertContains($expectedError, $exception->getMessage()); } if ($exception->getPrevious() !== null) {