diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c6ab16576..ce379b425 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -21,8 +21,6 @@ src/Bundle/ChillPersonBundle/Tests/ - - src/Bundle/ChillPersonBundle/Tests/Export/* src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingPeriodControllerTest.php diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/PersonFilters/PersonHavingActivityBetweenDateFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/PersonFilters/PersonHavingActivityBetweenDateFilter.php index ec6aa9174..3fe4808fa 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/PersonFilters/PersonHavingActivityBetweenDateFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/PersonFilters/PersonHavingActivityBetweenDateFilter.php @@ -37,8 +37,11 @@ use function count; class PersonHavingActivityBetweenDateFilter implements ExportElementValidatedInterface, FilterInterface { - public function __construct(protected TranslatableStringHelper $translatableStringHelper, protected ActivityReasonRepository $activityReasonRepository, protected TranslatorInterface $translator) - { + public function __construct( + protected TranslatableStringHelper $translatableStringHelper, + protected ActivityReasonRepository $activityReasonRepository, + protected TranslatorInterface $translator + ) { } public function addRole(): ?string diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/ActivityTypeFilterTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/ActivityTypeFilterTest.php index 72b99375b..f5ca3d67d 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/ActivityTypeFilterTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/ActivityTypeFilterTest.php @@ -41,6 +41,7 @@ final class ActivityTypeFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() @@ -62,9 +63,7 @@ final class ActivityTypeFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/ByUserFilterTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/ByCreatorFilterTest.php similarity index 84% rename from src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/ByUserFilterTest.php rename to src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/ByCreatorFilterTest.php index 47e76e25c..cde4b9136 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/ByUserFilterTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/ByCreatorFilterTest.php @@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Tests\Export\Filter\ACPFilters; use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Export\Filter\ACPFilters\ByCreatorFilter; +use Chill\ActivityBundle\Export\Filter\ACPFilters\UserFilter; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Test\Export\AbstractFilterTest; use Doctrine\ORM\EntityManagerInterface; @@ -21,7 +22,7 @@ use Doctrine\ORM\EntityManagerInterface; * @internal * @coversNothing */ -final class ByUserFilterTest extends AbstractFilterTest +final class ByCreatorFilterTest extends AbstractFilterTest { private ByCreatorFilter $filter; @@ -29,7 +30,7 @@ final class ByUserFilterTest extends AbstractFilterTest { self::bootKernel(); - $this->filter = self::$container->get('chill.activity.export.byuser_filter'); + $this->filter = self::$container->get(ByCreatorFilter::class); } public function getFilter() @@ -39,12 +40,14 @@ final class ByUserFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(User::class, 'u') ->select('u') ->getQuery() + ->setMaxResults(2) ->getResult(); $data = []; @@ -60,9 +63,7 @@ final class ByUserFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/BySocialActionFilterTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/BySocialActionFilterTest.php index a707e1242..8a5abb5d0 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/BySocialActionFilterTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/BySocialActionFilterTest.php @@ -15,6 +15,7 @@ use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Export\Filter\ACPFilters\BySocialActionFilter; use Chill\MainBundle\Test\Export\AbstractFilterTest; use Chill\PersonBundle\Entity\SocialWork\SocialAction; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManagerInterface; /** @@ -39,19 +40,22 @@ final class BySocialActionFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); + $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(SocialAction::class, 'sa') ->select('sa') ->getQuery() + ->setMaxResults(4) ->getResult(); $data = []; foreach ($array as $a) { $data[] = [ - 'accepted_socialactions' => $a, + 'accepted_socialactions' => new ArrayCollection([$a]), ]; } @@ -60,9 +64,7 @@ final class BySocialActionFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/EmergencyFilterTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/EmergencyFilterTest.php index 5242f337a..b3ba2cec1 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/EmergencyFilterTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/EmergencyFilterTest.php @@ -46,9 +46,7 @@ final class EmergencyFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/LocationTypeFilterTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/LocationTypeFilterTest.php index c037a28b1..7aa208da5 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/LocationTypeFilterTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/LocationTypeFilterTest.php @@ -39,12 +39,14 @@ final class LocationTypeFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(LocationType::class, 'lt') ->select('lt') ->getQuery() + ->setMaxResults(1) ->getResult(); $data = []; @@ -60,9 +62,7 @@ final class LocationTypeFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/SentReceivedFilterTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/SentReceivedFilterTest.php index 6b16daa99..529c37864 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/SentReceivedFilterTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/SentReceivedFilterTest.php @@ -46,9 +46,7 @@ final class SentReceivedFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/UserFilterTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/UserFilterTest.php index fda613d2e..de7e29241 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/UserFilterTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/UserFilterTest.php @@ -39,12 +39,14 @@ final class UserFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(User::class, 'u') ->select('u') ->getQuery() + ->setMaxResults(1) ->getResult(); $data = []; @@ -60,9 +62,7 @@ final class UserFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/UserScopeFilterTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/UserScopeFilterTest.php index 5742662b2..844293142 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/UserScopeFilterTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ACPFilters/UserScopeFilterTest.php @@ -39,12 +39,14 @@ final class UserScopeFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(Scope::class, 's') ->select('s') ->getQuery() + ->setMaxResults(1) ->getResult(); $data = []; @@ -60,9 +62,7 @@ final class UserScopeFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ActivityDateFilterTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ActivityDateFilterTest.php index 8d6d6b790..1f5b7a3a8 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ActivityDateFilterTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ActivityDateFilterTest.php @@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Tests\Export\Filter; use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Export\Filter\ActivityDateFilter; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; use DateTime; use Doctrine\ORM\EntityManagerInterface; @@ -41,24 +42,23 @@ final class ActivityDateFilterTest extends AbstractFilterTest { return [ [ - 'date_from' => DateTime::createFromFormat('Y-m-d', '2020-01-01'), - 'date_to' => DateTime::createFromFormat('Y-m-d', '2021-01-01'), + 'date_from' => new RollingDate(RollingDate::T_FIXED_DATE, \DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01')), + 'date_to' => new RollingDate(RollingDate::T_FIXED_DATE, \DateTimeImmutable::createFromFormat('Y-m-d', '2021-01-01')), ], ]; } - public function getQueryBuilders(): array + public function getQueryBuilders(): iterable { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); - return [ + yield $em->createQueryBuilder() ->select('count(activity.id)') - ->from(Activity::class, 'activity'), - ]; + ->from(Activity::class, 'activity'); + + self::ensureKernelShutdown(); } } diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ActivityReasonFilterTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ActivityReasonFilterTest.php index 26d5248ae..6282200de 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ActivityReasonFilterTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ActivityReasonFilterTest.php @@ -14,7 +14,9 @@ namespace Chill\ActivityBundle\Tests\Export\Filter; use Chill\ActivityBundle\Export\Filter\PersonFilters\ActivityReasonFilter; use Chill\MainBundle\Test\Export\AbstractFilterTest; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\EntityManagerInterface; use Prophecy\PhpUnit\ProphecyTrait; +use Symfony\Component\HttpFoundation\RequestStack; /** * @internal @@ -37,7 +39,7 @@ final class ActivityReasonFilterTest extends AbstractFilterTest $request->getLocale()->willReturn('fr'); - self::$container->get('request_stack') + self::$container->get(RequestStack::class) ->push($request->reveal()); } @@ -48,12 +50,10 @@ final class ActivityReasonFilterTest extends AbstractFilterTest public function getFormData() { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); - $em = self::$kernel->getContainer() - ->get('doctrine.orm.entity_manager'); + $em = self::$container + ->get(EntityManagerInterface::class); $reasons = $em->createQuery('SELECT reason ' . 'FROM ChillActivityBundle:ActivityReason reason') @@ -61,34 +61,31 @@ final class ActivityReasonFilterTest extends AbstractFilterTest // generate an array of 5 different combination of results for ($i = 0; 5 > $i; ++$i) { - $r[] = ['reasons' => new ArrayCollection(array_splice($reasons, ($i + 1) * -1))]; + yield ['reasons' => new ArrayCollection(array_splice($reasons, ($i + 1) * -1))]; } - return $r; + self::ensureKernelShutdown(); } - public function getQueryBuilders() + public function getQueryBuilders(): iterable { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); - $em = self::$kernel->getContainer() - ->get('doctrine.orm.entity_manager'); + $em = self::$container->get(EntityManagerInterface::class); - return [ - $em->createQueryBuilder() - ->select('count(activity.id)') - ->from('ChillActivityBundle:Activity', 'activity'), - $em->createQueryBuilder() - ->select('count(activity.id)') - ->from('ChillActivityBundle:Activity', 'activity') - ->join('activity.reasons', 'reasons'), - $em->createQueryBuilder() - ->select('count(activity.id)') - ->from('ChillActivityBundle:Activity', 'activity') - ->join('activity.reasons', 'reasons') - ->join('reasons.category', 'category'), - ]; + yield $em->createQueryBuilder() + ->select('count(activity.id)') + ->from('ChillActivityBundle:Activity', 'activity'); + yield $em->createQueryBuilder() + ->select('count(activity.id)') + ->from('ChillActivityBundle:Activity', 'activity') + ->join('activity.reasons', 'reasons'); + yield $em->createQueryBuilder() + ->select('count(activity.id)') + ->from('ChillActivityBundle:Activity', 'activity') + ->join('activity.reasons', 'reasons') + ->join('reasons.category', 'category'); + + self::ensureKernelShutdown(); } } diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ActivityTypeFilterTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ActivityTypeFilterTest.php index 9fd1250ca..e0b590e75 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ActivityTypeFilterTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/ActivityTypeFilterTest.php @@ -15,6 +15,7 @@ use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Entity\ActivityType; use Chill\ActivityBundle\Export\Filter\ActivityTypeFilter; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManagerInterface; /** @@ -37,8 +38,10 @@ final class ActivityTypeFilterTest extends AbstractFilterTest return $this->filter; } - public function getFormData(): array + public function getFormData(): iterable { + self::bootKernel(); + $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() @@ -51,25 +54,24 @@ final class ActivityTypeFilterTest extends AbstractFilterTest foreach ($array as $a) { $data[] = [ - 'types' => $a, + 'types' => new ArrayCollection([$a]), ]; } return $data; } - public function getQueryBuilders(): array + public function getQueryBuilders(): iterable { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); - return [ + yield $em->createQueryBuilder() ->select('count(activity.id)') - ->from(Activity::class, 'activity'), - ]; + ->from(Activity::class, 'activity'); + + self::ensureKernelShutdown(); } } diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/PersonFilters/ActivityReasonFilterTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/PersonFilters/ActivityReasonFilterTest.php index b4e962ba9..6c28b846e 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/PersonFilters/ActivityReasonFilterTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/PersonFilters/ActivityReasonFilterTest.php @@ -15,6 +15,7 @@ use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Entity\ActivityReason; use Chill\ActivityBundle\Export\Filter\PersonFilters\ActivityReasonFilter; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManagerInterface; /** @@ -39,19 +40,21 @@ final class ActivityReasonFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(ActivityReason::class, 'ar') ->select('ar') ->getQuery() + ->setMaxResults(1) ->getResult(); $data = []; foreach ($array as $a) { $data[] = [ - 'reasons' => $a, + 'reasons' => new ArrayCollection([$a]), ]; } @@ -60,9 +63,7 @@ final class ActivityReasonFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/PersonFilters/PersonHavingActivityBetweenDateFilterTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/PersonFilters/PersonHavingActivityBetweenDateFilterTest.php index eb296e9a4..92d05f9cf 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/PersonFilters/PersonHavingActivityBetweenDateFilterTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/PersonFilters/PersonHavingActivityBetweenDateFilterTest.php @@ -40,12 +40,14 @@ final class PersonHavingActivityBetweenDateFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(ActivityReason::class, 'ar') ->select('ar') ->getQuery() + ->setMaxResults(1) ->getResult(); $data = []; diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/PersonHavingActivityBetweenDateFilterTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/PersonHavingActivityBetweenDateFilterTest.php index 762de529e..1552b951f 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Filter/PersonHavingActivityBetweenDateFilterTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Filter/PersonHavingActivityBetweenDateFilterTest.php @@ -12,8 +12,13 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Tests\Export\Filter; use Chill\ActivityBundle\Export\Filter\PersonFilters\PersonHavingActivityBetweenDateFilter; +use Chill\ActivityBundle\Repository\ActivityReasonRepository; use Chill\MainBundle\Test\Export\AbstractFilterTest; use DateTime; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\ManagerRegistry; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use function array_slice; /** @@ -35,7 +40,7 @@ final class PersonHavingActivityBetweenDateFilterTest extends AbstractFilterTest $request->getLocale()->willReturn('fr'); - self::$container->get('request_stack') + self::$container->get(RequestStack::class) ->push($request->reveal()); } @@ -65,26 +70,24 @@ final class PersonHavingActivityBetweenDateFilterTest extends AbstractFilterTest public function getQueryBuilders() { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); - $em = self::$kernel->getContainer() - ->get('doctrine.orm.entity_manager'); + $em = self::$container + ->get(EntityManagerInterface::class); - return [ - $em->createQueryBuilder() - ->select('count(person.id)') - ->from('ChillPersonBundle:Person', 'person') - // add a fake where clause - ->where('person.id > 0'), - $em->createQueryBuilder() - ->select('count(person.id)') - ->from('ChillActivityBundle:Activity', 'activity') - ->join('activity.person', 'person') - // add a fake where clause - ->where('person.id > 0'), - ]; + yield $em->createQueryBuilder() + ->select('count(person.id)') + ->from('ChillPersonBundle:Person', 'person') + // add a fake where clause + ->where('person.id > 0'); + yield $em->createQueryBuilder() + ->select('count(person.id)') + ->from('ChillActivityBundle:Activity', 'activity') + ->join('activity.person', 'person') + // add a fake where clause + ->where('person.id > 0'); + + self::ensureKernelShutdown(); } /** @@ -94,12 +97,14 @@ final class PersonHavingActivityBetweenDateFilterTest extends AbstractFilterTest */ private function getActivityReasons() { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); - return self::$kernel->getContainer() - ->get('chill_activity.repository.reason') - ->findAll(); + $managerRegistry = self::$container->get(ManagerRegistry::class); + $requestStack = new RequestStack(); + $requestStack->push(new Request()); + + $repository = new ActivityReasonRepository($managerRegistry, $requestStack); + + return $repository->findAll(); } } diff --git a/src/Bundle/ChillCalendarBundle/Tests/Export/Filter/BetweenDatesFilterTest.php b/src/Bundle/ChillCalendarBundle/Tests/Export/Filter/BetweenDatesFilterTest.php index e8cee9ef1..a8c8b1749 100644 --- a/src/Bundle/ChillCalendarBundle/Tests/Export/Filter/BetweenDatesFilterTest.php +++ b/src/Bundle/ChillCalendarBundle/Tests/Export/Filter/BetweenDatesFilterTest.php @@ -63,9 +63,7 @@ final class BetweenDatesFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillCalendarBundle/Tests/Export/Filter/JobFilterTest.php b/src/Bundle/ChillCalendarBundle/Tests/Export/Filter/JobFilterTest.php index 61cb47120..42629896c 100644 --- a/src/Bundle/ChillCalendarBundle/Tests/Export/Filter/JobFilterTest.php +++ b/src/Bundle/ChillCalendarBundle/Tests/Export/Filter/JobFilterTest.php @@ -50,32 +50,24 @@ final class JobFilterTest extends AbstractFilterTest return $this->filter; } - public function getFormData(): array + public function getFormData(): iterable { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(UserJob::class, 'uj') ->select('uj') ->getQuery() + ->setMaxResults(1) ->getResult(); - $data = []; - - foreach ($array as $a) { - $data[] = [ - 'job' => $a, - ]; - } - - return $data; + yield ['job' => $array]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); @@ -83,7 +75,6 @@ final class JobFilterTest extends AbstractFilterTest $em->createQueryBuilder() ->select('cal.id') ->from(Calendar::class, 'cal') - ->join('cal.user', 'caluser'), ]; } } diff --git a/src/Bundle/ChillCalendarBundle/Tests/Export/Filter/ScopeFilterTest.php b/src/Bundle/ChillCalendarBundle/Tests/Export/Filter/ScopeFilterTest.php index a6ab9ed7b..eef7d1362 100644 --- a/src/Bundle/ChillCalendarBundle/Tests/Export/Filter/ScopeFilterTest.php +++ b/src/Bundle/ChillCalendarBundle/Tests/Export/Filter/ScopeFilterTest.php @@ -52,12 +52,14 @@ final class ScopeFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(Scope::class, 's') ->select('s') ->getQuery() + ->setMaxResults(1) ->getResult(); $data = []; @@ -73,9 +75,7 @@ final class ScopeFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); @@ -83,7 +83,6 @@ final class ScopeFilterTest extends AbstractFilterTest $em->createQueryBuilder() ->select('cal.id') ->from(Calendar::class, 'cal') - ->join('cal.user', 'caluser'), ]; } } diff --git a/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php b/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php index 4304a92d1..37455799d 100644 --- a/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php +++ b/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php @@ -23,8 +23,6 @@ use function is_string; /** * Helper to test filters. - * - * @internal */ abstract class AbstractFilterTest extends KernelTestCase { @@ -50,18 +48,45 @@ abstract class AbstractFilterTest extends KernelTestCase */ public function dataProviderAliasDidNotDisappears() { + $datas = $this->getFormData(); + foreach ($this->getQueryBuilders() as $qb) { - foreach ($this->getFormData() as $data) { - yield [clone $qb, $data]; + if ([] === $datas) { + yield [clone $qb, []]; + } else { + foreach ($datas as $data) { + yield [clone $qb, $data]; + } } } } public function dataProviderAlterQuery() { + $datas = $this->getFormData(); + foreach ($this->getQueryBuilders() as $qb) { - foreach ($this->getFormData() as $data) { - yield [$qb, $data]; + if ([] === $datas) { + yield [clone $qb, []]; + } else { + foreach ($datas as $data) { + yield [clone $qb, $data]; + } + } + } + } + + public function dataProvideQueryExecution(): iterable + { + $datas = $this->getFormData(); + + foreach ($this->getQueryBuilders() as $qb) { + if ([] === $datas) { + yield [clone $qb, []]; + } else { + foreach ($datas as $data) { + yield [clone $qb, $data]; + } } } } @@ -108,10 +133,8 @@ abstract class AbstractFilterTest extends KernelTestCase * Compare aliases array before and after that filter alter query. * * @dataProvider dataProviderAliasDidNotDisappears - * - * @return void */ - public function testAliasDidNotDisappears(QueryBuilder $qb, array $data) + public function testAliasDidNotDisappears(QueryBuilder $qb, array $data): void { $aliases = $qb->getAllAliases(); @@ -131,9 +154,8 @@ abstract class AbstractFilterTest extends KernelTestCase * * @dataProvider dataProviderAlterQuery * - * @param type $data */ - public function testAlterQuery(QueryBuilder $query, $data) + public function testAlterQuery(QueryBuilder $query, array $data) { // retains informations about query $nbOfFrom = $query->getDQLPart('from') !== null ? @@ -164,6 +186,18 @@ abstract class AbstractFilterTest extends KernelTestCase ); } + /** + * @dataProvider dataProvideQueryExecution + */ + public function testQueryExecution(QueryBuilder $qb, mixed $data): void + { + $this->getFilter()->alterQuery($qb, $data); + + $actual = $qb->getQuery()->getResult(); + + self::assertIsArray($actual); + } + public function testApplyOn() { $filter = $this->getFilter(); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilter.php index 4cdedd8a3..c90189ff5 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilter.php @@ -79,7 +79,7 @@ class ReferrerFilter implements FilterInterface } public function getFormDefaultData(): array { - return ['date_calc' => new RollingDate(RollingDate::T_TODAY)]; + return ['date_calc' => new RollingDate(RollingDate::T_TODAY), 'accepted_referrers' => []]; } public function describeAction($data, $format = 'string'): array diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ActiveOnDateFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ActiveOnDateFilterTest.php index a01db6367..22420c7d5 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ActiveOnDateFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ActiveOnDateFilterTest.php @@ -11,7 +11,9 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\AccompanyingCourseFilters; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\ActiveOnDateFilter; use DateTime; use Doctrine\ORM\EntityManagerInterface; @@ -40,22 +42,20 @@ final class ActiveOnDateFilterTest extends AbstractFilterTest { return [ [ - 'on_date' => DateTime::createFromFormat('Y-m-d', '2022-05-01'), + 'on_date' => new RollingDate(RollingDate::T_FIXED_DATE, \DateTimeImmutable::createFromFormat('Y-m-d', '2022-05-01')), ], ]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() - ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') + ->from(AccompanyingPeriod::class, 'acp') ->select('acp.id'), ]; } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ActiveOneDayBetweenDatesFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ActiveOneDayBetweenDatesFilterTest.php index 5bfbcbe22..f857dca7a 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ActiveOneDayBetweenDatesFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ActiveOneDayBetweenDatesFilterTest.php @@ -11,7 +11,9 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\AccompanyingCourseFilters; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\ActiveOneDayBetweenDatesFilter; use DateTime; use Doctrine\ORM\EntityManagerInterface; @@ -40,24 +42,22 @@ final class ActiveOneDayBetweenDatesFilterTest extends AbstractFilterTest { return [ [ - 'date_from' => DateTime::createFromFormat('Y-m-d', '2022-05-01'), - 'date_to' => DateTime::createFromFormat('Y-m-d', '2022-06-01'), + 'date_from' => new RollingDate(RollingDate::T_FIXED_DATE, \DateTimeImmutable::createFromFormat('Y-m-d', '2022-05-01')), + 'date_to' => new RollingDate(RollingDate::T_FIXED_DATE, \DateTimeImmutable::createFromFormat('Y-m-d', '2022-06-01')), ], ]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() - ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') - ->select('acp.id'), + ->from(AccompanyingPeriod::class, 'acp') + ->select('count(distinct acp)'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/AdministrativeLocationFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/AdministrativeLocationFilterTest.php index 3c0c39956..580f1e7c4 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/AdministrativeLocationFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/AdministrativeLocationFilterTest.php @@ -38,12 +38,14 @@ final class AdministrativeLocationFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(Location::class, 'l') ->select('l') ->getQuery() + ->setMaxResults(1) ->getResult(); $data = []; @@ -57,9 +59,7 @@ final class AdministrativeLocationFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ClosingMotiveFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ClosingMotiveFilterTest.php index 26c686c0d..2f1ddd52f 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ClosingMotiveFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ClosingMotiveFilterTest.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive; use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\ClosingMotiveFilter; use Doctrine\ORM\EntityManagerInterface; @@ -38,6 +39,7 @@ final class ClosingMotiveFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() @@ -57,16 +59,14 @@ final class ClosingMotiveFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() ->select('acp.id') - ->from('ChillPersonBundle:AccompanyingPeriod', 'acp'), + ->from(AccompanyingPeriod::class, 'acp'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ConfidentialFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ConfidentialFilterTest.php index 73c8f1370..431d5ba93 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ConfidentialFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ConfidentialFilterTest.php @@ -45,9 +45,7 @@ final class ConfidentialFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/EmergencyFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/EmergencyFilterTest.php index 18b85915a..3c7489424 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/EmergencyFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/EmergencyFilterTest.php @@ -38,16 +38,14 @@ final class EmergencyFilterTest extends AbstractFilterTest public function getFormData(): array { return [ - ['accepted_emergencies' => true], - ['accepted_emergencies' => false], + ['accepted_emergency' => true], + ['accepted_emergency' => false], ]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/EvaluationFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/EvaluationFilterTest.php index 60027c41d..bf4ef7de0 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/EvaluationFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/EvaluationFilterTest.php @@ -38,12 +38,14 @@ final class EvaluationFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(Evaluation::class, 'ev') ->select('ev') ->getQuery() + ->setMaxResults(1) ->getResult(); $data = []; @@ -57,9 +59,7 @@ final class EvaluationFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilterTest.php index 8ef085beb..235d6487f 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilterTest.php @@ -11,7 +11,11 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\AccompanyingCourseFilters; +use Chill\MainBundle\Entity\GeographicalUnit; +use Chill\MainBundle\Repository\GeographicalUnitRepositoryInterface; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\GeographicalUnitStatFilter; use DateTime; use Doctrine\ORM\EntityManagerInterface; @@ -38,25 +42,28 @@ final class GeographicalUnitStatFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); + $repo = self::$container->get(GeographicalUnitRepositoryInterface::class); + + $units = $repo->findAll(); + return [ [ - 'date' => DateTime::createFromFormat('Y-m-d', '2022-05-01'), - 'accepted_loctype' => 'center', + 'date_calc' => new RollingDate(RollingDate::T_TODAY), + 'units' => $units ], ]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() - ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') + ->from(AccompanyingPeriod::class, 'acp') ->select('acp.id'), ]; } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/IntensityFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/IntensityFilterTest.php index ade9efd50..b5b22da4e 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/IntensityFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/IntensityFilterTest.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\IntensityFilter; use Doctrine\ORM\EntityManagerInterface; @@ -45,16 +46,14 @@ final class IntensityFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() ->select('acp.id') - ->from('ChillPersonBundle:AccompanyingPeriod', 'acp'), + ->from(AccompanyingPeriod::class, 'acp'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/OpenBetweenDatesFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/OpenBetweenDatesFilterTest.php index b29570db6..56713b5a1 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/OpenBetweenDatesFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/OpenBetweenDatesFilterTest.php @@ -11,7 +11,9 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\AccompanyingCourseFilters; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\OpenBetweenDatesFilter; use DateTime; use Doctrine\ORM\EntityManagerInterface; @@ -40,23 +42,21 @@ final class OpenBetweenDatesFilterTest extends AbstractFilterTest { return [ [ - 'date_from' => DateTime::createFromFormat('Y-m-d', '2022-05-01'), - 'date_to' => DateTime::createFromFormat('Y-m-d', '2022-06-01'), + 'date_from' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), + 'date_to' => new RollingDate(RollingDate::T_TODAY), ], ]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() - ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') + ->from(AccompanyingPeriod::class, 'acp') ->select('acp.id'), ]; } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/OriginFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/OriginFilterTest.php index 01962bd51..41a271e4b 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/OriginFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/OriginFilterTest.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin; use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\OriginFilter; use Doctrine\ORM\EntityManagerInterface; @@ -38,12 +39,14 @@ final class OriginFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(Origin::class, 'o') ->select('o') ->getQuery() + ->setMaxResults(1) ->getResult(); $data = []; @@ -57,16 +60,14 @@ final class OriginFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() ->select('acp.id') - ->from('ChillPersonBundle:AccompanyingPeriod', 'acp'), + ->from(AccompanyingPeriod::class, 'acp'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ReferrerFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ReferrerFilterTest.php index 3ab1f94ec..c79b5e9b8 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ReferrerFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ReferrerFilterTest.php @@ -12,7 +12,11 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Entity\User; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\AccompanyingPeriod; +use Chill\PersonBundle\Entity\Person\PersonCenterHistory; +use Chill\PersonBundle\Export\Export\CountAccompanyingPeriodWork; use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\ReferrerFilter; use Doctrine\ORM\EntityManagerInterface; @@ -38,42 +42,46 @@ final class ReferrerFilterTest extends AbstractFilterTest public function getFormData(): array { + self:self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(User::class, 'u') ->select('u') ->getQuery() + ->setMaxResults(1) ->getResult(); $data = []; foreach ($array as $u) { - $data[] = ['accepted_referrers' => $u]; + $data[] = ['accepted_referrers' => $u, 'date_calc' => new RollingDate(RollingDate::T_TODAY)]; } return $data; } - public function getQueryBuilders(): array + public function getQueryBuilders(): iterable { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); - return [ - $em->createQueryBuilder() - ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') - ->select('acp.id'), - $em->createQueryBuilder() - ->from('ChillPersonBundle:AccompanyingPeriod\AccompanyingPeriodWork', 'acpw') - ->select('acpw.id'), - $em->createQueryBuilder() - ->from('ChillPersonBundle:AccompanyingPeriod\AccompanyingPeriodWork', 'acpw') - ->join('acpw.referrers', 'acpwuser') - ->select('acpwuser.id'), - ]; + yield $em->createQueryBuilder() + ->from(AccompanyingPeriod::class, 'acp') + ->select('acp.id'); + + $qb = $em->createQueryBuilder(); + $qb + ->from(AccompanyingPeriod\AccompanyingPeriodWork::class, 'acpw') + ->join('acpw.accompanyingPeriod', 'acp') + ->join('acp.participations', 'acppart') + ->join('acppart.person', 'person') + ; + + $qb->select('COUNT(DISTINCT acpw.id) as export_result'); + + yield $qb; + } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/RequestorFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/RequestorFilterTest.php index 25cc86c57..50b5941bc 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/RequestorFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/RequestorFilterTest.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\RequestorFilter; use Doctrine\ORM\EntityManagerInterface; @@ -47,15 +48,13 @@ final class RequestorFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() - ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') + ->from(AccompanyingPeriod::class, 'acp') ->select('acp.id'), ]; } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/SocialActionFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/SocialActionFilterTest.php index 76bd55afb..7d4be6476 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/SocialActionFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/SocialActionFilterTest.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\SocialWork\SocialAction; use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\SocialActionFilter; use Doctrine\ORM\EntityManagerInterface; @@ -36,36 +37,30 @@ final class SocialActionFilterTest extends AbstractFilterTest return $this->filter; } - public function getFormData(): array + public function getFormData(): iterable { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(SocialAction::class, 'sa') ->select('sa') ->getQuery() + ->setMaxResults(1) ->getResult(); - $data = []; - - foreach ($array as $a) { - $data[] = ['accepted_socialactions' => $a]; - } - - return $data; + yield ['accepted_socialactions' => $array]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() - ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') + ->from(AccompanyingPeriod::class, 'acp') ->select('acp.id'), ]; } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/SocialIssueFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/SocialIssueFilterTest.php index 2776ab8dd..74eb3534d 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/SocialIssueFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/SocialIssueFilterTest.php @@ -12,8 +12,10 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\SocialIssueFilter; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManagerInterface; /** @@ -36,37 +38,31 @@ final class SocialIssueFilterTest extends AbstractFilterTest return $this->filter; } - public function getFormData(): array + public function getFormData(): iterable { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(SocialIssue::class, 'si') ->select('si') ->getQuery() + ->setMaxResults(1) ->getResult(); - $data = []; - - foreach ($array as $i) { - $data[] = ['accepted_socialissues' => $i]; - } - - return $data; + yield ['accepted_socialissues' => new ArrayCollection($array)]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() ->select('acp.id') - ->from('ChillPersonBundle:AccompanyingPeriod', 'acp'), + ->from(AccompanyingPeriod::class, 'acp'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/StepFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/StepFilterTest.php index 1b6224487..5b9ef5f4f 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/StepFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/StepFilterTest.php @@ -11,9 +11,11 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\AccompanyingCourseFilters; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\StepFilterOnDate; +use Doctrine\ORM\EntityManagerInterface; /** * @internal @@ -27,7 +29,7 @@ final class StepFilterTest extends AbstractFilterTest { self::bootKernel(); - $this->filter = self::$container->get('chill.person.export.filter_step'); + $this->filter = self::$container->get(StepFilterOnDate::class); } public function getFilter() @@ -35,29 +37,29 @@ final class StepFilterTest extends AbstractFilterTest return $this->filter; } - public function getFormData(): array + public function getFormData(): iterable { - return [ - ['accepted_steps' => AccompanyingPeriod::STEP_DRAFT], - ['accepted_steps' => AccompanyingPeriod::STEP_CONFIRMED], - ['accepted_steps' => AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_LONG], - ['accepted_steps' => AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_SHORT], - ['accepted_steps' => AccompanyingPeriod::STEP_CLOSED], - ]; + foreach ([ + ['accepted_steps_multi' => [AccompanyingPeriod::STEP_DRAFT]], + ['accepted_steps_multi' => [AccompanyingPeriod::STEP_CONFIRMED]], + ['accepted_steps_multi' => [AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_LONG]], + ['accepted_steps_multi' => [AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_SHORT]], + ['accepted_steps_multi' => [AccompanyingPeriod::STEP_CLOSED]], + ] as $d) { + yield ['calc_date' => new RollingDate(RollingDate::T_TODAY), ...$d] ; + } } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); - $em = self::$container->get('doctrine.orm.entity_manager'); + $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() ->select('acp.id') - ->from('ChillPersonBundle:AccompanyingPeriod', 'acp'), + ->from(AccompanyingPeriod::class, 'acp'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/CurrentUserJobFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/UserJobFilterTest.php similarity index 53% rename from src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/CurrentUserJobFilterTest.php rename to src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/UserJobFilterTest.php index dbf7a8fe3..86cced5e1 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/CurrentUserJobFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/UserJobFilterTest.php @@ -11,15 +11,19 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\AccompanyingCourseFilters; +use Chill\MainBundle\Entity\UserJob; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\UserJobFilter; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManagerInterface; /** * @internal * @coversNothing */ -final class CurrentUserJobFilterTest extends AbstractFilterTest +final class UserJobFilterTest extends AbstractFilterTest { private UserJobFilter $filter; @@ -27,7 +31,7 @@ final class CurrentUserJobFilterTest extends AbstractFilterTest { self::bootKernel(); - $this->filter = self::$container->get('chill.person.export.filter_userjob'); + $this->filter = self::$container->get(UserJobFilter::class); } public function getFilter() @@ -35,23 +39,30 @@ final class CurrentUserJobFilterTest extends AbstractFilterTest return $this->filter; } - public function getFormData(): array + public function getFormData(): iterable { - return []; + self::bootKernel(); + $jobs = self::$container->get(EntityManagerInterface::class) + ->createQuery('SELECT j FROM ' . UserJob::class . ' j') + ->setMaxResults(1) + ->getResult(); + + yield [ + 'jobs' => new ArrayCollection($jobs), + 'date_calc' => new RollingDate(RollingDate::T_TODAY) + ]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() ->select('acp.id') - ->from('ChillPersonBundle:AccompanyingPeriod', 'acp'), + ->from(AccompanyingPeriod::class, 'acp'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/CurrentUserScopeFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/UserScopeFilterTest.php similarity index 54% rename from src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/CurrentUserScopeFilterTest.php rename to src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/UserScopeFilterTest.php index 9140d5c41..de2c397fa 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/CurrentUserScopeFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/UserScopeFilterTest.php @@ -11,15 +11,19 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\AccompanyingCourseFilters; +use Chill\MainBundle\Entity\Scope; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\UserScopeFilter; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManagerInterface; /** * @internal * @coversNothing */ -final class CurrentUserScopeFilterTest extends AbstractFilterTest +final class UserScopeFilterTest extends AbstractFilterTest { private UserScopeFilter $filter; @@ -27,7 +31,7 @@ final class CurrentUserScopeFilterTest extends AbstractFilterTest { self::bootKernel(); - $this->filter = self::$container->get('chill.person.export.filter_userscope'); + $this->filter = self::$container->get(UserScopeFilter::class); } public function getFilter() @@ -37,21 +41,30 @@ final class CurrentUserScopeFilterTest extends AbstractFilterTest public function getFormData(): array { - return []; + self::bootKernel(); + $scopes = self::$container->get(EntityManagerInterface::class) + ->createQuery('SELECT s FROM ' . Scope::class . ' s') + ->setMaxResults(1) + ->getResult(); + + return [ + [ + 'date_calc' => new RollingDate(RollingDate::T_TODAY), + 'scopes' => new ArrayCollection($scopes), + ] + ]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() ->select('acp.id') - ->from('ChillPersonBundle:AccompanyingPeriod', 'acp'), + ->from(AccompanyingPeriod::class, 'acp'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilters/EvaluationTypeFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilters/EvaluationTypeFilterTest.php index 320a98249..5217e0d57 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilters/EvaluationTypeFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilters/EvaluationTypeFilterTest.php @@ -39,12 +39,14 @@ final class EvaluationTypeFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(Evaluation::class, 'e') ->select('e') ->getQuery() + ->setMaxResults(1) ->getResult(); $data = []; @@ -60,18 +62,16 @@ final class EvaluationTypeFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() - ->select('workeval.id') + ->select('eval.id') ->from(AccompanyingPeriod::class, 'acp') ->join('acp.works', 'acpw') - ->join('acpw.accompanyingPeriodWorkEvaluations', 'workeval'), + ->join('acpw.accompanyingPeriodWorkEvaluations', 'eval'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilters/MaxDateFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilters/MaxDateFilterTest.php index 2b3870b82..7b2262770 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilters/MaxDateFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilters/MaxDateFilterTest.php @@ -46,9 +46,7 @@ final class MaxDateFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/HouseholdFilters/CompositionFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/HouseholdFilters/CompositionFilterTest.php index aa8ec6c2c..74f8a787f 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/HouseholdFilters/CompositionFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/HouseholdFilters/CompositionFilterTest.php @@ -11,9 +11,11 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\HouseholdFilters; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Household\HouseholdCompositionType; +use Chill\PersonBundle\Entity\Person\PersonCenterHistory; use Chill\PersonBundle\Export\Filter\HouseholdFilters\CompositionFilter; use DateTime; use Doctrine\ORM\EntityManagerInterface; @@ -40,12 +42,14 @@ final class CompositionFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(HouseholdCompositionType::class, 'r') ->select('r') ->getQuery() + ->setMaxResults(1) ->getResult(); $data = []; @@ -53,25 +57,33 @@ final class CompositionFilterTest extends AbstractFilterTest foreach ($array as $r) { $data[] = [ 'accepted_composition' => $r, - 'on_date' => DateTime::createFromFormat('Y-m-d', '2022-05-01'), + 'on_date' => new RollingDate(RollingDate::T_TODAY), ]; } return $data; } - public function getQueryBuilders(): array + public function getQueryBuilders(): iterable { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); + $qb = $em->createQueryBuilder(); + $qb + ->from(Household::class, 'household') + ->join('household.members', 'hmember') + ->join('hmember.person', 'person') + ->join('person.accompanyingPeriodParticipations', 'acppart') + ->join('acppart.accompanyingPeriod', 'acp') + ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') + ->andWhere('hmember.startDate <= :count_household_at_date AND (hmember.endDate IS NULL OR hmember.endDate > :count_household_at_date)') + ->setParameter('count_household_at_date', new \DateTimeImmutable('today')); - return [ - $em->createQueryBuilder() - ->select('h.id') - ->from(Household::class, 'h'), - ]; + $qb + ->select('COUNT(DISTINCT household.id) AS household_export_result') + ->addSelect('COUNT(DISTINCT acp.id) AS acp_export_result'); + + yield $qb; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/AgeFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/AgeFilterTest.php index 789a72956..243b94a2e 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/AgeFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/AgeFilterTest.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\PersonFilters; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Export\Filter\PersonFilters\AgeFilter; @@ -43,28 +44,21 @@ final class AgeFilterTest extends AbstractFilterTest [ 'min_age' => '18', 'max_age' => '60', - 'date_calc' => DateTime::createFromFormat('Y-m-d', '2020-05-01'), - ], - [ // ça devrait faire boum ! - 'min_age' => '35', - 'max_age' => '30', - 'date_calc' => DateTime::createFromFormat('Y-m-d', '2020-05-01'), + 'date_calc' => new RollingDate(RollingDate::T_TODAY), ], ]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() - ->select('p.id') - ->from(Person::class, 'p'), + ->select('person.id') + ->from(Person::class, 'person'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/BirthdateFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/BirthdateFilterTest.php index 6c0c44774..25723f7ee 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/BirthdateFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/BirthdateFilterTest.php @@ -11,9 +11,12 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\PersonFilters; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Export\Filter\PersonFilters\BirthdateFilter; use DateTime; +use Doctrine\ORM\EntityManagerInterface; /** * @internal @@ -39,35 +42,28 @@ final class BirthdateFilterTest extends AbstractFilterTest { return [ [ - 'date_from' => DateTime::createFromFormat('Y-m-d', '2000-01-01'), - 'date_to' => DateTime::createFromFormat('Y-m-d', '2010-01-01'), + 'date_from' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), + 'date_to' => new RollingDate(RollingDate::T_TODAY), ], ]; } public function getQueryBuilders() { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container - ->get('doctrine.orm.entity_manager'); + ->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() - ->select('p.firstName') - ->from('ChillPersonBundle:Person', 'p'), + ->select('person.firstName') + ->from(Person::class, 'person'), $em->createQueryBuilder() - ->select('p.firstName') - ->from('ChillPersonBundle:Person', 'p') + ->select('count(DISTINCT person)') + ->from(Person::class, 'person') // add a dummy where clause - ->where('p.firstname IS NOT NULL'), - $em->createQueryBuilder() - ->select('count(IDENTITY(p))') - ->from('ChillPersonBundle:Person', 'p') - // add a dummy where clause - ->where('p.firstname IS NOT NULL'), + ->where('person.firstName IS NOT NULL'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/DeadOrAliveFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/DeadOrAliveFilterTest.php index 4134662ff..27b06b19f 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/DeadOrAliveFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/DeadOrAliveFilterTest.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\PersonFilters; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Export\Filter\PersonFilters\DeadOrAliveFilter; @@ -42,27 +43,25 @@ final class DeadOrAliveFilterTest extends AbstractFilterTest return [ [ 'person_state' => 'alive', - 'date_calc' => DateTime::createFromFormat('Y-m-d', '2021-05-01'), + 'date_calc' => new RollingDate(RollingDate::T_TODAY), ], [ 'person_state' => 'deceased', - 'date_calc' => DateTime::createFromFormat('Y-m-d', '2021-05-01'), + 'date_calc' => new RollingDate(RollingDate::T_TODAY), ], ]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() - ->select('p.id') - ->from(Person::class, 'p'), + ->select('person.id') + ->from(Person::class, 'person'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/DeathdateFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/DeathdateFilterTest.php index 804639608..9f2cce4f1 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/DeathdateFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/DeathdateFilterTest.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\PersonFilters; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Export\Filter\PersonFilters\DeathdateFilter; @@ -41,24 +42,22 @@ final class DeathdateFilterTest extends AbstractFilterTest { return [ [ - 'date_from' => DateTime::createFromFormat('Y-m-d', '2020-05-01'), - 'date_to' => DateTime::createFromFormat('Y-m-d', '2022-05-01'), + 'date_from' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), + 'date_to' => new RollingDate(RollingDate::T_TODAY), ], ]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() - ->select('p.id') - ->from(Person::class, 'p'), + ->select('person.id') + ->from(Person::class, 'person'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/GenderFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/GenderFilterTest.php index 15da064b8..04ea4a997 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/GenderFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/GenderFilterTest.php @@ -14,6 +14,7 @@ namespace Chill\PersonBundle\Tests\Export\Filter\PersonFilters; use Chill\MainBundle\Test\Export\AbstractFilterTest; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Export\Filter\PersonFilters\GenderFilter; +use Doctrine\ORM\EntityManagerInterface; /** * @internal @@ -52,17 +53,15 @@ final class GenderFilterTest extends AbstractFilterTest public function getQueryBuilders() { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container - ->get('doctrine.orm.entity_manager'); + ->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() - ->select('p.firstName') - ->from('ChillPersonBundle:Person', 'p'), + ->select('person.firstName') + ->from(Person::class, 'person') ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/MaritalStatusFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/MaritalStatusFilterTest.php index f8f530fe9..06d2fcdc4 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/MaritalStatusFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/MaritalStatusFilterTest.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\PersonFilters; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; use Chill\PersonBundle\Entity\MaritalStatus; use Chill\PersonBundle\Entity\Person; @@ -40,12 +41,14 @@ final class MaritalStatusFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(MaritalStatus::class, 'm') ->select('m') ->getQuery() + ->setMaxResults(1) ->getResult(); $data = []; @@ -53,7 +56,6 @@ final class MaritalStatusFilterTest extends AbstractFilterTest foreach ($array as $m) { $data[] = [ 'maritalStatus' => $m, - 'calc_date' => DateTime::createFromFormat('Y-m-d', '2022-05-01'), ]; } @@ -62,16 +64,14 @@ final class MaritalStatusFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() - ->select('p.id') - ->from(Person::class, 'p'), + ->select('count(person)') + ->from(Person::class, 'person'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/NationalityFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/NationalityFilterTest.php index 2fcf22887..565c75280 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/NationalityFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/NationalityFilterTest.php @@ -39,9 +39,10 @@ final class NationalityFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); - $countries = $em->getRepository(Country::class)->findAll(); + $countries = array_slice($em->getRepository(Country::class)->findAll(), 0, 1); $data = []; @@ -56,16 +57,14 @@ final class NationalityFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() - ->select('p.id') - ->from(Person::class, 'p'), + ->select('count(person)') + ->from(Person::class, 'person'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilterTest.php index 52c08c63c..6d1b2c398 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilterTest.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\PersonFilters; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person\ResidentialAddress; @@ -42,20 +43,22 @@ final class ResidentialAddressAtThirdpartyFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); $array = $em->createQueryBuilder() ->from(ThirdPartyCategory::class, 'tpc') ->select('tpc') ->getQuery() + ->setMaxResults(1) ->getResult(); $data = []; foreach ($array as $r) { $data[] = [ - 'thirdparty_cat' => $r, - 'date_calc' => DateTime::createFromFormat('Y-m-d', '2022-05-01'), + 'thirdparty_cat' => [$r], + 'date_calc' => new RollingDate(RollingDate::T_TODAY), ]; } @@ -64,18 +67,15 @@ final class ResidentialAddressAtThirdpartyFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() - ->select('p.id') - ->from(Person::class, 'p') - ->join(ResidentialAddress::class, 'resaddr', Expr\Join::WITH, 'resaddr.person = p') - ->join('p.center', 'center') + ->select('person.id') + ->from(Person::class, 'person') + ->join(ResidentialAddress::class, 'resaddr', Expr\Join::WITH, 'resaddr.person = person') ->join('resaddr.hostThirdParty', 'tparty') ->join('tparty.categories', 'tpartycat'), ]; diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/ResidentialAddressAtUserFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/ResidentialAddressAtUserFilterTest.php index 77b46a7e1..c357f7a65 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/ResidentialAddressAtUserFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/ResidentialAddressAtUserFilterTest.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\PersonFilters; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Export\Filter\PersonFilters\ResidentialAddressAtUserFilter; @@ -39,14 +40,14 @@ final class ResidentialAddressAtUserFilterTest extends AbstractFilterTest public function getFormData(): array { - return []; + return [ + ['date_calc' => new RollingDate(RollingDate::T_TODAY)] + ]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/JobFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/JobFilterTest.php index 481032d0b..890222b5b 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/JobFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/JobFilterTest.php @@ -11,8 +11,11 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\SocialWorkFilters; +use Chill\MainBundle\Entity\UserJob; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; use Chill\PersonBundle\Export\Filter\SocialWorkFilters\JobFilter; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManagerInterface; /** @@ -37,21 +40,30 @@ final class JobFilterTest extends AbstractFilterTest public function getFormData(): array { - return []; + self::bootKernel(); + $em = self::$container->get(EntityManagerInterface::class); + + $jobs = $em->createQuery('SELECT j FROM ' . UserJob::class . ' j') + ->setMaxResults(1) + ->getResult(); + + return [ + [ + 'job' => new ArrayCollection($jobs) + ] + ]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() ->select('acpw.id') - ->from('ChillPersonBundle:AccompanyingPeriodWork', 'acpw'), + ->from(AccompanyingPeriodWork::class, 'acpw'), ]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/ReferrerFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/ReferrerFilterTest.php index b7b07c9e1..68fab1250 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/ReferrerFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/ReferrerFilterTest.php @@ -39,9 +39,10 @@ final class ReferrerFilterTest extends AbstractFilterTest public function getFormData(): array { + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); - $users = $em->getRepository(User::class)->findAll(); + $users = array_slice($em->getRepository(User::class)->findAll(), 0, 1); $data = []; @@ -56,9 +57,7 @@ final class ReferrerFilterTest extends AbstractFilterTest public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/ScopeFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/ScopeFilterTest.php index 47af12d34..1ff6c6d6e 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/ScopeFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/ScopeFilterTest.php @@ -11,7 +11,9 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Filter\SocialWorkFilters; +use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Test\Export\AbstractFilterTest; +use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; use Chill\PersonBundle\Export\Filter\SocialWorkFilters\ScopeFilter; use Doctrine\ORM\EntityManagerInterface; @@ -37,21 +39,30 @@ final class ScopeFilterTest extends AbstractFilterTest public function getFormData(): array { - return []; + self::bootKernel(); + $em = self::$container->get(EntityManagerInterface::class); + + $scopes = $em->createQuery('SELECT s FROM ' . Scope::class . ' s') + ->setMaxResults(1) + ->getResult(); + + return [ + [ + 'scope' => $scopes + ] + ]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); return [ $em->createQueryBuilder() ->select('acpw.id') - ->from('ChillPersonBundle:AccompanyingPeriodWork', 'acpw'), + ->from(AccompanyingPeriodWork::class, 'acpw'), ]; } } diff --git a/src/Bundle/ChillReportBundle/Tests/Export/Filter/ReportDateFilterTest.php b/src/Bundle/ChillReportBundle/Tests/Export/Filter/ReportDateFilterTest.php index 5076c861c..8ddc1357e 100644 --- a/src/Bundle/ChillReportBundle/Tests/Export/Filter/ReportDateFilterTest.php +++ b/src/Bundle/ChillReportBundle/Tests/Export/Filter/ReportDateFilterTest.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\ReportBundle\Tests\Export\Filter; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractFilterTest; use Chill\ReportBundle\Entity\Report; use Chill\ReportBundle\Export\Filter\ReportDateFilter; @@ -29,7 +30,7 @@ final class ReportDateFilterTest extends AbstractFilterTest { self::bootKernel(); - $this->filter = self::$container->get('chill.report.export.filter_date'); + $this->filter = self::$container->get(ReportDateFilter::class); } public function getFilter() @@ -41,17 +42,15 @@ final class ReportDateFilterTest extends AbstractFilterTest { return [ [ - 'date_from' => DateTime::createFromFormat('Y-m-d', '2021-07-01'), - 'date_to' => DateTime::createFromFormat('Y-m-d', '2022-07-01'), + 'date_from' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), + 'date_to' => new RollingDate(RollingDate::T_TODAY), ], ]; } public function getQueryBuilders(): array { - if (null === self::$kernel) { - self::bootKernel(); - } + self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); diff --git a/src/Bundle/ChillReportBundle/translations/messages.fr.yml b/src/Bundle/ChillReportBundle/translations/messages.fr.yml index 69b0ea60e..b39f8d079 100644 --- a/src/Bundle/ChillReportBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillReportBundle/translations/messages.fr.yml @@ -53,3 +53,4 @@ CHILL_REPORT_LISTS: Liste des rapports Filter by report's date: Filtrer par date de rapport Report is after this date: Rapports après cette date Report is before this date: Rapports avant cette date +"Filtered by report's date: between %date_from% and %date_to%": "Filtré par date du rapport: entre le %date_from% et le %date_to%"