mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -17,12 +17,6 @@ use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Traversable;
|
||||
|
||||
use function call_user_func;
|
||||
use function count;
|
||||
use function is_array;
|
||||
use function is_callable;
|
||||
use function is_string;
|
||||
|
||||
/**
|
||||
* Helper which creates a set of test for aggregators.
|
||||
*/
|
||||
@@ -45,7 +39,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
{
|
||||
$datas = $this->getFormData();
|
||||
|
||||
if (!is_array($datas)) {
|
||||
if (!\is_array($datas)) {
|
||||
$datas = iterator_to_array($datas);
|
||||
}
|
||||
|
||||
@@ -67,7 +61,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
{
|
||||
$datas = $this->getFormData();
|
||||
|
||||
if (!is_array($datas)) {
|
||||
if (!\is_array($datas)) {
|
||||
$datas = iterator_to_array($datas);
|
||||
}
|
||||
|
||||
@@ -86,7 +80,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
{
|
||||
$datas = $this->getFormData();
|
||||
|
||||
if (!is_array($datas)) {
|
||||
if (!\is_array($datas)) {
|
||||
$datas = iterator_to_array($datas);
|
||||
}
|
||||
|
||||
@@ -108,7 +102,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
{
|
||||
$datas = $this->getFormData();
|
||||
|
||||
if (!is_array($datas)) {
|
||||
if (!\is_array($datas)) {
|
||||
$datas = iterator_to_array($datas);
|
||||
}
|
||||
|
||||
@@ -124,7 +118,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
{
|
||||
$datas = $this->getFormData();
|
||||
|
||||
if (!is_array($datas)) {
|
||||
if (!\is_array($datas)) {
|
||||
$datas = iterator_to_array($datas);
|
||||
}
|
||||
|
||||
@@ -186,7 +180,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
|
||||
$alteredQuery = $qb->getAllAliases();
|
||||
|
||||
$this->assertGreaterThanOrEqual(count($aliases), count($alteredQuery));
|
||||
$this->assertGreaterThanOrEqual(\count($aliases), \count($alteredQuery));
|
||||
|
||||
foreach ($aliases as $alias) {
|
||||
$this->assertContains($alias, $alteredQuery);
|
||||
@@ -194,8 +188,8 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @dataProvider dataProviderQueryExecution
|
||||
*
|
||||
* @group dbIntensive
|
||||
*/
|
||||
public function testQueryExecution(QueryBuilder $qb, array $data): void
|
||||
@@ -217,30 +211,30 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
public function testAlterQuery(QueryBuilder $query, $data)
|
||||
{
|
||||
// retains informations about query
|
||||
$nbOfFrom = $query->getDQLPart('from') !== null ?
|
||||
count($query->getDQLPart('from')) : 0;
|
||||
$nbOfWhere = $query->getDQLPart('where') !== null ?
|
||||
$nbOfFrom = null !== $query->getDQLPart('from') ?
|
||||
\count($query->getDQLPart('from')) : 0;
|
||||
$nbOfWhere = null !== $query->getDQLPart('where') ?
|
||||
$query->getDQLPart('where')->count() : 0;
|
||||
$nbOfSelect = $query->getDQLPart('select') !== null ?
|
||||
count($query->getDQLPart('select')) : 0;
|
||||
$nbOfSelect = null !== $query->getDQLPart('select') ?
|
||||
\count($query->getDQLPart('select')) : 0;
|
||||
|
||||
$this->getAggregator()->alterQuery($query, $data);
|
||||
|
||||
$this->assertGreaterThanOrEqual(
|
||||
$nbOfFrom,
|
||||
$query->getDQLPart('from') !== null ? count($query->getDQLPart('from')) : 0,
|
||||
null !== $query->getDQLPart('from') ? \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,
|
||||
$query->getDQLPart('where') !== null ? $query->getDQLPart('where')->count() : 0,
|
||||
null !== $query->getDQLPart('where') ? $query->getDQLPart('where')->count() : 0,
|
||||
"Test that there are equal or more 'where' clause after that the filter has"
|
||||
. 'altered the query'
|
||||
.'altered the query'
|
||||
);
|
||||
$this->assertGreaterThanOrEqual(
|
||||
$nbOfSelect,
|
||||
$query->getDQLPart('select') !== null ? count($query->getDQLPart('select')) : 0,
|
||||
null !== $query->getDQLPart('select') ? \count($query->getDQLPart('select')) : 0,
|
||||
"Test that the filter has no altered the 'select' part of the query"
|
||||
);
|
||||
}
|
||||
@@ -283,7 +277,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
);
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
count($queryKeys),
|
||||
\count($queryKeys),
|
||||
'test that there are at least one query key returned'
|
||||
);
|
||||
}
|
||||
@@ -312,9 +306,9 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
|
||||
$results = $qb->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
|
||||
|
||||
if (count($results) === 0) {
|
||||
if (0 === \count($results)) {
|
||||
$this->markTestIncomplete('The result is empty. We cannot process tests '
|
||||
. 'on results');
|
||||
.'on results');
|
||||
}
|
||||
|
||||
// testing the result
|
||||
@@ -335,23 +329,23 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
||||
$closure = $this->getAggregator()->getLabels($key, [$result[$key]], $data);
|
||||
|
||||
$this->assertTrue(
|
||||
is_callable($closure, false),
|
||||
\is_callable($closure, false),
|
||||
'test that the `getLabels` for key is a callable'
|
||||
);
|
||||
$this->assertTrue(
|
||||
is_string((string) call_user_func($closure, $result[$key])),
|
||||
\is_string((string) \call_user_func($closure, $result[$key])),
|
||||
sprintf('test that the callable return by `getLabels` for key %s '
|
||||
. 'is a string or an be converted to a string', $key)
|
||||
.'is a string or an be converted to a string', $key)
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
// conditions
|
||||
is_string((string) call_user_func($closure, '_header'))
|
||||
&& !empty(call_user_func($closure, '_header'))
|
||||
&& call_user_func($closure, '_header') !== '_header',
|
||||
\is_string((string) \call_user_func($closure, '_header'))
|
||||
&& !empty(\call_user_func($closure, '_header'))
|
||||
&& '_header' !== \call_user_func($closure, '_header'),
|
||||
// message
|
||||
sprintf('Test that the callable return by `getLabels` for key %s '
|
||||
. 'can provide an header', $key)
|
||||
.'can provide an header', $key)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -15,15 +15,7 @@ use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\NativeQuery;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use RuntimeException;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\BrowserKit\HttpBrowser;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
use function call_user_func;
|
||||
use function count;
|
||||
use function is_callable;
|
||||
use function is_string;
|
||||
|
||||
/**
|
||||
* This class provide a set of tests for exports.
|
||||
@@ -84,14 +76,12 @@ abstract class AbstractExportTest extends WebTestCase
|
||||
$circles = $em->getRepository(\Chill\MainBundle\Entity\Scope::class)
|
||||
->findAll();
|
||||
|
||||
if (count($centers) === 0) {
|
||||
throw new RuntimeException('No center found. Did you forget to '
|
||||
. 'run `doctrine:fixtures:load` command before ?');
|
||||
if (0 === \count($centers)) {
|
||||
throw new \RuntimeException('No center found. Did you forget to run `doctrine:fixtures:load` command before ?');
|
||||
}
|
||||
|
||||
if (count($circles) === 0) {
|
||||
throw new RuntimeException('No circle found. Did you forget to '
|
||||
. 'run `doctrine:fixtures:load` command before ?');
|
||||
if (0 === \count($circles)) {
|
||||
throw new \RuntimeException('No circle found. Did you forget to run `doctrine:fixtures:load` command before ?');
|
||||
}
|
||||
|
||||
return [[
|
||||
@@ -155,7 +145,7 @@ abstract class AbstractExportTest extends WebTestCase
|
||||
$this->assertNotEmpty(
|
||||
$export->getDescription(),
|
||||
'Assert that the `getDescription` method does not return an empty '
|
||||
. 'string.'
|
||||
.'string.'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -176,7 +166,7 @@ abstract class AbstractExportTest extends WebTestCase
|
||||
);
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
count($queryKeys),
|
||||
\count($queryKeys),
|
||||
'test that there are at least one query key returned'
|
||||
);
|
||||
}
|
||||
@@ -191,7 +181,7 @@ abstract class AbstractExportTest extends WebTestCase
|
||||
* - each of this callable can provide a string for '_header'
|
||||
*
|
||||
* @param string[] $modifiers
|
||||
* @param array $acl
|
||||
* @param array $acl
|
||||
*
|
||||
* @dataProvider dataProviderInitiateQuery
|
||||
*/
|
||||
@@ -216,9 +206,9 @@ abstract class AbstractExportTest extends WebTestCase
|
||||
'assert that the returned result is an array'
|
||||
);
|
||||
|
||||
if (count($results) === 0) {
|
||||
if (0 === \count($results)) {
|
||||
$this->markTestIncomplete('The result is empty. We cannot process tests '
|
||||
. 'on results');
|
||||
.'on results');
|
||||
}
|
||||
|
||||
// testing the result
|
||||
@@ -239,18 +229,18 @@ abstract class AbstractExportTest extends WebTestCase
|
||||
$closure = $this->getExport()->getLabels($key, [$value], $data);
|
||||
|
||||
$this->assertTrue(
|
||||
is_callable($closure, false),
|
||||
\is_callable($closure, false),
|
||||
'test that the `getLabels` for key is a callable'
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
// conditions
|
||||
is_string((string) call_user_func($closure, '_header'))
|
||||
&& !empty(call_user_func($closure, '_header'))
|
||||
&& call_user_func($closure, '_header') !== '_header',
|
||||
\is_string((string) \call_user_func($closure, '_header'))
|
||||
&& !empty(\call_user_func($closure, '_header'))
|
||||
&& '_header' !== \call_user_func($closure, '_header'),
|
||||
// message
|
||||
sprintf('Test that the callable return by `getLabels` for key %s '
|
||||
. 'can provide an header', $key)
|
||||
.'can provide an header', $key)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -267,7 +257,7 @@ abstract class AbstractExportTest extends WebTestCase
|
||||
'Assert that the `getType` method return a string'
|
||||
);
|
||||
$this->assertNotEmpty($export->getType(), 'Assert that the `getType` method'
|
||||
. ' does not return an empty string.');
|
||||
.' does not return an empty string.');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -296,13 +286,13 @@ abstract class AbstractExportTest extends WebTestCase
|
||||
if ($query instanceof QueryBuilder) {
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
count($query->getDQLPart('select')),
|
||||
\count($query->getDQLPart('select')),
|
||||
"assert there is at least one 'select' part"
|
||||
);
|
||||
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
count($query->getDQLPart('from')),
|
||||
\count($query->getDQLPart('from')),
|
||||
"assert there is at least one 'from' part"
|
||||
);
|
||||
} elseif ($query instanceof NativeQuery) {
|
||||
@@ -345,8 +335,8 @@ abstract class AbstractExportTest extends WebTestCase
|
||||
);
|
||||
} elseif ($query instanceof NativeQuery) {
|
||||
$this->assertTrue(
|
||||
$export->supportsModifiers() === null
|
||||
|| count($export->supportsModifiers()) === 0,
|
||||
null === $export->supportsModifiers()
|
||||
|| 0 === \count($export->supportsModifiers()),
|
||||
'Test that the `supportsModifier` methods returns null or an empty array'
|
||||
);
|
||||
}
|
||||
|
@@ -13,15 +13,9 @@ namespace Chill\MainBundle\Test\Export;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Exception;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
use function count;
|
||||
use function get_class;
|
||||
use function is_array;
|
||||
use function is_string;
|
||||
|
||||
/**
|
||||
* Helper to test filters.
|
||||
*/
|
||||
@@ -148,7 +142,7 @@ abstract class AbstractFilterTest extends KernelTestCase
|
||||
|
||||
$alteredQuery = $qb->getAllAliases();
|
||||
|
||||
$this->assertGreaterThanOrEqual(count($aliases), count($alteredQuery));
|
||||
$this->assertGreaterThanOrEqual(\count($aliases), \count($alteredQuery));
|
||||
|
||||
foreach ($aliases as $alias) {
|
||||
$this->assertContains($alias, $alteredQuery);
|
||||
@@ -159,35 +153,36 @@ abstract class AbstractFilterTest extends KernelTestCase
|
||||
* test the alteration of query by the filter.
|
||||
*
|
||||
* @dataProvider dataProviderAlterQuery
|
||||
*
|
||||
* @group dbIntensive
|
||||
*/
|
||||
public function testAlterQuery(QueryBuilder $query, array $data)
|
||||
{
|
||||
// retains informations about query
|
||||
$nbOfFrom = $query->getDQLPart('from') !== null ?
|
||||
count($query->getDQLPart('from')) : 0;
|
||||
$nbOfWhere = $query->getDQLPart('where') !== null ?
|
||||
$nbOfFrom = null !== $query->getDQLPart('from') ?
|
||||
\count($query->getDQLPart('from')) : 0;
|
||||
$nbOfWhere = null !== $query->getDQLPart('where') ?
|
||||
$query->getDQLPart('where')->count() : 0;
|
||||
$nbOfSelect = $query->getDQLPart('select') !== null ?
|
||||
count($query->getDQLPart('select')) : 0;
|
||||
$nbOfSelect = null !== $query->getDQLPart('select') ?
|
||||
\count($query->getDQLPart('select')) : 0;
|
||||
|
||||
$this->getFilter()->alterQuery($query, $data);
|
||||
|
||||
$this->assertGreaterThanOrEqual(
|
||||
$nbOfFrom,
|
||||
$query->getDQLPart('from') !== null ? count($query->getDQLPart('from')) : 0,
|
||||
null !== $query->getDQLPart('from') ? \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,
|
||||
$query->getDQLPart('where') !== null ? $query->getDQLPart('where')->count() : 0,
|
||||
null !== $query->getDQLPart('where') ? $query->getDQLPart('where')->count() : 0,
|
||||
"Test that there are equal or more 'where' clause after that the filter has"
|
||||
. 'altered the query'
|
||||
.'altered the query'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$nbOfSelect,
|
||||
$query->getDQLPart('select') !== null ? count($query->getDQLPart('select')) : 0,
|
||||
null !== $query->getDQLPart('select') ? \count($query->getDQLPart('select')) : 0,
|
||||
"Test that the filter has no altered the 'select' part of the query"
|
||||
);
|
||||
}
|
||||
@@ -221,16 +216,16 @@ abstract class AbstractFilterTest extends KernelTestCase
|
||||
$description = $this->getFilter()->describeAction($data);
|
||||
|
||||
$this->assertTrue(
|
||||
is_string($description) || is_array($description),
|
||||
\is_string($description) || \is_array($description),
|
||||
'test that the description is a string or an array'
|
||||
);
|
||||
|
||||
if (is_string($description)) {
|
||||
if (\is_string($description)) {
|
||||
$this->assertNotEmpty(
|
||||
$description,
|
||||
'test that the description is not empty'
|
||||
);
|
||||
} elseif (is_array($description)) {
|
||||
} elseif (\is_array($description)) {
|
||||
$this->assertIsString(
|
||||
$description[0],
|
||||
'test that the first element in the description array is a string'
|
||||
@@ -245,11 +240,11 @@ abstract class AbstractFilterTest extends KernelTestCase
|
||||
$catalogue = static::$kernel->getContainer()
|
||||
->get('translator')
|
||||
->getCatalogue();
|
||||
} catch (Exception $ex) {
|
||||
} catch (\Exception $ex) {
|
||||
$this->markTestIncomplete(
|
||||
sprintf(
|
||||
"This test is incomplete due to %s thrown by 'translator' : %s, "
|
||||
. 'complete stack : %s',
|
||||
.'complete stack : %s',
|
||||
$ex::class,
|
||||
$ex->getMessage(),
|
||||
$ex->getTraceAsString()
|
||||
@@ -262,8 +257,8 @@ abstract class AbstractFilterTest extends KernelTestCase
|
||||
$description[2] ?? 'messages'
|
||||
),
|
||||
sprintf('Test that the message returned by getDescriptionAction is '
|
||||
. 'present in the catalogue of translations. HINT : check that "%s" '
|
||||
. 'is correctly translated', $description[0])
|
||||
.'present in the catalogue of translations. HINT : check that "%s" '
|
||||
.'is correctly translated', $description[0])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user