em = self::getContainer()->get(EntityManagerInterface::class); $this->connection = self::getContainer()->get(Connection::class); } public function testCountByAccompanyingPeriod(): void { $period = $this->em->createQuery('SELECT a FROM '.AccompanyingPeriod::class.' a') ->setMaxResults(1) ->getSingleResult(); if (null === $period) { throw new \UnexpectedValueException('period not found'); } $manager = new Manager( [new SimpleGenericDocAccompanyingPeriodProvider()], [new SimpleGenericDocPersonProvider()], $this->connection, ); $nb = $manager->countDocForAccompanyingPeriod($period); self::assertIsInt($nb); } public function testCountByPerson(): void { $person = $this->em->createQuery('SELECT a FROM '.Person::class.' a') ->setMaxResults(1) ->getSingleResult(); if (null === $person) { throw new \UnexpectedValueException('person found'); } $manager = new Manager( [new SimpleGenericDocAccompanyingPeriodProvider()], [new SimpleGenericDocPersonProvider()], $this->connection, ); $nb = $manager->countDocForPerson($person); self::assertIsInt($nb); } public function testFindDocByAccompanyingPeriod(): void { $period = $this->em->createQuery('SELECT a FROM '.AccompanyingPeriod::class.' a') ->setMaxResults(1) ->getSingleResult(); if (null === $period) { throw new \UnexpectedValueException('period not found'); } $manager = new Manager( [new SimpleGenericDocAccompanyingPeriodProvider()], [new SimpleGenericDocPersonProvider()], $this->connection, ); foreach ($manager->findDocForAccompanyingPeriod($period) as $doc) { self::assertInstanceOf(GenericDocDTO::class, $doc); } } public function testFindDocByPerson(): void { $person = $this->em->createQuery('SELECT a FROM '.Person::class.' a') ->setMaxResults(1) ->getSingleResult(); if (null === $person) { throw new \UnexpectedValueException('person not found'); } $manager = new Manager( [new SimpleGenericDocAccompanyingPeriodProvider()], [new SimpleGenericDocPersonProvider()], $this->connection, ); foreach ($manager->findDocForPerson($person) as $doc) { self::assertInstanceOf(GenericDocDTO::class, $doc); } } public function testPlacesForPerson(): void { $person = $this->em->createQuery('SELECT a FROM '.Person::class.' a') ->setMaxResults(1) ->getSingleResult(); if (null === $person) { throw new \UnexpectedValueException('person not found'); } $manager = new Manager( [new SimpleGenericDocAccompanyingPeriodProvider()], [new SimpleGenericDocPersonProvider()], $this->connection, ); $places = $manager->placesForPerson($person); self::assertEquals(['dummy_person_doc'], $places); } public function testPlacesForAccompanyingPeriod(): void { $period = $this->em->createQuery('SELECT a FROM '.AccompanyingPeriod::class.' a') ->setMaxResults(1) ->getSingleResult(); if (null === $period) { throw new \UnexpectedValueException('period not found'); } $manager = new Manager( [new SimpleGenericDocAccompanyingPeriodProvider()], [new SimpleGenericDocPersonProvider()], $this->connection, ); $places = $manager->placesForAccompanyingPeriod($period); self::assertEquals(['accompanying_course_document_dummy'], $places); } } final readonly class SimpleGenericDocAccompanyingPeriodProvider implements GenericDocForAccompanyingPeriodProviderInterface { public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface { $query = new FetchQuery( 'accompanying_course_document_dummy', sprintf('jsonb_build_object(\'id\', %s)', 'id'), 'd', '(VALUES (1, \'2023-05-01\'::date), (2, \'2023-05-01\'::date)) AS sq (id, d)', ); $query->addWhereClause('d > ?', [new \DateTimeImmutable('2023-01-01')], [Types::DATE_IMMUTABLE]); return $query; } public function isAllowedForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): bool { return true; } } final readonly class SimpleGenericDocPersonProvider implements GenericDocForPersonProviderInterface { public function buildFetchQueryForPerson(Person $person, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface { $query = new FetchQuery( 'dummy_person_doc', sprintf('jsonb_build_object(\'id\', %s)', 'id'), 'd', '(VALUES (1, \'2023-05-01\'::date), (2, \'2023-05-01\'::date)) AS sq (id, d)', ); $query->addWhereClause('d > ?', [new \DateTimeImmutable('2023-01-01')], [Types::DATE_IMMUTABLE]); return $query; } public function isAllowedForPerson(Person $person): bool { return true; } }