feat: simplify handling of ski pass service
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\BusProNet\Model;
|
||||
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\Service;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BookingTest extends TestCase
|
||||
{
|
||||
public function testGetSkiPassForParticipantReturnsCorrectService(): void
|
||||
{
|
||||
$booking = new Booking();
|
||||
|
||||
// Create a ski pass service
|
||||
$skiPassService = new Service();
|
||||
$skiPassService->id = 123;
|
||||
$skiPassService->subType = 'SPA';
|
||||
$skiPassService->mapping = [0, 2]; // Assigned to participants 0 and 2
|
||||
|
||||
// Create a non-ski pass service
|
||||
$otherService = new Service();
|
||||
$otherService->id = 456;
|
||||
$otherService->subType = 'OTHER';
|
||||
$otherService->mapping = [0];
|
||||
|
||||
$booking->additionalServices = [
|
||||
123 => $skiPassService,
|
||||
456 => $otherService,
|
||||
];
|
||||
|
||||
// Test: participant 0 should get the ski pass
|
||||
$result = $booking->getSkiPassForParticipant(0);
|
||||
$this->assertSame($skiPassService, $result);
|
||||
$this->assertEquals(123, $result->id);
|
||||
|
||||
// Test: participant 1 should get null (no ski pass assigned)
|
||||
$result = $booking->getSkiPassForParticipant(1);
|
||||
$this->assertNull($result);
|
||||
|
||||
// Test: participant 2 should get the ski pass
|
||||
$result = $booking->getSkiPassForParticipant(2);
|
||||
$this->assertSame($skiPassService, $result);
|
||||
}
|
||||
|
||||
public function testGetSkiPassForParticipantReturnsNullWhenNoSkiPasses(): void
|
||||
{
|
||||
$booking = new Booking();
|
||||
|
||||
// Only non-ski pass services
|
||||
$otherService = new Service();
|
||||
$otherService->id = 456;
|
||||
$otherService->subType = 'COURSES';
|
||||
$otherService->mapping = [0];
|
||||
|
||||
$booking->additionalServices = [456 => $otherService];
|
||||
|
||||
$result = $booking->getSkiPassForParticipant(0);
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
public function testGetSkiPassForParticipantReturnsNullWhenNoServices(): void
|
||||
{
|
||||
$booking = new Booking();
|
||||
$booking->additionalServices = [];
|
||||
|
||||
$result = $booking->getSkiPassForParticipant(0);
|
||||
$this->assertNull($result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user