Skip to content

Commit

Permalink
Use dedicated PHPUnit assertions (#1535)
Browse files Browse the repository at this point in the history
Following #1488, also, I've added a rule in our CS to enforce this dedicated assertions in new codes.
  • Loading branch information
carusogabriel authored and ruflin committed Nov 20, 2018
1 parent 478f425 commit d45df9f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 27 deletions.
13 changes: 8 additions & 5 deletions .php_cs
@@ -1,12 +1,12 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create()
->in(array('lib', 'test'));
->in(['lib', 'test']);

$config = Symfony\CS\Config\Config::create()
->setUsingCache(true)
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers(array(
->fixers([
// [contrib] Multi-line whitespace before closing semicolon are prohibited.
'multiline_spaces_before_semicolon',
// [contrib] There should be no blank lines before a namespace declaration.
Expand All @@ -15,15 +15,18 @@ $config = Symfony\CS\Config\Config::create()
'ordered_use',
// [contrib] Annotations should be ordered so that param annotations come first, then throws annotations, then return annotations.
'phpdoc_order',
// [contrib] Arrays should use the long syntax.
// [contrib] Arrays should use the short syntax.
'short_array_syntax',
// [contrib] Ensure there is no code on the same line as the PHP open tag.
'newline_after_open_tag',
// [contrib] Use null coalescing operator ?? where possible
'ternary_to_null_coalescing',
// [contrib] There should not be useless else cases.
// [contrib] There should not be useless else cases.
'no_useless_else',
))
// [contrib] Use dedicated PHPUnit assertions for better error messages.
'@PHPUnit60Migration:risky' => true,
'php_unit_dedicate_assert' => ['target' => 'newest'],
])
->finder($finder);

return $config;
5 changes: 1 addition & 4 deletions test/Elastica/Cluster/Health/IndexTest.php
Expand Up @@ -137,9 +137,6 @@ public function testGetShards()

$this->assertInternalType('array', $shards);
$this->assertCount(3, $shards);

foreach ($shards as $shard) {
$this->assertInstanceOf(Shard::class, $shard);
}
$this->assertContainsOnlyInstancesOf(Shard::class, $shards);
}
}
5 changes: 1 addition & 4 deletions test/Elastica/Cluster/HealthTest.php
Expand Up @@ -189,9 +189,6 @@ public function testGetIndices()
$this->assertCount(2, $indices);
$this->assertArrayHasKey('index_one', $indices);
$this->assertArrayHasKey('index_two', $indices);

foreach ($indices as $index) {
$this->assertInstanceOf(Index::class, $index);
}
$this->assertContainsOnlyInstancesOf(Index::class, $indices);
}
}
5 changes: 1 addition & 4 deletions test/Elastica/ClusterTest.php
Expand Up @@ -40,10 +40,7 @@ public function testGetNodes()

$nodes = $cluster->getNodes();

foreach ($nodes as $node) {
$this->assertInstanceOf(Node::class, $node);
}

$this->assertContainsOnlyInstancesOf(Node::class, $nodes);
$this->assertGreaterThan(0, count($nodes));
}

Expand Down
11 changes: 2 additions & 9 deletions test/Elastica/Multi/SearchTest.php
Expand Up @@ -163,10 +163,7 @@ public function testSearch()
$this->assertInstanceOf(MultiResultSet::class, $multiResultSet);
$this->assertCount(2, $multiResultSet);
$this->assertInstanceOf(Response::class, $multiResultSet->getResponse());

foreach ($multiResultSet as $resultSet) {
$this->assertInstanceOf(ResultSet::class, $resultSet);
}
$this->assertContainsOnlyInstancesOf(ResultSet::class, $multiResultSet);

$resultSets = $multiResultSet->getResultSets();

Expand Down Expand Up @@ -257,11 +254,7 @@ public function testSearchWithKeys()
$this->assertInstanceOf(MultiResultSet::class, $multiResultSet);
$this->assertCount(2, $multiResultSet);
$this->assertInstanceOf(Response::class, $multiResultSet->getResponse());

foreach ($multiResultSet as $resultSet) {
$this->assertInstanceOf(ResultSet::class, $resultSet);
}

$this->assertContainsOnlyInstancesOf(ResultSet::class, $multiResultSet);
$this->assertInstanceOf(ResultSet::class, $multiResultSet['search1']);
$this->assertInstanceOf(ResultSet::class, $multiResultSet['search2']);

Expand Down
2 changes: 1 addition & 1 deletion test/Elastica/TaskTest.php
Expand Up @@ -15,7 +15,7 @@ public function testGetData()
$task = $this->_createTask();
$data = $task->getData();

$this->assertTrue(is_array($data));
$this->assertInternalType('array', $data);
$this->assertNotEmpty($data);
}

Expand Down

0 comments on commit d45df9f

Please sign in to comment.