dateFrom = new \DateTimeImmutable('2030-01-01'); $travel->dateTo = new \DateTimeImmutable('2030-01-06'); $bookingDto = new BookingDto($travel, 157047); $travelDataService = $this->createMock(TravelDataProvider::class); $travelDataService->expects($this->once()) ->method('enrichWithFreshAvailabilities') ->with($travel); $service = new BookingEditContextFactory( $this->createMock(ParticipantCardAssembler::class), $this->createMock(BookingSummaryAssembler::class), $travelDataService, ); $service->prepareBookingDto($bookingDto); } public function testCreateBuildsEditContext(): void { $travel = new Travel(); $travel->dateFrom = new \DateTimeImmutable('2030-01-01'); $travel->dateTo = new \DateTimeImmutable('2030-01-06'); $bookingDto = new BookingDto($travel, 157047); $bookingDto->booking = new Booking(); $bookingData = new Booking(); $bookingData->dateId = 1234; $mutableData = new BaseData([ MutableData::CATEGORY_ADDITIONAL_SERVICES => new MutableData(MutableData::CATEGORY_ADDITIONAL_SERVICES, true, new \DateTimeImmutable('2030-01-02')), ]); $summaryData = $this->createMock(BookingSummaryDto::class); $summaryDataService = $this->createMock(BookingSummaryAssembler::class); $summaryDataService->expects($this->once()) ->method('getSummaryData') ->with($bookingDto) ->willReturn($summaryData); $travelDataService = $this->createMock(TravelDataProvider::class); $travelDataService->expects($this->once()) ->method('getMutabilityData') ->with(1234) ->willReturn($mutableData); $service = new BookingEditContextFactory( $this->createMock(ParticipantCardAssembler::class), $summaryDataService, $travelDataService, ); $context = $service->createParticipantContext($bookingDto, $bookingData); $this->assertInstanceOf(BookingEditContext::class, $context); $this->assertSame($bookingDto, $context->bookingDto); $this->assertSame($bookingData, $context->bookingData); $this->assertInstanceOf(BookingMutabilityDto::class, $context->mutableData); $this->assertSame($mutableData->getItemByKey(MutableData::CATEGORY_ADDITIONAL_SERVICES), $context->mutableData->additionalServices); $this->assertNull($context->mutableData->transportation); $this->assertSame($summaryData, $context->summaryData); } public function testCreateParticipantContextWithoutBookingDataFallsBackToSummaryOnly(): void { $travel = new Travel(); $travel->dateFrom = new \DateTimeImmutable('2030-01-01'); $travel->dateTo = new \DateTimeImmutable('2030-01-06'); $bookingDto = new BookingDto($travel, 157047); $summaryData = $this->createMock(BookingSummaryDto::class); $summaryDataService = $this->createMock(BookingSummaryAssembler::class); $summaryDataService->expects($this->once()) ->method('getSummaryData') ->with($bookingDto) ->willReturn($summaryData); $travelDataService = $this->createMock(TravelDataProvider::class); $travelDataService->expects($this->never()) ->method('getMutabilityData'); $service = new BookingEditContextFactory( $this->createMock(ParticipantCardAssembler::class), $summaryDataService, $travelDataService, ); $context = $service->createParticipantContext($bookingDto, null); $this->assertInstanceOf(BookingEditContext::class, $context); $this->assertSame($bookingDto, $context->bookingDto); $this->assertNull($context->bookingData); $this->assertNull($context->mutableData); $this->assertSame($summaryData, $context->summaryData); } public function testCreateOverviewContextBuildsEditOverviewPayload(): void { $travel = new Travel(); $travel->dateFrom = new \DateTimeImmutable('2030-01-01'); $travel->dateTo = new \DateTimeImmutable('2030-01-06'); $bookingDto = new BookingDto($travel, 157047); $bookingData = new Booking(); $bookingData->dateId = 1234; $mutableData = new BaseData([]); $summaryData = $this->createMock(BookingSummaryDto::class); $cardsData = []; $participantCardDataService = $this->createMock(ParticipantCardAssembler::class); $participantCardDataService->expects($this->once()) ->method('getAllCardsDataWithValidation') ->with($bookingDto) ->willReturn($cardsData); $summaryDataService = $this->createMock(BookingSummaryAssembler::class); $summaryDataService->expects($this->once()) ->method('getSummaryData') ->with($bookingDto) ->willReturn($summaryData); $travelDataService = $this->createMock(TravelDataProvider::class); $travelDataService->expects($this->once()) ->method('getMutabilityData') ->with(1234) ->willReturn($mutableData); $service = new BookingEditContextFactory( $participantCardDataService, $summaryDataService, $travelDataService, ); $context = $service->createOverviewContext($bookingDto, $bookingData, true, false, true); $this->assertInstanceOf(BookingEditContext::class, $context); $this->assertSame($cardsData, $context->cardsData); $this->assertTrue($context->isDirty); $this->assertFalse($context->isSubmitted); $this->assertTrue($context->hasValidationErrors); } }