public function testConstruct() { $tenant = new Tenant(11, 'tenant name'); $room = new Room(4, 1, 'room name'); $startDate = new DateTime(); $endDate = (new DateTime())->add(new DateInterval('P1M')); $booking = new Booking(123, $tenant, $room, $startDate, $endDate); $this->assertEquals(123, $booking->getId()); $this->assertEquals($tenant, $booking->getTenant()); $this->assertEquals($startDate, $booking->getStartDate()); $this->assertEquals($endDate, $booking->getEndDate()); }
/** * Check if a booking is valid (there's no overlap between existing reservations of the room and the tenant) * * @param Booking $newBooking The new Booking instance. * * @throws InvalidBookingException */ private function checkBooking(Booking $newBooking) { if ($newBooking->getStartDate() >= $newBooking->getEndDate()) { throw new InvalidBookingException('Invalid time range'); } $existingBookingsByTenant = $this->bookingRepositoryInterface->getByTenant($newBooking->getTenant()->getId()); if ($this->isBookingTimeRangesOverlapped($newBooking, $existingBookingsByTenant)) { throw new InvalidBookingException('Tenant booking time ranges are overlapped'); } $roomBookingsByRoom = $this->bookingRepositoryInterface->getByRoom($newBooking->getRoom()->getId()); if ($this->isBookingTimeRangesOverlapped($newBooking, $roomBookingsByRoom)) { throw new InvalidBookingException('Room booking time ranges are overlapped'); } }