assertSame(VoterInterface::ACCESS_GRANTED, $this->vote($this->travel('yesterday'))); } /** * @return iterable}> */ public static function deniedCases(): iterable { yield 'travel not ended' => [self::travel('tomorrow')]; yield 'travel ended before the go-live' => [self::travel('2025-12-31')]; yield 'travel deleted' => [self::travel('yesterday')->setDeletedAt(new \DateTimeImmutable())]; yield 'nobody worked on the travel' => [self::travel('yesterday'), true, false]; yield 'not a house manager' => [self::travel('yesterday'), false]; yield 'house manager of another house' => [self::travel('yesterday'), true, true, ['AGR']]; } /** * @param list $hotelCodes */ #[DataProvider('deniedCases')] public function testDenied(Destination $destination, bool $houseManager = true, bool $placements = true, array $hotelCodes = ['DKI']): void { $this->assertSame(VoterInterface::ACCESS_DENIED, $this->vote($destination, $houseManager, $placements, $hotelCodes)); } public function testOtherAttributesAndSubjectsAreNotVotedOn(): void { $voter = new DestinationVoter($this->createStub(Security::class), $this->createStub(DispositionRepository::class), self::GO_LIVE); $token = $this->createStub(TokenInterface::class); $this->assertSame(VoterInterface::ACCESS_ABSTAIN, $voter->vote($token, $this->travel('yesterday'), ['EDIT'])); $this->assertSame(VoterInterface::ACCESS_ABSTAIN, $voter->vote($token, new \stdClass(), [DestinationVoter::QUESTIONNAIRE])); } private static function travel(string $dateTo): Destination { return (new Destination()) ->setHotelCode('DKI') ->setDateFrom(new \DateTimeImmutable($dateTo)->modify('-7 days')) ->setDateTo(new \DateTimeImmutable($dateTo)->setTime(0, 0)) ; } /** * @param list $hotelCodes */ private function vote(Destination $destination, bool $houseManager = true, bool $placements = true, array $hotelCodes = ['DKI']): int { $security = $this->createStub(Security::class); $security->method('isGranted')->willReturn($houseManager); $repository = $this->createStub(DispositionRepository::class); $repository->method('findForHouseManagerQuestionnaire')->willReturn($placements ? [$this->createStub(Disposition::class)] : []); $token = $this->createStub(TokenInterface::class); $token->method('getUser')->willReturn((new User())->setHotelCodes($hotelCodes)); return new DestinationVoter($security, $repository, self::GO_LIVE)->vote($token, $destination, [DestinationVoter::QUESTIONNAIRE]); } }