Skip to content

Commit

Permalink
[TEST] improve code quality of tests (#610)
Browse files Browse the repository at this point in the history
* [TEST] add missing namespace declarations

* [TEST] fixes

* [TEST] add strict_types declaration

* [TEST] fix invalid expectedException classes

* [TEST] remove unused uses
  • Loading branch information
mhujer authored and polyfractal committed Aug 10, 2017
1 parent 7f43b2e commit 9ea2156
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 15 deletions.
3 changes: 2 additions & 1 deletion tests/Elasticsearch/Tests/ClientTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

declare(strict_types = 1);

namespace Elasticsearch\Tests;

use Elasticsearch;
use Elasticsearch\ClientBuilder;
use Elasticsearch\Connections\Connection;
use Mockery as m;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);

namespace Elasticsearch\Tests\ConnectionPool\Selectors;

use Elasticsearch;
Expand Down Expand Up @@ -43,7 +45,7 @@ public function testTenConnections()
}

/**
* Add Ten connections, select five, remove thre, test another 10 to check
* Add Ten connections, select five, remove three, test another 10 to check
* that the round-robining works after removing connections
*
* @covers \Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector::select
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);

namespace Elasticsearch\Tests\ConnectionPool\Selectors;

use Elasticsearch;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php

declare(strict_types = 1);

namespace Elasticsearch\Tests\ConnectionPool;

use Elasticsearch\ClientBuilder;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

use Elasticsearch\Common\Exceptions\NoNodesAvailableException;
declare(strict_types = 1);

namespace Elasticsearch\Tests\ConnectionPool;

use Elasticsearch\ConnectionPool\SniffingConnectionPool;
use Mockery as m;

Expand Down Expand Up @@ -185,7 +188,7 @@ public function testAddTenNodesTimeoutAllButLast()
}

/**
* @expectedException Elasticsearch\Common\Exceptions\NoNodesAvailableException
* @expectedException \Elasticsearch\Common\Exceptions\NoNodesAvailableException
*/
public function testAddTenNodesAllTimeout()
{
Expand Down Expand Up @@ -262,7 +265,7 @@ public function testAddOneHostSniffTwo()
}

/**
* @expectedException Elasticsearch\Common\Exceptions\NoNodesAvailableException
* @expectedException \Elasticsearch\Common\Exceptions\NoNodesAvailableException
*/
public function testAddSeed_SniffTwo_TimeoutTwo()
{
Expand Down Expand Up @@ -363,7 +366,7 @@ public function testTen_TimeoutNine_SniffTenth_AddTwoAlive()
}

/**
* @expectedException Elasticsearch\Common\Exceptions\NoNodesAvailableException
* @expectedException \Elasticsearch\Common\Exceptions\NoNodesAvailableException
*/
public function testTen_TimeoutNine_SniffTenth_AddTwoDead_TimeoutEveryone()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

declare(strict_types = 1);

namespace Elasticsearch\Tests\ConnectionPool;

use Elasticsearch;
use Elasticsearch\Common\Exceptions\NoNodesAvailableException;
use Mockery as m;

/**
Expand Down Expand Up @@ -84,7 +85,7 @@ public function testAddMultipleHostsThenGetFirst()
}

/**
* @expectedException Elasticsearch\Common\Exceptions\NoNodesAvailableException
* @expectedException \Elasticsearch\Common\Exceptions\NoNodesAvailableException
*/
public function testAllHostsFailPing()
{
Expand Down
4 changes: 3 additions & 1 deletion tests/Elasticsearch/Tests/Endpoints/AbstractEndpointTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);

namespace Elasticsearch\Tests\Endpoints;

use Elasticsearch\Endpoints\AbstractEndpoint;
Expand All @@ -18,7 +20,7 @@ public static function invalidParameters()

/**
* @dataProvider invalidParameters
* @expectedException Elasticsearch\Common\Exceptions\UnexpectedValueException
* @expectedException \Elasticsearch\Common\Exceptions\UnexpectedValueException
*/
public function testInvalidParamsCauseErrorsWhenProvidedToSetParams(array $params)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);

namespace Elasticsearch\Tests\Helper\Iterators;

use Elasticsearch\Helper\Iterators\SearchResponseIterator;
Expand Down
4 changes: 3 additions & 1 deletion tests/Elasticsearch/Tests/RegisteredNamespaceTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);

namespace Elasticsearch\Tests;

use Elasticsearch;
Expand Down Expand Up @@ -62,4 +64,4 @@ public function fooMethod()
{
return "123";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);

namespace Elasticsearch\Tests\Serializers;

use Elasticsearch\Serializers\ArrayToJSONSerializer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);

namespace Elasticsearch\Tests\Serializers;

use Elasticsearch\Serializers\EverythingToJSONSerializer;
Expand Down
10 changes: 5 additions & 5 deletions tests/Elasticsearch/Tests/YamlRunnerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);

namespace Elasticsearch\Tests;

use Doctrine\Common\Inflector\Inflector;
Expand All @@ -12,11 +14,9 @@
use Elasticsearch\Common\Exceptions\ServerErrorResponseException;
use Elasticsearch\Common\Exceptions\RoutingMissingException;
use GuzzleHttp\Ring\Future\FutureArrayInterface;
use stdClass;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Yaml;

/**
Expand All @@ -31,7 +31,7 @@
*/
class YamlRunnerTest extends \PHPUnit_Framework_TestCase
{
/** @var Parser Yaml parser for reading integrations tests */
/** @var \Symfony\Component\Yaml\Yaml Yaml parser for reading integrations tests */
private $yaml;

/** @var Elasticsearch\Client client used by elasticsearch */
Expand Down Expand Up @@ -1029,8 +1029,8 @@ private function waitForYellow()
++$counter;

if ($counter > 10) {
$this->log("Aborting test due to failure in clearing cluster.\n");
$this->log(print_r($response, true));
echo "Aborting test due to failure in clearing cluster.\n";
echo print_r($response, true);
exit;
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);

error_reporting(E_ALL | E_STRICT);

// Set the default timezone. While this doesn't cause any tests to fail, PHP
Expand Down
2 changes: 2 additions & 0 deletions util/EnsureClusterAlive.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);

error_reporting(E_ALL | E_STRICT);

// Set the default timezone. While this doesn't cause any tests to fail, PHP
Expand Down
2 changes: 2 additions & 0 deletions util/RestSpecRunner.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types = 1);

error_reporting(E_ALL | E_STRICT);

// Set the default timezone. While this doesn't cause any tests to fail, PHP
Expand Down
2 changes: 2 additions & 0 deletions util/SpecParser.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php

declare(strict_types = 1);

require_once '../vendor/autoload.php';

$loader = new Twig_Loader_Filesystem('templates');
Expand Down

0 comments on commit 9ea2156

Please sign in to comment.