Skip to content

Commit

Permalink
[TEST] add typehints where possible (elastic#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhujer authored and polyfractal committed Apr 4, 2018
1 parent 7892cc5 commit 76d7c50
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AbstractEndpointTest extends \PHPUnit\Framework\TestCase
{
private $endpoint;

public static function invalidParameters()
public static function invalidParameters(): array
{
return [
[['invalid' => 10]],
Expand Down
88 changes: 44 additions & 44 deletions tests/Elasticsearch/Tests/YamlRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class YamlRunnerTest extends \PHPUnit\Framework\TestCase
*
* @return string
*/
public static function getHost()
public static function getHost(): string
{
if (isset($_SERVER['ES_TEST_HOST']) === true) {
return $_SERVER['ES_TEST_HOST'];
Expand Down Expand Up @@ -136,7 +136,7 @@ public function setUp()
* @dataProvider yamlProvider
* @group sync
*/
public function testIntegration($testProcedure, $skip, $setupProcedure, $fileName)
public function testIntegration($testProcedure, bool $skip, $setupProcedure, string $fileName)
{
if ($skip) {
static::markTestIncomplete($testProcedure);
Expand All @@ -158,7 +158,7 @@ public function testIntegration($testProcedure, $skip, $setupProcedure, $fileNam
* @dataProvider yamlProvider
* @group async
*/
public function testAsyncIntegration($testProcedure, $skip, $setupProcedure, $fileName)
public function testAsyncIntegration($testProcedure, bool $skip, $setupProcedure, string $fileName)
{
if ($skip) {
static::markTestIncomplete($testProcedure);
Expand All @@ -179,11 +179,12 @@ public function testAsyncIntegration($testProcedure, $skip, $setupProcedure, $fi
/**
* Process a procedure
*
* @param $procedure
* @param $name
* @param array $procedure
* @param string $name
* @param string $fileName
* @param bool $async
*/
public function processProcedure($procedure, $name, $fileName, $async = false)
public function processProcedure(array $procedure, string $name, string $fileName, bool $async = false)
{
$lastOperationResult = null;
$context = [];
Expand All @@ -208,7 +209,7 @@ public function processProcedure($procedure, $name, $fileName, $async = false)
*
* @return mixed
*/
public function processOperation($operation, $lastOperationResult, &$context, $testName, $async = false)
public function processOperation($operation, $lastOperationResult, array &$context, string $testName, bool $async = false)
{
$operationName = array_keys((array)$operation)[0];

Expand Down Expand Up @@ -265,14 +266,14 @@ public function processOperation($operation, $lastOperationResult, &$context, $t
* @param $operation
* @param $lastOperationResult
* @param array $context
* @param $testName
* @param string $testName
* @param bool $async
*
* @throws \Exception
*
* @return mixed
*/
public function operationDo($operation, $lastOperationResult, &$context, $testName, $async = false)
public function operationDo($operation, $lastOperationResult, &$context, string $testName, bool $async = false)
{
$expectedError = null;
$expectedWarnings = null;
Expand Down Expand Up @@ -362,7 +363,7 @@ public function operationDo($operation, $lastOperationResult, &$context, $testNa
* Obtain the response from the server
*
* @param $caller
* @param $method
* @param string $method
* @param $endpointParams
* @param $expectedError
* @param $testName
Expand All @@ -371,7 +372,7 @@ public function operationDo($operation, $lastOperationResult, &$context, $testNa
*
* @return array|mixed
*/
public function executeRequest($caller, $method, $endpointParams, $expectedError, $expectedWarnings, $testName)
public function executeRequest($caller, string $method, $endpointParams, $expectedError, $expectedWarnings, string $testName)
{
try {
$response = $caller->$method($endpointParams);
Expand Down Expand Up @@ -407,7 +408,7 @@ public function executeRequest($caller, $method, $endpointParams, $expectedError
*
* @throws \Exception
*
* @return bool|mixed[]
* @return bool|mixed[]|null
*/
public function executeAsyncExistRequest($caller, $method, $endpointParams, $expectedError, $expectedWarnings, $testName)
{
Expand Down Expand Up @@ -480,11 +481,11 @@ public function checkForWarnings($expectedWarnings)
/**
* Check if a field in the last operation is false
*
* @param $operation
* @param string $operation
* @param $lastOperationResult
* @param $testName
* @param string $testName
*/
public function operationIsFalse($operation, $lastOperationResult, &$context, $testName)
public function operationIsFalse(string $operation, $lastOperationResult, &$context, string $testName)
{
$value = (bool)$this->resolveValue($lastOperationResult, $operation, $context);
$msg = "Failed to assert that a value is false in test \"$testName\"\n"
Expand All @@ -500,9 +501,9 @@ public function operationIsFalse($operation, $lastOperationResult, &$context, $t
*
* @param $operation
* @param $lastOperationResult
* @param $testName
* @param string $testName
*/
public function operationIsTrue($operation, $lastOperationResult, &$context, $testName)
public function operationIsTrue(string $operation, $lastOperationResult, &$context, string $testName)
{
$value = $this->resolveValue($lastOperationResult, $operation, $context);

Expand All @@ -522,9 +523,9 @@ public function operationIsTrue($operation, $lastOperationResult, &$context, $te
*
* @param $operation
* @param $lastOperationResult
* @param $testName
* @param string $testName
*/
public function operationMatch($operation, $lastOperationResult, &$context, $testName)
public function operationMatch($operation, $lastOperationResult, &$context, string $testName)
{
$key = key($operation);

Expand Down Expand Up @@ -558,9 +559,9 @@ public function operationMatch($operation, $lastOperationResult, &$context, $tes
*
* @param $operation
* @param $lastOperationResult
* @param $testName
* @param string $testName
*/
public function operationGreaterThanOrEqual($operation, $lastOperationResult, &$context, $testName)
public function operationGreaterThanOrEqual($operation, $lastOperationResult, &$context, string $testName)
{
$value = $this->resolveValue($lastOperationResult, key($operation), $context);
$expected = current($operation);
Expand All @@ -575,9 +576,9 @@ public function operationGreaterThanOrEqual($operation, $lastOperationResult, &$
*
* @param $operation
* @param $lastOperationResult
* @param $testName
* @param string $testName
*/
public function operationGreaterThan($operation, $lastOperationResult, &$context, $testName)
public function operationGreaterThan($operation, $lastOperationResult, &$context, string $testName)
{
$value = $this->resolveValue($lastOperationResult, key($operation), $context);
$expected = current($operation);
Expand All @@ -592,9 +593,9 @@ public function operationGreaterThan($operation, $lastOperationResult, &$context
*
* @param $operation
* @param $lastOperationResult
* @param $testName
* @param string $testName
*/
public function operationLessThanOrEqual($operation, $lastOperationResult, &$context, $testName)
public function operationLessThanOrEqual($operation, $lastOperationResult, &$context, string $testName)
{
$value = $this->resolveValue($lastOperationResult, key($operation), $context);
$expected = current($operation);
Expand All @@ -609,9 +610,9 @@ public function operationLessThanOrEqual($operation, $lastOperationResult, &$con
*
* @param $operation
* @param $lastOperationResult
* @param $testName
* @param string $testName
*/
public function operationLessThan($operation, $lastOperationResult, &$context, $testName)
public function operationLessThan($operation, $lastOperationResult, &$context, string $testName)
{
$value = $this->resolveValue($lastOperationResult, key($operation), $context);
$expected = current($operation);
Expand All @@ -626,9 +627,9 @@ public function operationLessThan($operation, $lastOperationResult, &$context, $
*
* @param $operation
* @param $lastOperationResult
* @param $testName
* @param string $testName
*/
public function operationLength($operation, $lastOperationResult, &$context, $testName)
public function operationLength($operation, $lastOperationResult, &$context, string $testName)
{
$value = $this->resolveValue($lastOperationResult, key($operation), $context);
$expected = current($operation);
Expand All @@ -644,9 +645,9 @@ public function operationLength($operation, $lastOperationResult, &$context, $te
* @param $operation
* @param $lastOperationResult
* @param $context
* @param $testName
* @param string $testName
*/
public function operationSet($operation, $lastOperationResult, &$context, $testName)
public function operationSet($operation, $lastOperationResult, &$context, string $testName)
{
$key = key($operation);
$value = $this->resolveValue($lastOperationResult, $key, $context);
Expand All @@ -662,9 +663,9 @@ public function operationSet($operation, $lastOperationResult, &$context, $testN
*
* @param $operation
* @param $lastOperationResult
* @param $testName
* @param string $testName
*/
public function operationSkip($operation, $lastOperationResult, $testName)
public function operationSkip($operation, $lastOperationResult, string $testName)
{
if (is_object($operation) !== true) {
return $lastOperationResult;
Expand Down Expand Up @@ -711,12 +712,12 @@ public function operationSkip($operation, $lastOperationResult, $testName)
* Assert an expected error
*
* @param \Exception $exception
* @param $expectedError
* @param $testName
* @param string $expectedError
* @param string $testName
*
* @return array
* @return array|null
*/
private function assertException(\Exception $exception, $expectedError, $testName)
private function assertException(\Exception $exception, string $expectedError, string $testName)
{
if (is_string($expectedError) && preg_match('#^/.+?/$#', $expectedError)) {
$this->assertRegExp($expectedError, $exception->getMessage(), 'Failed to catch error in test ' . $testName);
Expand Down Expand Up @@ -754,7 +755,7 @@ private function assertException(\Exception $exception, $expectedError, $testNam
*
* @return array
*/
public function yamlProvider()
public function yamlProvider(): array
{
$this->yaml = new Yaml();
$path = __DIR__ . '/../../../util/elasticsearch/rest-api-spec/src/main/resources/rest-api-spec/test';
Expand Down Expand Up @@ -786,7 +787,7 @@ public function yamlProvider()
*
* @return array
*/
private function mapEndpoint($method, $namespace = null)
private function mapEndpoint(string $method, $namespace = null): array
{
if (null === $namespace && array_key_exists($method, static::$endpointMapping)) {
return static::$endpointMapping[$method];
Expand Down Expand Up @@ -875,11 +876,11 @@ private function resolveValue($result, $field, &$context)
/**
* Format a regex for PHP
*
* @param $regex
* @param string $regex
*
* @return string
*/
private function formatRegex($regex)
private function formatRegex(string $regex): string
{
$regex = trim($regex);
$regex = substr($regex, 1, -1);
Expand All @@ -897,9 +898,8 @@ private function formatRegex($regex)
*
* @return array
*/
private function splitDocument($file, $path, $filter = null)
private function splitDocument(SplFileInfo $file, string $path, string $filter = null): array
{

$fileContent = $file->getContents();
// cleanup some bad comments
$fileContent = str_replace('"#', '" #', $fileContent);
Expand Down Expand Up @@ -1045,7 +1045,7 @@ private function clean()
$this->waitForYellow();
}

private function rmDirRecursively($dir)
private function rmDirRecursively(string $dir)
{
if (!is_dir($dir)) {
return;
Expand Down

0 comments on commit 76d7c50

Please sign in to comment.