예제 #1
0
 public function it_can_rent_any_free_locker(Faculty $faculty, User $user, Locker $locker, Rental $rental, EntityManager $manager, RentalRepository $rentalRepository, LockerRepository $lockerRepository)
 {
     $rentalRepository->createNew()->willReturn($rental);
     $lockerRepository->findOneFreeLocker()->shouldBeCalled()->willReturn($locker);
     $rental->setUser($user)->shouldBeCalled();
     $rental->setLocker($locker)->shouldBeCalled();
     $rental->setEndAt(Argument::any())->shouldBeCalled();
     $locker->setStatus(Locker::RENTED)->shouldBeCalled();
     $locker->setOwner($user)->shouldBeCalled();
     $manager->persist($locker)->shouldBeCalled();
     $manager->persist($rental)->shouldBeCalled();
     $manager->flush()->shouldBeCalled();
     $this->rentFirstFreeLocker($user);
 }
예제 #2
0
 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;
 }
예제 #3
0
 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);
 }