Files
myep/tests/Service/BookingEditParticipantContextFactoryTest.php
T

78 lines
2.7 KiB
PHP

<?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);
}
}