fix countable in php 7.2

in PHP 7.2, count does not allow null value or not countable object. This commit
adapt the use of count to the nature of the object
This commit is contained in:
Julien Fastré 2018-04-04 17:00:57 +02:00
parent c593c153a1
commit 7b4c728523
2 changed files with 23 additions and 11 deletions

View File

@ -213,7 +213,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase
$nbOfFrom = $query->getDQLPart('from') !== null ?
count($query->getDQLPart('from')) : 0;
$nbOfWhere = $query->getDQLPart('where') !== null ?
count($query->getDQLPart('where')) : 0;
$query->getDQLPart('where')->count() : 0;
$nbOfSelect = $query->getDQLPart('select') !== null ?
count($query->getDQLPart('select')) : 0;
@ -226,7 +226,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase
altered the query");
$this->assertGreaterThanOrEqual(
$nbOfWhere,
$query->getDQLPart('where') !== null ? count($query->getDQLPart('where')) : 0,
$query->getDQLPart('where') !== null ? $query->getDQLPart('where')->count() : 0,
"Test that there are equal or more 'where' clause after that the filter has"
. "altered the query");
$this->assertGreaterThanOrEqual(

View File

@ -104,20 +104,32 @@ abstract class AbstractFilterTest extends KernelTestCase
public function testAlterQuery(QueryBuilder $query, $data)
{
// retains informations about query
$nbOfFrom = count($query->getDQLPart('from'));
$nbOfWhere = count($query->getDQLPart('where'));
$nbOfSelect = count($query->getDQLPart('select'));
$nbOfFrom = $query->getDQLPart('from') !== null ?
count($query->getDQLPart('from')) : 0;
$nbOfWhere = $query->getDQLPart('where') !== null ?
$query->getDQLPart('where')->count() : 0;
$nbOfSelect = $query->getDQLPart('select') !== null ?
count($query->getDQLPart('select')) : 0;
$this->getFilter()->alterQuery($query, $data);
$this->assertGreaterThanOrEqual($nbOfFrom, count($query->getDQLPart('from')),
$this->assertGreaterThanOrEqual(
$nbOfFrom,
$query->getDQLPart('from') !== null ? count($query->getDQLPart('from')) : 0,
"Test that there are equal or more 'from' clause after that the filter has
altered the query");
$this->assertGreaterThanOrEqual($nbOfWhere, count($query->getDQLPart('where')),
altered the query"
);
$this->assertGreaterThanOrEqual(
$nbOfWhere,
$query->getDQLPart('where') !== null ? count($query->getDQLPart('where')) : 0,
"Test that there are equal or more 'where' clause after that the filter has"
. "altered the query");
$this->assertEquals($nbOfSelect, count($query->getDQLPart('select')),
"Test that the filter has no altered the 'select' part of the query");
. "altered the query"
);
$this->assertEquals(
$nbOfSelect,
$query->getDQLPart('select') !== null ? count($query->getDQLPart('select')) : 0,
"Test that the filter has no altered the 'select' part of the query"
);
}