public function rentLocker(User $user, Locker $locker)
 {
     if ($user->getIsPenalized()) {
         throw new PenalizedUserException();
     }
     if ($user->getFaculty()->getIsEnabled() === false) {
         throw new PenalizedFacultyException();
     }
     if ($locker->getStatus() != Locker::AVAILABLE) {
         throw new BusyLockerException();
     }
     if ($user->getLocker()) {
         throw new TooManyLockersRentedException();
     }
     /** @var Rental $rental */
     $rental = $this->rentalRepository->createNew();
     $rental->setUser($user);
     $rental->setLocker($locker);
     $rental->setEndAt(new \DateTime($this->days_length_rental . ' days'));
     $locker->setStatus(Locker::RENTED);
     $locker->setOwner($user);
     $this->manager->persist($locker);
     $this->manager->persist($rental);
     $this->manager->flush();
     $event = new RentalEvent($rental);
     $this->dispatcher->dispatch(RentalEvents::LOCKER_RENTED, $event);
     return $rental;
 }
 public function it_cannot_rent_two_lockers_to_the_same_user(User $user, Locker $locker)
 {
     $user->getLocker()->willReturn($locker);
     $this->shouldThrow(TooManyLockersRentedException::class)->duringRentLocker($user, $locker);
 }