fix: consider parking space availability
This commit is contained in:
@@ -7,9 +7,11 @@ namespace App\Tests\Form\Service;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\BusProNet\Utility\DirectionMapper;
|
||||
use App\BusProNet\Constants;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Service\ParticipantParkingFieldHandler;
|
||||
use App\Service\ServiceAvailabilityCalculator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ParticipantParkingFieldHandlerTest extends TestCase
|
||||
@@ -18,7 +20,7 @@ class ParticipantParkingFieldHandlerTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->handler = new ParticipantParkingFieldHandler();
|
||||
$this->handler = new ParticipantParkingFieldHandler(new ServiceAvailabilityCalculator());
|
||||
}
|
||||
|
||||
public function testGetFieldName(): void
|
||||
@@ -237,6 +239,50 @@ class ParticipantParkingFieldHandlerTest extends TestCase
|
||||
$this->assertFalse($participant->parking);
|
||||
}
|
||||
|
||||
public function testProcessFieldRejectsParkingWhenSoldOut(): void
|
||||
{
|
||||
$pkwService = $this->createTransportationService(DirectionMapper::SUBTYPE_CAR_API);
|
||||
$parkingService = $this->createParkingService(available: 0);
|
||||
|
||||
$participant = new ParticipantDto();
|
||||
$participant->dateOfBirth = new \DateTimeImmutable('-25 years');
|
||||
$participant->transportationOutbound = $pkwService;
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->additionalServices = [$parkingService->id => $parkingService];
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$participant];
|
||||
|
||||
$submittedData = ['parking' => true];
|
||||
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
$this->assertFalse($participant->parking);
|
||||
$this->assertNull($participant->parkingService);
|
||||
}
|
||||
|
||||
public function testProcessFieldAllowsParkingWhenAvailable(): void
|
||||
{
|
||||
$pkwService = $this->createTransportationService(DirectionMapper::SUBTYPE_CAR_API);
|
||||
$parkingService = $this->createParkingService(available: 5);
|
||||
|
||||
$participant = new ParticipantDto();
|
||||
$participant->dateOfBirth = new \DateTimeImmutable('-25 years');
|
||||
$participant->transportationOutbound = $pkwService;
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->additionalServices = [$parkingService->id => $parkingService];
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$participant];
|
||||
|
||||
$submittedData = ['parking' => true];
|
||||
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
$this->assertTrue($participant->parking);
|
||||
$this->assertSame($parkingService, $participant->parkingService);
|
||||
}
|
||||
|
||||
public function testProcessFieldSetsParkingToFalseWhenNotSelected(): void
|
||||
{
|
||||
$pkwService = $this->createTransportationService(DirectionMapper::SUBTYPE_CAR_API);
|
||||
@@ -300,4 +346,15 @@ class ParticipantParkingFieldHandlerTest extends TestCase
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
private function createParkingService(int $available): Service
|
||||
{
|
||||
$service = new Service();
|
||||
$service->id = 200;
|
||||
$service->label = 'Parkplatz';
|
||||
$service->subType = Constants::TOKEN_PARKING;
|
||||
$service->available = $available;
|
||||
|
||||
return $service;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user