mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 03:23:48 +00:00
Update test methods to static in AbstractFilterTest
The methods getFormData() and getQueryBuilders() across multiple test classes have been updated to static methods. This refactoring is part of a broader effort to improve code structure and readability. A rector rule has been employed to assist in the systematic update of these existing methods.
This commit is contained in:
@@ -41,20 +41,17 @@ final class ActivityTypeFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData(): array
|
||||
public static function getFormData(): array
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$array = $em->createQueryBuilder()
|
||||
->from(ActivityType::class, 'at')
|
||||
->select('at')
|
||||
->getQuery()
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($array as $a) {
|
||||
$data[] = [
|
||||
'accepted_activitytypes' => [],
|
||||
@@ -86,10 +83,9 @@ final class ActivityTypeFilterTest extends AbstractFilterTest
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): array
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
return [
|
||||
|
@@ -38,20 +38,17 @@ final class ByCreatorFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData(): array
|
||||
public static function getFormData(): array
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$array = $em->createQueryBuilder()
|
||||
->from(User::class, 'u')
|
||||
->select('u')
|
||||
->getQuery()
|
||||
->setMaxResults(2)
|
||||
->getResult();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($array as $a) {
|
||||
$data[] = [
|
||||
'accepted_users' => $a,
|
||||
@@ -61,10 +58,9 @@ final class ByCreatorFilterTest extends AbstractFilterTest
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): array
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
return [
|
||||
|
@@ -38,20 +38,16 @@ final class BySocialActionFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData(): array
|
||||
public static function getFormData(): array
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$array = $em->createQueryBuilder()
|
||||
->from(SocialAction::class, 'sa')
|
||||
->select('sa')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($array as $a) {
|
||||
$data[] = [
|
||||
'accepted_socialactions' => new ArrayCollection([$a]),
|
||||
@@ -61,10 +57,9 @@ final class BySocialActionFilterTest extends AbstractFilterTest
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): array
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
return [
|
||||
|
@@ -39,20 +39,17 @@ final class BySocialIssueFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData(): array
|
||||
public static function getFormData(): array
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$array = $em->createQueryBuilder()
|
||||
->from(SocialIssue::class, 'si')
|
||||
->select('si')
|
||||
->getQuery()
|
||||
->setMaxResults(2)
|
||||
->getResult();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($array as $a) {
|
||||
$data[] = [
|
||||
'accepted_socialissues' => new ArrayCollection([$a]),
|
||||
@@ -62,12 +59,11 @@ final class BySocialIssueFilterTest extends AbstractFilterTest
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): array
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
if (null === self::$kernel) {
|
||||
self::bootKernel();
|
||||
}
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
return [
|
||||
|
@@ -38,7 +38,7 @@ final class ActivityDateFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData(): array
|
||||
public static function getFormData(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
@@ -48,16 +48,13 @@ final class ActivityDateFilterTest extends AbstractFilterTest
|
||||
];
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): iterable
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
yield $em->createQueryBuilder()
|
||||
->select('count(activity.id)')
|
||||
->from(Activity::class, 'activity');
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
}
|
||||
}
|
||||
|
@@ -44,10 +44,9 @@ class ActivityPresenceFilterTest extends AbstractFilterTest
|
||||
return new ActivityPresenceFilter($this->translatableStringHelper, $this->translator);
|
||||
}
|
||||
|
||||
public function getFormData()
|
||||
public static function getFormData(): array
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$presences = self::getContainer()->get(ActivityPresenceRepositoryInterface::class)
|
||||
->findAll();
|
||||
|
||||
@@ -61,16 +60,13 @@ class ActivityPresenceFilterTest extends AbstractFilterTest
|
||||
];
|
||||
}
|
||||
|
||||
public function getQueryBuilders()
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
yield $em->createQueryBuilder()
|
||||
->select('count(activity.id)')
|
||||
->from(Activity::class, 'activity');
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
}
|
||||
}
|
||||
|
@@ -49,35 +49,29 @@ final class ActivityReasonFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData()
|
||||
public static function getFormData(): array
|
||||
{
|
||||
self::bootKernel();
|
||||
$data = [];
|
||||
|
||||
$em = self::getContainer()
|
||||
->get(EntityManagerInterface::class);
|
||||
|
||||
$reasons = $em->createQuery('SELECT reason '
|
||||
.'FROM ChillActivityBundle:ActivityReason reason')
|
||||
->getResult();
|
||||
|
||||
// generate an array of 5 different combination of results
|
||||
for ($i = 0; 5 > $i; ++$i) {
|
||||
$data[] = ['reasons' => new ArrayCollection(array_splice($reasons, ($i + 1) * -1))];
|
||||
$data[] = ['reasons' => array_splice($reasons, ($i + 1) * -1)];
|
||||
}
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): iterable
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
yield $em->createQueryBuilder()
|
||||
->select('count(activity.id)')
|
||||
->from('ChillActivityBundle:Activity', 'activity');
|
||||
@@ -90,7 +84,6 @@ final class ActivityReasonFilterTest extends AbstractFilterTest
|
||||
->from('ChillActivityBundle:Activity', 'activity')
|
||||
->join('activity.reasons', 'reasons')
|
||||
->join('reasons.category', 'category');
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
}
|
||||
}
|
||||
|
@@ -39,20 +39,16 @@ final class ActivityTypeFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData(): iterable
|
||||
public static function getFormData(): array
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$array = $em->createQueryBuilder()
|
||||
->from(ActivityType::class, 'at')
|
||||
->select('at')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($array as $a) {
|
||||
$data[] = [
|
||||
'types' => new ArrayCollection([$a]),
|
||||
@@ -65,16 +61,13 @@ final class ActivityTypeFilterTest extends AbstractFilterTest
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): iterable
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
yield $em->createQueryBuilder()
|
||||
->select('count(activity.id)')
|
||||
->from(Activity::class, 'activity');
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
}
|
||||
}
|
||||
|
@@ -38,18 +38,15 @@ final class ByCreatorFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData(): array
|
||||
public static function getFormData(): array
|
||||
{
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$array = $em->createQueryBuilder()
|
||||
->from(User::class, 'u')
|
||||
->select('u')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($array as $a) {
|
||||
$data[] = [
|
||||
'accepted_users' => $a,
|
||||
@@ -59,12 +56,11 @@ final class ByCreatorFilterTest extends AbstractFilterTest
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): array
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
if (null === self::$kernel) {
|
||||
self::bootKernel();
|
||||
}
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
return [
|
||||
|
@@ -51,7 +51,7 @@ class CreatorJobFilterTest extends AbstractFilterTest
|
||||
);
|
||||
}
|
||||
|
||||
public function getFormData()
|
||||
public static function getFormData(): array
|
||||
{
|
||||
$this->setUp();
|
||||
$jobs = $this->userJobRepository->findAll();
|
||||
@@ -61,7 +61,7 @@ class CreatorJobFilterTest extends AbstractFilterTest
|
||||
];
|
||||
}
|
||||
|
||||
public function getQueryBuilders()
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::setUp();
|
||||
|
||||
|
@@ -38,20 +38,17 @@ final class CreatorScopeFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData(): array
|
||||
public static function getFormData(): array
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$array = $em->createQueryBuilder()
|
||||
->from(Scope::class, 's')
|
||||
->select('s')
|
||||
->getQuery()
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($array as $a) {
|
||||
$data[] = [
|
||||
'scopes' => $a,
|
||||
@@ -61,10 +58,9 @@ final class CreatorScopeFilterTest extends AbstractFilterTest
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): array
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
return [
|
||||
|
@@ -37,7 +37,7 @@ final class EmergencyFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData(): array
|
||||
public static function getFormData(): array
|
||||
{
|
||||
return [
|
||||
['accepted_emergency' => true],
|
||||
@@ -45,10 +45,9 @@ final class EmergencyFilterTest extends AbstractFilterTest
|
||||
];
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): array
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
return [
|
||||
|
@@ -38,20 +38,17 @@ final class LocationTypeFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData(): array
|
||||
public static function getFormData(): array
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$array = $em->createQueryBuilder()
|
||||
->from(LocationType::class, 'lt')
|
||||
->select('lt')
|
||||
->getQuery()
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($array as $a) {
|
||||
$data[] = [
|
||||
'accepted_locationtype' => $a,
|
||||
@@ -61,10 +58,9 @@ final class LocationTypeFilterTest extends AbstractFilterTest
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): array
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
return [
|
||||
|
@@ -39,20 +39,17 @@ final class ActivityReasonFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData(): array
|
||||
public static function getFormData(): array
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$array = $em->createQueryBuilder()
|
||||
->from(ActivityReason::class, 'ar')
|
||||
->select('ar')
|
||||
->getQuery()
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($array as $a) {
|
||||
$data[] = [
|
||||
'reasons' => new ArrayCollection([$a]),
|
||||
@@ -62,10 +59,9 @@ final class ActivityReasonFilterTest extends AbstractFilterTest
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): array
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
return [
|
||||
|
@@ -38,20 +38,17 @@ final class PersonHavingActivityBetweenDateFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData(): array
|
||||
public static function getFormData(): array
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$array = $em->createQueryBuilder()
|
||||
->from(ActivityReason::class, 'ar')
|
||||
->select('ar')
|
||||
->getQuery()
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($array as $a) {
|
||||
$data[] = [
|
||||
'date_from' => \DateTime::createFromFormat('Y-m-d', '2021-07-01'),
|
||||
@@ -63,12 +60,11 @@ final class PersonHavingActivityBetweenDateFilterTest extends AbstractFilterTest
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): array
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
if (null === self::$kernel) {
|
||||
self::bootKernel();
|
||||
}
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
return [
|
||||
|
@@ -48,14 +48,13 @@ final class PersonHavingActivityBetweenDateFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData()
|
||||
public static function getFormData(): array
|
||||
{
|
||||
$date_from = \DateTime::createFromFormat('Y-m-d', '2015-01-15');
|
||||
$date_to = new \DateTime(); // today
|
||||
$date_to = new \DateTime();
|
||||
// today
|
||||
$reasons = $this->getActivityReasons();
|
||||
|
||||
$data = [];
|
||||
|
||||
for ($i = 0; 4 > $i; ++$i) {
|
||||
$data[] = [
|
||||
'date_from' => $date_from,
|
||||
@@ -67,13 +66,11 @@ final class PersonHavingActivityBetweenDateFilterTest extends AbstractFilterTest
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getQueryBuilders()
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()
|
||||
->get(EntityManagerInterface::class);
|
||||
|
||||
yield $em->createQueryBuilder()
|
||||
->select('count(person.id)')
|
||||
->from('ChillPersonBundle:Person', 'person')
|
||||
@@ -85,7 +82,6 @@ final class PersonHavingActivityBetweenDateFilterTest extends AbstractFilterTest
|
||||
->join('activity.person', 'person')
|
||||
// add a fake where clause
|
||||
->where('person.id > 0');
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
}
|
||||
|
||||
|
@@ -39,15 +39,13 @@ class PersonsFilterTest extends AbstractFilterTest
|
||||
return new PersonsFilter($this->personRender);
|
||||
}
|
||||
|
||||
public function getFormData()
|
||||
public static function getFormData(): array
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$persons = $em->createQuery('SELECT p FROM '.Person::class.' p ')
|
||||
->setMaxResults(2)
|
||||
->getResult();
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
|
||||
return [
|
||||
@@ -57,16 +55,13 @@ class PersonsFilterTest extends AbstractFilterTest
|
||||
];
|
||||
}
|
||||
|
||||
public function getQueryBuilders()
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
yield $em->createQueryBuilder()
|
||||
->select('count(activity.id)')
|
||||
->from(Activity::class, 'activity');
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
}
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ final class SentReceivedFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData(): array
|
||||
public static function getFormData(): array
|
||||
{
|
||||
return [
|
||||
['accepted_sentreceived' => Activity::SENTRECEIVED_SENT],
|
||||
@@ -45,10 +45,9 @@ final class SentReceivedFilterTest extends AbstractFilterTest
|
||||
];
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): array
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
return [
|
||||
|
@@ -38,20 +38,17 @@ final class UserFilterTest extends AbstractFilterTest
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
public function getFormData(): array
|
||||
public static function getFormData(): array
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
$array = $em->createQueryBuilder()
|
||||
->from(User::class, 'u')
|
||||
->select('u')
|
||||
->getQuery()
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($array as $a) {
|
||||
$data[] = [
|
||||
'accepted_users' => $a,
|
||||
@@ -61,10 +58,9 @@ final class UserFilterTest extends AbstractFilterTest
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): array
|
||||
public static function getQueryBuilders(): iterable
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
return [
|
||||
|
Reference in New Issue
Block a user