feat: move prepopulation guards into participant service

This commit is contained in:
Björn Fromme
2026-04-11 18:28:32 +02:00
parent dbc0b4acee
commit 63e8a068b3
9 changed files with 114 additions and 289 deletions
@@ -12,7 +12,6 @@ use App\Form\Model\ParticipantDto;
use App\Form\Model\RoomSelectionDto;
use App\Service\BookingParticipantCountService;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\User\UserInterface;
class BookingParticipantCountServiceTest extends TestCase
{
@@ -44,31 +43,6 @@ class BookingParticipantCountServiceTest extends TestCase
$this->assertSame(7, $bookingDto->participants[7]->index);
}
public function testEnsureCorrectNumberOfParticipantsPrepopulatesFreshApplicant(): void
{
$travel = $this->createTravel([1 => 2]);
$bookingDto = new BookingDto($travel, 123);
$bookingDto->roomSelections = [$this->createRoomSelection(1, 1)];
$bookingDto->participants = [new ParticipantDto()];
$user = $this->createMock(UserInterface::class);
$callbackCalled = false;
$this->service->ensureCorrectNumberOfParticipants(
$bookingDto,
$user,
function (UserInterface $userArg, ParticipantDto $participant) use (&$callbackCalled): ParticipantDto {
$callbackCalled = true;
$participant->firstName = 'Alex';
return $participant;
}
);
$this->assertTrue($callbackCalled);
$this->assertSame('Alex', $bookingDto->participants[0]->firstName);
}
private function createTravel(array $roomCapacities): Travel
{
$travel = new Travel();
@@ -10,9 +10,11 @@ use App\BusProNet\Model\Communication;
use App\BusProNet\Model\Notification;
use App\BusProNet\Model\PersonalData;
use App\Entity\User;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Security\Crypt;
use App\Service\ParticipantPrepopulationService;
use Carbon\CarbonImmutable;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
@@ -240,6 +242,44 @@ class ParticipantPrepopulationServiceTest extends TestCase
$this->assertTrue($result->bulkInsuranceBooking);
}
public function testShouldPrepopulateApplicantOnlyWhenFresh(): void
{
$fresh = new ParticipantDto();
$fresh->firstName = '';
$filled = new ParticipantDto();
$filled->firstName = 'Already set';
$this->assertTrue($this->service->shouldPrepopulateApplicant($fresh));
$this->assertFalse($this->service->shouldPrepopulateApplicant($filled));
}
public function testDummyTokenMatchesOnlyInCreateMode(): void
{
$participant = new ParticipantDto();
$participant->lastName = ParticipantPrepopulationService::TOKEN;
$this->assertTrue($this->service->isDummyDataFillRequested($participant, BookingDto::MODE_CREATE));
$this->assertFalse($this->service->isDummyDataFillRequested($participant, BookingDto::MODE_EDIT));
}
public function testFillDummyParticipantSetsGeneratedData(): void
{
CarbonImmutable::setTestNow(CarbonImmutable::create(2026, 1, 15, 14, 30));
$participant = new ParticipantDto();
$this->service->fillDummyParticipant($participant, 0);
$this->assertSame('Vorname 1', $participant->firstName);
$this->assertSame('Muster 1 14:30', $participant->lastName);
$this->assertSame('0171/111111', $participant->mobile);
$this->assertSame('[email protected]', $participant->email);
$this->assertSame('2006-01-15', $participant->dateOfBirth?->format('Y-m-d'));
$this->assertSame('Musterstr. 123', $participant->address?->street);
CarbonImmutable::setTestNow();
}
private function createUser(string $email, string $encryptedPassword): User
{
$user = new User($email);