95 lines
3.4 KiB
PHP
95 lines
3.4 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\Service\BookingEditDataLoaderService;
|
|
use App\Service\BookingEditDraftService;
|
|
use App\Service\BookingEditParticipantFormService;
|
|
use App\Service\BookingService;
|
|
use App\Service\BookingSummaryDataService;
|
|
use App\Service\TravelDataService;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
class BookingEditParticipantFormServiceTest extends TestCase
|
|
{
|
|
public function testLoadBookingDtoDelegatesToBookingService(): void
|
|
{
|
|
$request = new Request();
|
|
$bookingDto = $this->createBookingDto();
|
|
$bookingService = $this->createMock(BookingService::class);
|
|
$bookingService->expects($this->once())
|
|
->method('getBookingDto')
|
|
->with($request, BookingDto::MODE_EDIT)
|
|
->willReturn($bookingDto);
|
|
|
|
$service = $this->createService(bookingService: $bookingService);
|
|
|
|
$this->assertSame($bookingDto, $service->loadBookingDto($request));
|
|
}
|
|
|
|
public function testIsParticipantCanceledUsesBookingStatus(): void
|
|
{
|
|
$service = $this->createService();
|
|
$booking = new Booking();
|
|
$booking->participantsStatus = [0 => 'S', 1 => 'A'];
|
|
|
|
$this->assertTrue($service->isParticipantCanceled($booking, 0));
|
|
$this->assertFalse($service->isParticipantCanceled($booking, 1));
|
|
}
|
|
|
|
public function testGetMutableDataDelegatesToTravelDataService(): void
|
|
{
|
|
$mutableData = new BaseData([]);
|
|
$travelDataService = $this->createMock(TravelDataService::class);
|
|
$travelDataService->expects($this->once())
|
|
->method('getMutabilityData')
|
|
->with(1234)
|
|
->willReturn($mutableData);
|
|
|
|
$service = new BookingEditParticipantFormService(
|
|
$this->createMock(BookingEditDataLoaderService::class),
|
|
$this->createMock(BookingEditDraftService::class),
|
|
$this->createMock(BookingService::class),
|
|
$this->createMock(BookingSummaryDataService::class),
|
|
$travelDataService,
|
|
);
|
|
|
|
$this->assertSame($mutableData, $service->getMutableData(1234));
|
|
}
|
|
|
|
private function createService(
|
|
?BookingEditDataLoaderService $dataLoader = null,
|
|
?BookingEditDraftService $draftService = null,
|
|
?BookingService $bookingService = null,
|
|
?BookingSummaryDataService $summaryDataService = null,
|
|
?TravelDataService $travelDataService = null,
|
|
): BookingEditParticipantFormService {
|
|
return new BookingEditParticipantFormService(
|
|
$dataLoader ?? $this->createMock(BookingEditDataLoaderService::class),
|
|
$draftService ?? $this->createMock(BookingEditDraftService::class),
|
|
$bookingService ?? $this->createMock(BookingService::class),
|
|
$summaryDataService ?? $this->createMock(BookingSummaryDataService::class),
|
|
$travelDataService ?? $this->createMock(TravelDataService::class),
|
|
);
|
|
}
|
|
|
|
private function createBookingDto(): BookingDto
|
|
{
|
|
$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();
|
|
|
|
return $bookingDto;
|
|
}
|
|
}
|