getRepository()->getListQuery((new TeamerFilterDto())->setAllSeason(true)); $this->assertStringContainsString('teamer.allSeason = :allSeason', $query->getDQL()); $this->assertTrue($query->getParameter('allSeason')->getValue()); } public function testTheGeneralListIsNotRestricted(): void { $query = $this->getRepository()->getListQuery(new TeamerFilterDto()); $this->assertStringNotContainsString('teamer.allSeason', $query->getDQL()); $this->assertNull($query->getParameter('allSeason')); } /** * The mailing resolves its recipients through the same builder, so a mailing started from * the all-season list must not be able to reach the rest of the team. */ public function testTheMailingRecipientsCarryTheSameScope(): void { $repository = $this->getRepository(); $reflection = new \ReflectionMethod($repository, 'createListQueryBuilder'); $queryBuilder = $reflection->invoke($repository, (new TeamerFilterDto())->setAllSeason(true)); $this->assertStringContainsString('teamer.allSeason = :allSeason', $queryBuilder->getDQL()); } /** * The season assignment form picks its teamer through this endpoint, so an unrestricted * suggestion list would let an admin place a short term teamer on a season assignment. */ public function testTheAutocompleteCanBeRestrictedToAllSeasonTeamers(): void { $dql = $this->createAutocompletionQueryBuilder(true)->getDQL(); $this->assertStringContainsString('teamer.allSeason = :allSeason', $dql); } public function testTheAutocompleteIsUnrestrictedByDefault(): void { $dql = $this->createAutocompletionQueryBuilder(false)->getDQL(); $this->assertStringNotContainsString('teamer.allSeason', $dql); $this->assertStringContainsString('teamer.deletedAt IS NULL', $dql); } private function createAutocompletionQueryBuilder(bool $allSeasonOnly): QueryBuilder { $repository = $this->getRepository(); $reflection = new \ReflectionMethod($repository, 'createAutocompletionQueryBuilder'); return $reflection->invoke($repository, '', $allSeasonOnly); } private function getRepository(): TeamerRepository { self::bootKernel(); return self::getContainer()->get(TeamerRepository::class); } }