feat: replace edit participant facade with context factory

This commit is contained in:
Björn Fromme
2026-04-11 18:28:32 +02:00
parent 95d50e9833
commit f903f17ebd
7 changed files with 169 additions and 190 deletions
@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\Model\BaseData;
use App\BusProNet\Model\Booking;
use App\BusProNet\Model\Travel;
use App\Form\Model\BookingDto;
use App\Form\Model\BookingEditParticipantContext;
use App\Form\Model\BookingSummaryDto;
use App\Service\BookingEditParticipantContextFactory;
use App\Service\BookingSummaryDataService;
use App\Service\TravelDataService;
use PHPUnit\Framework\TestCase;
class BookingEditParticipantContextFactoryTest extends TestCase
{
public function testPrepareBookingDtoRefreshesTravelAvailability(): void
{
$travel = new Travel();
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
$bookingDto = new BookingDto($travel, 157047);
$travelDataService = $this->createMock(TravelDataService::class);
$travelDataService->expects($this->once())
->method('enrichWithFreshAvailabilities')
->with($travel);
$service = new BookingEditParticipantContextFactory(
$this->createMock(BookingSummaryDataService::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([]);
$summaryData = $this->createMock(BookingSummaryDto::class);
$summaryDataService = $this->createMock(BookingSummaryDataService::class);
$summaryDataService->expects($this->once())
->method('getSummaryData')
->with($bookingDto)
->willReturn($summaryData);
$travelDataService = $this->createMock(TravelDataService::class);
$travelDataService->expects($this->once())
->method('getMutabilityData')
->with(1234)
->willReturn($mutableData);
$service = new BookingEditParticipantContextFactory($summaryDataService, $travelDataService);
$context = $service->create($bookingDto, $bookingData);
$this->assertInstanceOf(BookingEditParticipantContext::class, $context);
$this->assertSame($bookingDto, $context->bookingDto);
$this->assertSame($bookingData, $context->bookingData);
$this->assertSame($mutableData, $context->mutableData);
$this->assertSame($summaryData, $context->summaryData);
}
}
@@ -1,94 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\Model\BaseData;
use App\BusProNet\Model\Booking;
use App\BusProNet\Model\Travel;
use App\Form\Model\BookingDto;
use App\Service\BookingEditDataLoaderService;
use App\Service\BookingEditDraftService;
use App\Service\BookingEditParticipantFormService;
use App\Service\BookingSessionService;
use App\Service\BookingSummaryDataService;
use App\Service\TravelDataService;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
class BookingEditParticipantFormServiceTest extends TestCase
{
public function testLoadBookingDtoDelegatesToBookingService(): void
{
$request = new Request();
$bookingDto = $this->createBookingDto();
$bookingSessionService = $this->createMock(BookingSessionService::class);
$bookingSessionService->expects($this->once())
->method('getBookingDto')
->with($request, BookingDto::MODE_EDIT)
->willReturn($bookingDto);
$service = $this->createService(bookingSessionService: $bookingSessionService);
$this->assertSame($bookingDto, $service->loadBookingDto($request));
}
public function testIsParticipantCanceledUsesBookingStatus(): void
{
$service = $this->createService();
$booking = new Booking();
$booking->participantsStatus = [0 => 'S', 1 => 'A'];
$this->assertTrue($service->isParticipantCanceled($booking, 0));
$this->assertFalse($service->isParticipantCanceled($booking, 1));
}
public function testGetMutableDataDelegatesToTravelDataService(): void
{
$mutableData = new BaseData([]);
$travelDataService = $this->createMock(TravelDataService::class);
$travelDataService->expects($this->once())
->method('getMutabilityData')
->with(1234)
->willReturn($mutableData);
$service = new BookingEditParticipantFormService(
$this->createMock(BookingEditDataLoaderService::class),
$this->createMock(BookingEditDraftService::class),
$this->createMock(BookingSessionService::class),
$this->createMock(BookingSummaryDataService::class),
$travelDataService,
);
$this->assertSame($mutableData, $service->getMutableData(1234));
}
private function createService(
?BookingEditDataLoaderService $dataLoader = null,
?BookingEditDraftService $draftService = null,
?BookingSessionService $bookingSessionService = null,
?BookingSummaryDataService $summaryDataService = null,
?TravelDataService $travelDataService = null,
): BookingEditParticipantFormService {
return new BookingEditParticipantFormService(
$dataLoader ?? $this->createMock(BookingEditDataLoaderService::class),
$draftService ?? $this->createMock(BookingEditDraftService::class),
$bookingSessionService ?? $this->createMock(BookingSessionService::class),
$summaryDataService ?? $this->createMock(BookingSummaryDataService::class),
$travelDataService ?? $this->createMock(TravelDataService::class),
);
}
private function createBookingDto(): BookingDto
{
$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();
return $bookingDto;
}
}