Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace spec\Reservation;
- use Core\CompanyId;
- use Core\RoomId;
- use Core\RoomMasterId;
- use DateTime;
- use PhpSpec\ObjectBehavior;
- use Prophecy\Argument;
- use Reservation\BlockedTermWasCanceled;
- use Reservation\CustomerReservationInformation;
- use Reservation\Room;
- use Reservation\SourcesOfReservations\ReservationSourceId;
- use Reservation\Term;
- use Reservation\TermCannotBeBlocked;
- use Reservation\TermCannotBeEdited;
- use Reservation\ReservationCannotUnfulfilled;
- use Reservation\TermCannotBeUnblocked;
- use Reservation\TermWasBlocked;
- use Reservation\TermWasReserved;
- use Reservation\TermWasCanceled;
- use Reservation\TermWasReservedByGameMaster;
- use Reservation\TimeFrameWasAdded;
- /**
- * Class RoomSpec
- * @package spec\Reservation
- * @mixin Room
- */
- class RoomSpec extends ObjectBehavior
- {
- public function it_is_initializable()
- {
- $this->shouldHaveType('Reservation\Room');
- }
- public function let()
- {
- $this->beConstructedWith(new RoomId('123'), new CompanyId('987'));
- }
- public function it_allows_to_reserve_new_term()
- {
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $this->addAvailableTimeFrame($timeFrame);
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $customerReservationInformation = new CustomerReservationInformation('customer name', '661200032', 'szymon.skowronski@gmail.com');
- $reservationSourceId = new ReservationSourceId('sourceId');
- $this->addNewReservation($term, $customerReservationInformation, $reservationSourceId);
- $this->getRecordedEvents()[1]->shouldBeLike(TermWasReserved::fromRoomTerm(
- new RoomId('123'),
- new CompanyId('987'),
- $term,
- $customerReservationInformation,
- $reservationSourceId
- ));
- }
- public function it_allows_to_reserve_by_game_master()
- {
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $this->addAvailableTimeFrame($timeFrame);
- $roomMasterId = new RoomMasterId('id');
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $this->reserveByGameMaster($term, new CustomerReservationInformation('customer name', '661200032', 'szymon.skowronski@gmail.com'), $roomMasterId);
- $this->getRecordedEvents()[1]->shouldBeLike(
- TermWasReservedByGameMaster::fromRoomTerm(new RoomId('123'), $term, new CustomerReservationInformation('customer name', '661200032', 'szymon.skowronski@gmail.com'), $roomMasterId)
- );
- }
- public function it_cannot_reserve_room_in_same_time()
- {
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $this->addAvailableTimeFrame($timeFrame);
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $this->reserveByCustomer($term, new CustomerReservationInformation('customer name', '661200032', 'szymon.skowronski@gmail.com'));
- $this->shouldThrow(\LogicException::class)->duringReserveByCustomer($term, new CustomerReservationInformation('customer name', '661200032', 'szymon.skowronski@gmail.com'));
- }
- public function it_cannot_cancel_not_reserved_term()
- {
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $this->addAvailableTimeFrame($timeFrame);
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $this->shouldThrow(\LogicException::class)->duringCancelReservation($term);
- }
- public function it_cancel_reservation()
- {
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $this->addAvailableTimeFrame($timeFrame);
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $customerReservationInformation = new CustomerReservationInformation('customer name', '661200032', 'szymon.skowronski@gmail.com');
- $reservationSourceId = new ReservationSourceId('sourceId');
- $this->addNewReservation($term, $customerReservationInformation, $reservationSourceId);
- $this->cancelReservation($term);
- $events = $this->getRecordedEvents();
- $events->shouldHaveCount(3);
- $events[1]->shouldBeLike(TermWasReserved::fromRoomTerm(
- new RoomId('123'),
- new CompanyId('987'),
- $term,
- $customerReservationInformation,
- $reservationSourceId
- ));
- $events[2]->shouldBeLike(TermWasCanceled::fromRoomTerm(new RoomId('123'), new CompanyId('987'), $term));
- }
- public function it_allows_to_reserve_term_after_cancel()
- {
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $this->addAvailableTimeFrame($timeFrame);
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $customerReservationInformation = new CustomerReservationInformation('customer name', '661200032', 'szymon.skowronski@gmail.com');
- $reservationSourceId = new ReservationSourceId('sourceId');
- $this->addNewReservation($term, $customerReservationInformation, $reservationSourceId);
- $this->cancelReservation($term);
- $this->addNewReservation($term, $customerReservationInformation, $reservationSourceId);
- $events = $this->getRecordedEvents();
- $events->shouldHaveCount(4);
- $events[3]->shouldBeLike(TermWasReserved::fromRoomTerm(
- new RoomId('123'),
- new CompanyId('987'),
- $term,
- $customerReservationInformation,
- $reservationSourceId
- ));
- }
- public function it_allows_to_add_new_open_hour()
- {
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::MON, Room\OpenHour::fromString('17:00'));
- $this->addAvailableTimeFrame($timeFrame);
- $events = $this->getRecordedEvents();
- $events->shouldHaveCount(1);
- $events[0]->shouldBeLike(
- TimeFrameWasAdded::fromRoomSingleTimeFrame(new RoomId('123'), $timeFrame, new DateTime())
- );
- }
- public function it_clear_recoreded_events_after_getting_them()
- {
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $this->addAvailableTimeFrame($timeFrame);
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $this->reserveByCustomer($term, new CustomerReservationInformation('customer name', '661200032', 'szymon.skowronski@gmail.com'));
- $events = $this->getRecordedEvents();
- $events->shouldHaveCount(2);
- $this->getRecordedEvents()->shouldHaveCount(0);
- }
- public function it_can_be_reconstructed_from_events()
- {
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $term2 = Term::fromDateTime(new \DateTimeImmutable('08.01.2016 15:40'));
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $roomId = new RoomId('123');
- $companyId = new CompanyId('987');
- $customerReservationInformation = new CustomerReservationInformation('customer name', '661200032', 'szymon.skowronski@gmail.com');
- $reservationSourceId = new ReservationSourceId('sourceId');
- $events = [
- TimeFrameWasAdded::fromRoomSingleTimeFrame($roomId, $timeFrame, new DateTime()),
- TermWasReserved::fromRoomTerm(
- $roomId,
- $companyId,
- $term,
- $customerReservationInformation,
- $reservationSourceId
- ),
- TermWasReserved::fromRoomTerm(
- $roomId,
- $companyId,
- $term2,
- $customerReservationInformation,
- $reservationSourceId
- ),
- TermWasCanceled::fromRoomTerm($roomId, $companyId, $term),
- ];
- $this->beConstructedThrough('fromEvents', [$roomId, $companyId, $events]);
- $this->getAggregateRootId()->shouldBeLike($roomId);
- }
- public function it_allows_to_block_term()
- {
- $roomId = new RoomId('123');
- $companyId = new CompanyId('987');
- $reasonOfBlockade = 'dobry powód';
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $existingEvents = [
- TimeFrameWasAdded::fromRoomSingleTimeFrame($roomId, $timeFrame, new DateTime())
- ];
- $this->beConstructedThrough('fromEvents', [$roomId, $companyId, $existingEvents]);
- $this->block($term, new RoomMasterId('master-id'), $reasonOfBlockade);
- $events = $this->getRecordedEvents();
- $events->shouldHaveCount(1);
- $events[0]->shouldBeLike(
- TermWasBlocked::fromRoomTerm($roomId, $companyId, $term, $reasonOfBlockade, new RoomMasterId('master-id'))
- );
- }
- public function it_does_not_allow_to_block_term_when_given_term_is_reserved_already()
- {
- $roomId = new RoomId('123');
- $companyId = new CompanyId('987');
- $reasonOfBlockade = 'dobry powód';
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $existingEvents = [
- TimeFrameWasAdded::fromRoomSingleTimeFrame($roomId, $timeFrame, new DateTime()),
- TermWasReserved::fromRoomTerm(
- $roomId,
- $companyId,
- $term,
- new CustomerReservationInformation('customer name', '661200032', 'szymon.skowronski@gmail.com'),
- new ReservationSourceId('sourceId')
- )
- ];
- $this->beConstructedThrough('fromEvents', [$roomId, $companyId, $existingEvents]);
- $this->shouldThrow(TermCannotBeBlocked::class)->duringBlock($term, new RoomMasterId('master-id'), $reasonOfBlockade);
- $events = $this->getRecordedEvents();
- $events->shouldHaveCount(0);
- }
- public function it_allows_to_block_term_after_cancelling_reservation_for_that_term()
- {
- $roomId = new RoomId('123');
- $companyId = new CompanyId('987');
- $reasonOfBlockade = 'dobry powód';
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $existingEvents = [
- TimeFrameWasAdded::fromRoomSingleTimeFrame($roomId, $timeFrame, new DateTime()),
- TermWasReserved::fromRoomTerm(
- $roomId,
- $companyId,
- $term,
- new CustomerReservationInformation('customer name', '661200032', 'szymon.skowronski@gmail.com'),
- new ReservationSourceId('sourceId')
- ),
- TermWasCanceled::fromRoomTerm($roomId, $companyId, $term)
- ];
- $this->beConstructedThrough('fromEvents', [$roomId, $companyId, $existingEvents]);
- $this->block($term, new RoomMasterId('master-id'), $reasonOfBlockade);
- $events = $this->getRecordedEvents();
- $events->shouldHaveCount(1);
- $events[0]->shouldBeLike(
- TermWasBlocked::fromRoomTerm(new RoomId('123'), $companyId, $term, $reasonOfBlockade, new RoomMasterId('master-id'))
- );
- }
- public function it_not_allows_to_reservate_for_other_term_that_is_not_predefinate()
- {
- $roomId = new RoomId('123');
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $existingEvents = [
- TimeFrameWasAdded::fromRoomSingleTimeFrame($roomId, $timeFrame, new DateTime())
- ];
- $this->beConstructedThrough('fromEvents', [$roomId, new CompanyId('987'), $existingEvents]);
- $term = Term::fromDateTime(new \DateTimeImmutable('02.01.2016 15:40'));
- $this->shouldThrow(\LogicException::class)->during(
- 'addNewReservation',
- [
- $term,
- new CustomerReservationInformation('test', 'test', 'email@email.pl'),
- new ReservationSourceId('sourceId')
- ]);
- }
- public function it_can_delete_all_predefinated_terms()
- {
- $roomId = new RoomId('123');
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $existingEvents = [
- TimeFrameWasAdded::fromRoomSingleTimeFrame($roomId, $timeFrame, new DateTime())
- ];
- $this->beConstructedThrough('fromEvents', [$roomId, new CompanyId('987'), $existingEvents]);
- $this->clearAvailableTimeFrames();
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $this->shouldThrow(\LogicException::class)->during(
- 'addNewReservation',
- [
- $term,
- new CustomerReservationInformation('test', 'test', 'email@email.pl'),
- new ReservationSourceId('sourceId')
- ]);
- }
- public function it_can_cancel_blocked_term()
- {
- $roomId = new RoomId('123');
- $companyId = new CompanyId('987');
- $reasonOfBlockade = 'dobry powód';
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $existingEvents = [
- TimeFrameWasAdded::fromRoomSingleTimeFrame($roomId, $timeFrame, new DateTime()),
- ];
- $this->beConstructedThrough('fromEvents', [$roomId, $companyId, $existingEvents]);
- $this->block($term, new RoomMasterId('master-id'), $reasonOfBlockade);
- $this->unblock($term, new RoomMasterId('master-id'));
- $events = $this->getRecordedEvents();
- $events->shouldHaveCount(2);
- $events[1]->shouldBeLike(
- BlockedTermWasCanceled::fromRoomTerm($roomId, $companyId, $term, new RoomMasterId('master-id'))
- );
- }
- public function it_cannot_cancel_block_that_not_exist()
- {
- $roomId = new RoomId('123');
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $existingEvents = [
- TimeFrameWasAdded::fromRoomSingleTimeFrame($roomId, $timeFrame, new DateTime()),
- ];
- $this->beConstructedThrough('fromEvents', [$roomId, new CompanyId('987'), $existingEvents]);
- $this->shouldThrow(TermCannotBeUnblocked::class)->during('unblock', [$term, new RoomMasterId('master-id')]);
- }
- public function it_cant_block_term_twice()
- {
- $roomId = new RoomId('123');
- $reasonOfBlockade = 'dobry powód';
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $existingEvents = [
- TimeFrameWasAdded::fromRoomSingleTimeFrame($roomId, $timeFrame, new DateTime())
- ];
- $this->beConstructedThrough('fromEvents', [$roomId, new CompanyId('987'), $existingEvents]);
- $this->block($term, new RoomMasterId('master-id'), $reasonOfBlockade);
- $this->shouldThrow(TermCannotBeBlocked::class)->during('block', [$term, new RoomMasterId('master-id'), $reasonOfBlockade]);
- }
- public function it_can_block_term_after_unblock()
- {
- $roomId = new RoomId('123');
- $companyId = new CompanyId('987');
- $reasonOfBlockade = 'dobry powód';
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $existingEvents = [
- TimeFrameWasAdded::fromRoomSingleTimeFrame($roomId, $timeFrame, new DateTime())
- ];
- $this->beConstructedThrough('fromEvents', [$roomId, $companyId, $existingEvents]);
- $this->block($term, new RoomMasterId('master-id'), $reasonOfBlockade);
- $this->unblock($term, new RoomMasterId('master-id'));
- $this->block($term, new RoomMasterId('master-id'), $reasonOfBlockade);
- $events = $this->getRecordedEvents();
- $events->shouldHaveCount(3);
- $events[2]->shouldBeLike(
- TermWasBlocked::fromRoomTerm($roomId, $companyId, $term, $reasonOfBlockade, new RoomMasterId('master-id'))
- );
- }
- public function it_can_edit_only_when_there_is_reservation()
- {
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $this->addAvailableTimeFrame($timeFrame);
- $roomMasterId = new RoomMasterId('id');
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $this->reserveByGameMaster($term, new CustomerReservationInformation('customer name', '661200032', 'szymon.skowronski@gmail.com'), $roomMasterId);
- $this->editReservation($term, new CustomerReservationInformation('name', 'phone'), $roomMasterId);
- }
- public function it_throws_cannot_edit_without_reservation()
- {
- $this->addAvailableTimeFrame(new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40')));
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $this->shouldThrow(TermCannotBeEdited::class)->during('editReservation', [$term, new CustomerReservationInformation('name', 'phone'), new RoomMasterId('id')]);
- }
- public function it_can_mark_as_unfulfilled_only_when_there_is_reservation()
- {
- $timeFrame = new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40'));
- $this->addAvailableTimeFrame($timeFrame);
- $roomMasterId = new RoomMasterId('id');
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $this->reserveByGameMaster($term, new CustomerReservationInformation('customer name', '661200032', 'szymon.skowronski@gmail.com'), $roomMasterId);
- $this->groupAreNotComing($term, $roomMasterId);
- }
- public function it_throws_cannot_mark_as_unfulfilled_without_reservation()
- {
- $this->addAvailableTimeFrame(new Room\SingleTimeFrame(Room\SingleTimeFrame::FRI, Room\OpenHour::fromString('15:40')));
- $term = Term::fromDateTime(new \DateTimeImmutable('01.01.2016 15:40'));
- $this->shouldThrow(ReservationCannotUnfulfilled::class)->during('groupAreNotComing', [$term, new RoomMasterId('id')]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement