-
Notifications
You must be signed in to change notification settings - Fork 974
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [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 sebastianbergmann/phpunit#1914 (comment)
- Loading branch information
1 parent
fcd5ff1
commit dc5d18c
Showing
9 changed files
with
235 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,15 +227,15 @@ public function testMaxRetriesException() | |
->setRetries(0) | ||
->build(); | ||
|
||
$searchParams = array( | ||
$searchParams = [ | ||
'index' => 'test', | ||
'type' => 'test', | ||
'body' => [ | ||
'query' => [ | ||
'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:[email protected]: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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.