예제 #1
0
 /**
  * Crea y calcula una nueva sanción a través de los datos de un alquiler.
  *
  * @param Rental $rental
  */
 public function penalizeRental(Rental $rental)
 {
     $end = $this->calculatePenalty($rental);
     $comment = 'Bloqueo automático por retraso al entregar la taquilla ' . $rental->getLocker()->getCode();
     /** @var TimePenalty $penalty */
     $penalty = $this->penaltyRepository->createNew();
     $user = $rental->getUser();
     $penalty->setUser($user);
     $penalty->setEndAt($end);
     $penalty->setComment($comment);
     $penalty->setRental($rental);
     $this->manager->persist($penalty);
     $this->manager->flush();
     $event = new PenaltyEvent($penalty);
     $this->dispatcher->dispatch(PenaltyEvents::PENALTY_CREATED, $event);
 }
 public function it_can_add_a_penalty_from_a_rent(EventDispatcherInterface $dispatcher, ObjectManager $manager, Locker $locker, TimePenalty $penalty, TimePenaltyRepository $timePenaltyRepository, Rental $rental, User $user)
 {
     $end = $this->calculatePenalty($rental);
     $rental->getLocker()->shouldBeCalled();
     $locker->getCode()->shouldBeCalled();
     $comment = 'Bloqueo automático por retraso al entregar la taquilla 100';
     $rental->getUser()->shouldBeCalled();
     $timePenaltyRepository->createNew()->shouldBeCalled()->willReturn($penalty);
     $penalty->setUser($user)->shouldBeCalled();
     $penalty->setEndAt($end)->shouldBeCalled();
     $penalty->setComment($comment)->shouldBeCalled();
     $penalty->setRental($rental)->shouldBeCalled();
     $manager->persist($penalty)->shouldBeCalled();
     $manager->flush()->shouldBeCalled();
     $dispatcher->dispatch(PenaltyEvents::PENALTY_CREATED, Argument::type(PenaltyEvent::class))->shouldBeCalled();
     $this->penalizeRental($rental);
 }