fix: normalize non-numeric body dimension values of existing drafts

This commit is contained in:
Björn Fromme
2026-05-28 15:35:34 +02:00
parent 02b1cbfd6c
commit ee8c6a6545
5 changed files with 148 additions and 0 deletions
+24
View File
@@ -6,6 +6,7 @@ namespace App\Tests\Form\Model;
use App\BusProNet\Model\Travel;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use PHPUnit\Framework\TestCase;
/**
@@ -63,4 +64,27 @@ class BookingDtoTest extends TestCase
$this->assertSame($travel, $dto->travel);
$this->assertSame(42, $dto->travel->id);
}
public function testUnserializeNormalizesLegacyBodyDimensionsOnParticipants(): void
{
$travel = new Travel();
$travel->id = 42;
$travel->dateFrom = new \DateTimeImmutable('2025-06-01');
$travel->dateTo = new \DateTimeImmutable('2025-06-08');
$participant = new ParticipantDto();
$participant->height = '149-157';
$participant->weight = '75';
$participant->shoeSize = '043';
$dto = new BookingDto($travel, 1);
$dto->participants = [$participant];
$restored = unserialize(serialize($dto));
$this->assertInstanceOf(BookingDto::class, $restored);
$this->assertNull($restored->participants[0]->height);
$this->assertSame('75', $restored->participants[0]->weight);
$this->assertSame('43', $restored->participants[0]->shoeSize);
}
}
@@ -422,6 +422,66 @@ class BookingEditDraftManagerMutabilityTest extends TestCase
$this->assertSame('Updated', $mutableParticipant->firstName);
}
public function testDraftNormalizesLegacyBodyDimensionsToNull(): void
{
$participant = new ParticipantDto();
$participant->height = null;
$participant->weight = null;
$participant->shoeSize = null;
$travel = $this->createTravel();
$dto = $this->createBookingDto($travel, [$participant]);
$draft = $this->createDraft([
'participants' => [
0 => [
'bodyDimensions' => [
'height' => '149-157',
'weight' => '195+',
'shoeSize' => 'abc',
],
],
],
]);
$applied = $this->service->applyDraftToDto($draft, $dto, $travel);
$this->assertTrue($applied);
$this->assertNull($participant->height);
$this->assertNull($participant->weight);
$this->assertNull($participant->shoeSize);
}
public function testDraftNormalizesNumericBodyDimensionsToCanonicalStrings(): void
{
$participant = new ParticipantDto();
$participant->height = null;
$participant->weight = null;
$participant->shoeSize = null;
$travel = $this->createTravel();
$dto = $this->createBookingDto($travel, [$participant]);
$draft = $this->createDraft([
'participants' => [
0 => [
'bodyDimensions' => [
'height' => '180',
'weight' => '75',
'shoeSize' => '043',
],
],
],
]);
$applied = $this->service->applyDraftToDto($draft, $dto, $travel);
$this->assertTrue($applied);
$this->assertSame('180', $participant->height);
$this->assertSame('75', $participant->weight);
$this->assertSame('43', $participant->shoeSize);
}
// --- Helpers ---
private function createService(int $id, string $label = 'Test', bool $isTransportation = false): Service