/**
  * 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);
 }
 public function it_send_emails(ClosePenaltyService $closePenaltyService, ContainerInterface $container, Config $config, InputInterface $input, MailService $mailer, OutputInterface $output, Penalty $penalty, Rental $rental, RentalRepository $rentalRepository, RequestStack $requestStack, TimePenaltyRepository $timePenaltyRepository, TranslatorInterface $translator)
 {
     $config->get('seta.notifications.days_before_renovation')->shouldBeCalled()->willReturn('2');
     $config->get('seta.notifications.days_before_suspension')->shouldBeCalled()->willReturn('8');
     $container->get('seta_mailing')->shouldBeCalled()->willReturn($mailer);
     $container->get('translator')->shouldBeCalled()->willReturn($translator);
     $container->get('seta.service.close_penalty')->willReturn($closePenaltyService);
     $timePenaltyRepository->findExpiredPenalties()->shouldBeCalled()->willReturn([$penalty]);
     $closePenaltyService->closePenalty($penalty);
     $translator->getLocale()->shouldBeCalled()->willReturn('es');
     $container->get('request_stack')->shouldBeCalled()->willReturn($requestStack);
     $requestStack->push(Argument::type(Request::class))->shouldBeCalled();
     $rentalRepository->getExpireOnDateRentals(Argument::type(\DateTime::class))->willReturn([$rental])->shouldBeCalled();
     $mailer->sendEmail($rental, Argument::any())->shouldBeCalled();
     $this->setContainer($container);
     $this->run($input, $output);
 }