entityManager = self::$container->get(EntityManagerInterface::class); $this->centerResolverManager = self::$container->get(CenterResolverManagerInterface::class); $this->authorizationHelperForCurrentUser = self::$container->get(AuthorizationHelperForCurrentUserInterface::class); $this->security = self::$container->get(Security::class); } /** * @dataProvider provideDataForPerson */ public function testBuildFetchQueryActivityDocumentLinkedToPersonFromPersonContext(Person $person, array $reachableScopes, bool $_unused, ?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate, ?string $content): void { $authorizationHelper = $this->prophesize(AuthorizationHelperForCurrentUserInterface::class); $authorizationHelper->getReachableScopes(ActivityVoter::SEE, Argument::any()) ->willReturn($reachableScopes); $repository = new ActivityDocumentACLAwareRepository( $this->entityManager, $this->centerResolverManager, $authorizationHelper->reveal(), $this->security ); $query = $repository->buildFetchQueryActivityDocumentLinkedToPersonFromPersonContext($person, $startDate, $endDate, $content); ['sql' => $sql, 'params' => $params, 'types' => $types] = (new FetchQueryToSqlBuilder())->toSql($query); $nb = $this->entityManager->getConnection()->fetchOne("SELECT COUNT(*) FROM ({$sql}) sq", $params, $types); self::assertIsInt($nb); } /** * @dataProvider provideDataForPerson */ public function testBuildFetchQueryActivityDocumentLinkedToAccompanyingPeriodFromPersonContext(Person $person, array $_unused, bool $canSeePeriod, ?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate, ?string $content): void { $security = $this->prophesize(Security::class); $security->isGranted(ActivityVoter::SEE, Argument::type(AccompanyingPeriod::class)) ->willReturn($canSeePeriod); $repository = new ActivityDocumentACLAwareRepository( $this->entityManager, $this->centerResolverManager, $this->authorizationHelperForCurrentUser, $security->reveal() ); $query = $repository->buildFetchQueryActivityDocumentLinkedToAccompanyingPeriodFromPersonContext($person, $startDate, $endDate, $content); ['sql' => $sql, 'params' => $params, 'types' => $types] = (new FetchQueryToSqlBuilder())->toSql($query); $nb = $this->entityManager->getConnection()->fetchOne("SELECT COUNT(*) FROM ({$sql}) sq", $params, $types); self::assertIsInt($nb); } public function provideDataForPerson(): iterable { $this->setUp(); if (null === $person = $this->entityManager->createQuery("SELECT p FROM " . Person::class . " p WHERE SIZE(p.accompanyingPeriodParticipations) > 0 ") ->setMaxResults(1) ->getSingleResult()) { throw new \RuntimeException("no person in dtabase"); } if ([] === $scopes = $this->entityManager->createQuery("SELECT s FROM " . Scope::class . " s ")->setMaxResults(5)->getResult()) { throw new \RuntimeException("no scopes in database"); } yield [$person, [], true, null, null, null]; yield [$person, $scopes, true, null, null, null]; yield [$person, $scopes, true, new \DateTimeImmutable("1 month ago"), null, null]; yield [$person, $scopes, true, new \DateTimeImmutable("1 month ago"), new \DateTimeImmutable("1 week ago"), null]; yield [$person, $scopes, true, new \DateTimeImmutable("1 month ago"), new \DateTimeImmutable("1 week ago"), "content"]; yield [$person, $scopes, true, null, new \DateTimeImmutable("1 week ago"), "content"]; yield [$person, [], true, new \DateTimeImmutable("1 month ago"), new \DateTimeImmutable("1 week ago"), "content"]; } }