79 lines
2.7 KiB
PHP
79 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Service;
|
|
|
|
use App\BusProNet\Model\Booking;
|
|
use App\BusProNet\Model\Travel;
|
|
use App\Form\Model\BookingDto;
|
|
use App\Form\Model\BookingSummaryDto;
|
|
use App\Form\Model\ParticipantCardDataDto;
|
|
use App\Form\Model\ParticipantCardPriceDto;
|
|
use App\Service\BookingEditContextFactory;
|
|
use App\Service\BookingSummaryAssembler;
|
|
use App\Service\ParticipantCardAssembler;
|
|
use App\Service\TravelDataProvider;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class BookingEditContextFactoryTest extends TestCase
|
|
{
|
|
public function testCreateOverviewContextKeepsCardsNeutralAndTracksMissingValueLabels(): void
|
|
{
|
|
$travel = new Travel();
|
|
$travel->id = 123;
|
|
|
|
$bookingDto = new BookingDto($travel, 1);
|
|
$bookingDto->participants = [
|
|
new \App\Form\Model\ParticipantDto(),
|
|
new \App\Form\Model\ParticipantDto(),
|
|
];
|
|
|
|
$bookingData = new Booking();
|
|
$bookingData->dateId = 123;
|
|
|
|
$summaryData = $this->createStub(BookingSummaryDto::class);
|
|
|
|
$participantCardAssembler = $this->createMock(ParticipantCardAssembler::class);
|
|
$participantCardAssembler->expects($this->once())
|
|
->method('getAllCardsDataWithValidation')
|
|
->with($bookingDto)
|
|
->willReturn([
|
|
0 => new ParticipantCardDataDto('One', '[email protected]', 'Room A', new ParticipantCardPriceDto(10.0, false), false, true),
|
|
1 => new ParticipantCardDataDto('Two', '[email protected]', 'Room B', new ParticipantCardPriceDto(20.0, false), false, true),
|
|
]);
|
|
|
|
$summaryAssembler = $this->createMock(BookingSummaryAssembler::class);
|
|
$summaryAssembler->expects($this->once())
|
|
->method('getSummaryData')
|
|
->with($bookingDto)
|
|
->willReturn($summaryData);
|
|
|
|
$travelDataProvider = $this->createMock(TravelDataProvider::class);
|
|
$travelDataProvider->expects($this->once())
|
|
->method('getMutabilityData')
|
|
->with(123)
|
|
->willReturn(null);
|
|
|
|
$factory = new BookingEditContextFactory(
|
|
$participantCardAssembler,
|
|
$summaryAssembler,
|
|
$travelDataProvider,
|
|
);
|
|
|
|
$context = $factory->createOverviewContext(
|
|
$bookingDto,
|
|
$bookingData,
|
|
false,
|
|
false,
|
|
false,
|
|
[1 => ['E-Mail', 'Straße']],
|
|
);
|
|
|
|
$this->assertTrue($context->cardsData[0]->isValid);
|
|
$this->assertTrue($context->cardsData[1]->isValid);
|
|
$this->assertSame([], $context->cardsData[1]->errorMessages);
|
|
$this->assertSame([1 => ['E-Mail', 'Straße']], $context->missingValueLabelsByParticipantIndex);
|
|
}
|
|
}
|