Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] add PHP_CodeSniffer to build #638

Merged
merged 4 commits into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ before_script:
- php util/EnsureClusterAlive.php

script:
- composer run-script phpcs
- composer run-script phpstan
- vendor/bin/phpunit $PHPUNIT_FLAGS
- vendor/bin/phpunit -c phpunit-integration.xml --group sync $PHPUNIT_FLAGS
Expand Down
21 changes: 14 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
"require": {
"php": "^7.0",
"ext-json": ">=1.3.7",
"psr/log": "~1.0",
"guzzlehttp/ringphp" : "~1.0"
"guzzlehttp/ringphp": "~1.0",
"psr/log": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "6.3.0",
"mockery/mockery": "0.9.4",
"symfony/yaml": "^2.8",
"symfony/finder": "^2.8",
"cpliakas/git-wrapper": "~1.0",
"doctrine/inflector": "^1.1",
"phpstan/phpstan-shim": "0.8.3"
"mockery/mockery": "0.9.4",
"phpstan/phpstan-shim": "0.8.3",
"phpunit/phpunit": "6.3.0",
"squizlabs/php_codesniffer": "3.0.2",
"symfony/finder": "^2.8",
"symfony/yaml": "^2.8"
},
"suggest": {
"ext-curl": "*",
Expand All @@ -38,7 +39,13 @@
"Elasticsearch\\Tests\\": "tests/Elasticsearch/Tests/"
}
},
"config": {
"sort-packages": true
},
"scripts": {
"phpcs": [
"phpcs --standard=ruleset.xml --extensions=php --encoding=utf-8 --tab-width=4 -sp tests"
],
"phpstan": [
"@php vendor/phpstan/phpstan-shim/phpstan.phar analyse -c phpstan.neon tests --level 7 --no-progress"
]
Expand Down
6 changes: 6 additions & 0 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<ruleset name="Elasticsearch-PHP">
<rule ref="PSR2">
<exclude name="Generic.Files.LineLength.TooLong"/>
</rule>
</ruleset>
1 change: 0 additions & 1 deletion tests/Elasticsearch/Tests/ClientIntegrationTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ public function testCustomQueryParams()

$this->assertFalse($exists);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function testTenConnections()
$this->assertSame($mockConnections[2], $roundRobin->select($mockConnections));
$this->assertSame($mockConnections[3], $roundRobin->select($mockConnections));
$this->assertSame($mockConnections[4], $roundRobin->select($mockConnections));

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function testAddOneHostSniffTwo()
$this->assertSame($newConnections[1], $retConnection);
}

public function testAddSeed_SniffTwo_TimeoutTwo()
public function testAddSeedSniffTwoTimeoutTwo()
{
$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);

Expand Down Expand Up @@ -320,7 +320,7 @@ public function testAddSeed_SniffTwo_TimeoutTwo()
$retConnection = $connectionPool->nextConnection();
}

public function testTen_TimeoutNine_SniffTenth_AddTwoAlive()
public function testTenTimeoutNineSniffTenthAddTwoAlive()
{
$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);

Expand Down Expand Up @@ -374,7 +374,7 @@ public function testTen_TimeoutNine_SniffTenth_AddTwoAlive()
$this->assertSame($newConnections[12], $retConnection);
}

public function testTen_TimeoutNine_SniffTenth_AddTwoDead_TimeoutEveryone()
public function testTenTimeoutNineSniffTenthAddTwoDeadTimeoutEveryone()
{
$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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
class StaticConnectionPoolIntegrationTest extends \PHPUnit\Framework\TestCase
{
// Issue #636
public function test404Liveness() {
public function test404Liveness()
{
$client = \Elasticsearch\ClientBuilder::create()
->setHosts([$_SERVER['ES_TEST_HOST']])
->setConnectionPool(\Elasticsearch\ConnectionPool\StaticConnectionPool::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ public function testAllHostsFailPing()
$this->expectException(\Elasticsearch\Common\Exceptions\NoNodesAvailableException::class);
$this->expectExceptionMessage('No alive nodes found in your cluster');

$this->expectException(\Elasticsearch\Common\Exceptions\NoNodesAvailableException::class);
$this->expectExceptionMessage('No alive nodes found in your cluster');

$connectionPool->nextConnection();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public function testWithHits()
]
]
]
]);
]
);

$mock_client->shouldReceive('scroll')
->once()
Expand Down
2 changes: 2 additions & 0 deletions tests/Elasticsearch/Tests/RegisteredNamespaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function testNonExistingNamespace()
}
}

// @codingStandardsIgnoreStart "Each class must be in a file by itself" - not worth the extra work here
class FooNamespaceBuilder implements Elasticsearch\Namespaces\NamespaceBuilderInterface
{
public function getName()
Expand All @@ -66,3 +67,4 @@ public function fooMethod()
return "123";
}
}
// @codingStandardsIgnoreEnd
17 changes: 8 additions & 9 deletions tests/Elasticsearch/Tests/YamlRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function processProcedure($procedure, $name, $fileName, $async = false)
* @param $operation
* @param $lastOperationResult
* @param $testName
* @param array $context
* @param array $context
* @param bool $async
*
* @return mixed
Expand Down Expand Up @@ -412,7 +412,6 @@ public function executeRequest($caller, $method, $endpointParams, $expectedError
public function executeAsyncExistRequest($caller, $method, $endpointParams, $expectedError, $expectedWarnings, $testName)
{
try {

$response = $caller->$method($endpointParams);

while ($response instanceof FutureArrayInterface) {
Expand All @@ -439,7 +438,8 @@ public function executeAsyncExistRequest($caller, $method, $endpointParams, $exp
}
}

public function checkForWarnings($expectedWarnings) {
public function checkForWarnings($expectedWarnings)
{
$last = $this->client->transport->getLastConnection()->getLastRequestInfo();


Expand Down Expand Up @@ -475,7 +475,6 @@ public function checkForWarnings($expectedWarnings) {
$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));

}

/**
Expand Down Expand Up @@ -667,7 +666,7 @@ public function operationSet($operation, $lastOperationResult, &$context, $testN
*/
public function operationSkip($operation, $lastOperationResult, $testName)
{
if (is_object($operation) !== true ) {
if (is_object($operation) !== true) {
return $lastOperationResult;
}

Expand Down Expand Up @@ -696,7 +695,7 @@ public function operationSkip($operation, $lastOperationResult, $testName)
$version[0] = ~PHP_INT_MAX;
}

if (!isset($version[1]) || $version[1] === "" ) {
if (!isset($version[1]) || $version[1] === "") {
$version[1] = PHP_INT_MAX;
}

Expand Down Expand Up @@ -1029,7 +1028,6 @@ private function clean()

$response = curl_exec($ch);
curl_close($ch);

}
}
}
Expand All @@ -1043,8 +1041,9 @@ private function clean()
$this->waitForYellow();
}

private function rmDirRecursively($dir) {
if (!is_dir($dir )) {
private function rmDirRecursively($dir)
{
if (!is_dir($dir)) {
return;
}
$files = new RecursiveIteratorIterator(
Expand Down