entityManager = self::getContainer()->get(EntityManagerInterface::class); } /** * @dataProvider provideSearchArguments */ public function testWithoutAnyArgument(?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate, ?string $content = null): void { $period = $this->entityManager->createQuery('SELECT a FROM '.AccompanyingPeriod::class.' a') ->setMaxResults(1) ->getSingleResult(); if (null === $period) { throw new \UnexpectedValueException('period not found'); } $security = $this->prophesize(Security::class); $security->isGranted(AccompanyingCourseDocumentVoter::SEE, $period) ->willReturn(true); $provider = new AccompanyingCourseDocumentGenericDocProvider( $security->reveal(), $this->entityManager, $this->prophesize(AccompanyingCourseDocumentRepository::class)->reveal() ); $query = $provider->buildFetchQueryForAccompanyingPeriod($period, $startDate, $endDate, $content); ['sql' => $sql, 'params' => $params, 'types' => $types] = (new FetchQueryToSqlBuilder())->toSql($query); $nb = $this->entityManager->getConnection()->executeQuery('SELECT COUNT(*) FROM ('.$sql.') AS sq', $params, $types) ->fetchOne(); self::assertIsInt($nb); } public static function provideSearchArguments(): iterable { yield [null, null, null]; yield [new \DateTimeImmutable('1 month ago'), null, null]; yield [new \DateTimeImmutable('1 month ago'), new \DateTimeImmutable('now'), null]; yield [null, null, 'test']; } }