Skip to content

Commit 553b433

Browse files
mhujerpolyfractal
authored andcommitted
[TEST] add PHPStan to build (#628)
* PHPUnit 5.7.21 + update config + fix risky tests * PHPUnit 6.3.0 * use $this->expectException instead of annotation * [TEST] fixes of issues detected by phpstan * phpstan setup
1 parent dc76714 commit 553b433

File tree

7 files changed

+53
-13
lines changed

7 files changed

+53
-13
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ before_script:
5252
- php util/EnsureClusterAlive.php
5353

5454
script:
55+
- composer run-script phpstan
5556
- vendor/bin/phpunit $PHPUNIT_FLAGS
5657
- vendor/bin/phpunit -c phpunit-integration.xml --group sync $PHPUNIT_FLAGS
5758

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"symfony/yaml": "^2.8",
2222
"symfony/finder": "^2.8",
2323
"cpliakas/git-wrapper": "~1.0",
24-
"doctrine/inflector": "^1.1"
24+
"doctrine/inflector": "^1.1",
25+
"phpstan/phpstan-shim": "0.8.3"
2526
},
2627
"suggest": {
2728
"ext-curl": "*",
@@ -36,5 +37,10 @@
3637
"psr-4": {
3738
"Elasticsearch\\Tests\\": "tests/Elasticsearch/Tests/"
3839
}
40+
},
41+
"scripts": {
42+
"phpstan": [
43+
"@php vendor/phpstan/phpstan-shim/phpstan.phar analyse -c phpstan.neon tests --level 7 --no-progress"
44+
]
3945
}
4046
}

phpstan.neon

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
parameters:
2+
ignoreErrors:
3+
- '#Mockery\\MockInterface::shouldReceive\(\)#'
4+
- '#Mockery\\MockInterface given#'
5+
- '#Mockery\\MockInterface\[\] given#'
6+
7+
# because of \Elasticsearch\Tests\RegisteredNamespaceTest
8+
- '#Call to an undefined method Elasticsearch\\Client::foo\(\)#'
9+
- '#Call to an undefined method Elasticsearch\\Client::bar\(\)#'

tests/Elasticsearch/Tests/ClientIntegrationTests.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
declare(strict_types = 1);
44

5+
namespace Elasticsearch\Tests;
6+
7+
use Elasticsearch;
8+
59
/**
610
* Class ClientTest
711
*

tests/Elasticsearch/Tests/ConnectionPool/StaticConnectionPoolIntegrationTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
declare(strict_types = 1);
44

5+
namespace Elasticsearch\Tests\ConnectionPool;
6+
7+
use Elasticsearch;
8+
59
/**
610
* Class StaticConnectionPoolIntegrationTest
711
*

tests/Elasticsearch/Tests/ConnectionPool/StaticConnectionPoolTest.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ public function testAddOneHostThenGetConnection()
4848

4949
$connectionFactory = m::mock(ConnectionFactory::class);
5050

51-
$randomizeHosts = false;
52-
$connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $randomizeHosts);
51+
$connectionPoolParams = [
52+
'randomizeHosts' => false,
53+
];
54+
$connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams);
5355

5456
$retConnection = $connectionPool->nextConnection();
5557

@@ -80,8 +82,10 @@ public function testAddMultipleHostsThenGetFirst()
8082

8183
$connectionFactory = m::mock(ConnectionFactory::class);
8284

83-
$randomizeHosts = false;
84-
$connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $randomizeHosts);
85+
$connectionPoolParams = [
86+
'randomizeHosts' => false,
87+
];
88+
$connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams);
8589

8690
$retConnection = $connectionPool->nextConnection();
8791

@@ -114,8 +118,13 @@ public function testAllHostsFailPing()
114118

115119
$connectionFactory = m::mock(ConnectionFactory::class);
116120

117-
$randomizeHosts = false;
118-
$connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $randomizeHosts);
121+
$connectionPoolParams = [
122+
'randomizeHosts' => false,
123+
];
124+
$connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams);
125+
126+
$this->expectException(\Elasticsearch\Common\Exceptions\NoNodesAvailableException::class);
127+
$this->expectExceptionMessage('No alive nodes found in your cluster');
119128

120129
$this->expectException(\Elasticsearch\Common\Exceptions\NoNodesAvailableException::class);
121130
$this->expectExceptionMessage('No alive nodes found in your cluster');
@@ -162,8 +171,10 @@ public function testAllExceptLastHostFailPingRevivesInSkip()
162171

163172
$connectionFactory = m::mock(ConnectionFactory::class);
164173

165-
$randomizeHosts = false;
166-
$connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $randomizeHosts);
174+
$connectionPoolParams = [
175+
'randomizeHosts' => false,
176+
];
177+
$connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams);
167178

168179
$ret = $connectionPool->nextConnection();
169180
$this->assertSame($goodConnection, $ret);
@@ -208,8 +219,10 @@ public function testAllExceptLastHostFailPingRevivesPreSkip()
208219

209220
$connectionFactory = m::mock(ConnectionFactory::class);
210221

211-
$randomizeHosts = false;
212-
$connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $randomizeHosts);
222+
$connectionPoolParams = [
223+
'randomizeHosts' => false,
224+
];
225+
$connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams);
213226

214227
$ret = $connectionPool->nextConnection();
215228
$this->assertSame($goodConnection, $ret);

tests/Elasticsearch/Tests/YamlRunnerTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function testAsyncIntegration($testProcedure, $skip, $setupProcedure, $fi
169169
}
170170

171171
if (null !== $setupProcedure) {
172-
$this->processProcedure(current($setupProcedure), 'setup');
172+
$this->processProcedure(current($setupProcedure), 'setup', $fileName);
173173
$this->waitForYellow();
174174
}
175175

@@ -326,6 +326,9 @@ public function operationDo($operation, $lastOperationResult, &$context, $testNa
326326
$endpointParams->client['headers'] = $headers;
327327
}
328328

329+
if (!is_string($method)) {
330+
throw new \Exception('$method must be string');
331+
}
329332
list($method, $namespace) = $this->mapEndpoint($method, $namespace);
330333

331334
if (null !== $namespace) {
@@ -404,7 +407,7 @@ public function executeRequest($caller, $method, $endpointParams, $expectedError
404407
*
405408
* @throws \Exception
406409
*
407-
* @return bool
410+
* @return bool|mixed[]
408411
*/
409412
public function executeAsyncExistRequest($caller, $method, $endpointParams, $expectedError, $expectedWarnings, $testName)
410413
{

0 commit comments

Comments
 (0)