Пример #1
0
 public function it_can_return_a_locker_after_due_date(Locker $locker, Rental $rental, EntityManager $manager, EventDispatcherInterface $dispatcher, TimePenaltyService $penaltyService)
 {
     $rental->getDaysLate()->shouldBeCalled()->willReturn(1);
     $rental->setReturnAt(Argument::type(\DateTime::class))->shouldBeCalled();
     $penaltyService->penalizeRental($rental)->shouldBeCalled();
     $locker->setOwner(null)->shouldBeCalled();
     $locker->setStatus(Locker::AVAILABLE)->shouldBeCalled();
     $manager->persist($rental)->shouldBeCalled();
     $manager->persist($locker)->shouldBeCalled();
     $manager->flush()->shouldBeCalled();
     $dispatcher->dispatch(RentalEvents::LOCKER_RETURNED, Argument::type(RentalEvent::class))->shouldBeCalled();
     $this->returnRental($rental);
 }
Пример #2
0
 /**
  * Calcula la fecha de finalización de la sanción.
  *
  * @param Rental $rental
  *
  * @return \DateTime
  */
 public function calculatePenalty(Rental $rental)
 {
     $late = $rental->getDaysLate();
     if ($late === 0) {
         throw new NotExpiredRentalException();
     }
     if ($late >= $this->days_before_suspension) {
         $end = TimePenalty::getEndSeasonPenalty();
     } else {
         $time = $late * 7;
         $end = new \DateTime($time . ' days midnight');
     }
     return $end;
 }
Пример #3
0
 /**
  * Return a Rental.
  *
  * @param Rental $rental
  */
 public function returnRental(Rental $rental)
 {
     if ($rental->getReturnAt()) {
         throw new FinishedRentalException();
     }
     if ($rental->getDaysLate() > 0) {
         $this->penaltyService->penalizeRental($rental);
     }
     $now = new \DateTime('now');
     $rental->setReturnAt($now);
     $locker = $rental->getLocker();
     $locker->setOwner(null);
     $locker->setStatus(Locker::AVAILABLE);
     $this->manager->persist($rental);
     $this->manager->persist($locker);
     $this->manager->flush();
     $event = new RentalEvent($rental);
     $this->dispatcher->dispatch(RentalEvents::LOCKER_RETURNED, $event);
 }
 public function it_can_calculate_penalty(Rental $rental)
 {
     $rental->getDaysLate()->shouldBeCalled();
     $this->calculatePenalty($rental)->shouldBeLike(new \DateTime('14 days midnight'));
 }