Files
myep/tests/Form/Model/AccommodationBookingPeriodDtoTest.php
T
2026-09-30 18:06:20 +02:00

47 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Form\Model;
use App\Entity\Groups\AccommodationBookingPeriod;
use App\Enum\Groups\AccommodationBookingPeriodPosition;
use App\Form\Model\AccommodationBookingPeriodDto;
use App\Form\Model\AccommodationBookingPeriodLineDto;
use PHPUnit\Framework\TestCase;
class AccommodationBookingPeriodDtoTest extends TestCase
{
public function testTheEditModalStartsFromWhatThePeriodHolds(): void
{
$period = (new AccommodationBookingPeriod(
AccommodationBookingPeriodPosition::Leading,
new \DateTimeImmutable('2026-07-01'),
new \DateTimeImmutable('2026-07-03'),
))
->setLabel('Vorausteam')
->setLines([['label' => 'Übernachtung', 'amount' => 25000]]);
$dto = AccommodationBookingPeriodDto::fromPeriod($period);
self::assertSame('Vorausteam', $dto->label);
self::assertSame(2, $dto->nights);
self::assertSame([['label' => 'Übernachtung', 'amount' => 25000]], $dto->linesSnapshot());
}
public function testTheLinesAreStoredAsAListWhateverKeysTheFormSubmitted(): void
{
// A collection form keeps the indexes of the rows it was sent, so after a removed row
// the keys have gaps — the JSON column must still get a list, not an object.
$dto = new AccommodationBookingPeriodDto(1, [
2 => new AccommodationBookingPeriodLineDto('Übernachtung', 25000),
5 => new AccommodationBookingPeriodLineDto('Verpflegung', 6000),
]);
self::assertSame([
['label' => 'Übernachtung', 'amount' => 25000],
['label' => 'Verpflegung', 'amount' => 6000],
], $dto->linesSnapshot());
}
}