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); }
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_can_add_a_penalty_from_a_rent(EventDispatcherInterface $dispatcher, ObjectManager $manager, Locker $locker, FinancialPenalty $penalty, FinancialPenaltyRepository $penaltyRepository, Rental $rental, User $user) { $rental->getLocker()->shouldBeCalled(); $locker->getCode()->shouldBeCalled(); $comment = 'Penalización automática por retraso al entregar la taquilla 100'; $rental->getUser()->shouldBeCalled(); $penaltyRepository->createNew()->shouldBeCalled()->willReturn($penalty); $penalty->setUser($user)->shouldBeCalled(); $penalty->setAmount($this->amount)->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_finds_current_locker_rental(Locker $locker, Rental $rental, User $user, EntityManager $manager, QueryBuilder $builder, AbstractQuery $query, Expr $expr) { $locker->getOwner()->shouldBeCalled()->willReturn($user); $manager->createQueryBuilder()->shouldBeCalled()->willReturn($builder); $builder->expr()->shouldBeCalled()->willReturn($expr); $builder->select('o')->shouldBeCalled()->willReturn($builder); $builder->from(Argument::any(), 'o', Argument::any())->shouldBeCalled()->willReturn($builder); $expr->eq('o.user', ':user')->shouldBeCalled()->willReturn($expr); $builder->andWhere($expr)->shouldBeCalled()->willReturn($builder); $expr->eq('o.locker', ':locker')->shouldBeCalled()->willReturn($expr); $builder->andWhere($expr)->shouldBeCalled()->willReturn($builder); $expr->isNull('o.returnAt')->shouldBeCalled()->willReturn($expr); $builder->andWhere($expr)->shouldBeCalled()->willReturn($builder); $builder->setParameter('user', $user)->shouldBeCalled()->willReturn($builder); $builder->setParameter('locker', $locker)->shouldBeCalled()->willReturn($builder); $builder->getQuery()->shouldBeCalled()->willReturn($query); $query->getOneOrNullResult()->shouldBeCalled()->willReturn($rental); $this->getCurrentRental($locker); }
public function it_cannot_rent_busy_locker(User $user, Locker $locker) { $locker->getStatus()->willReturn(Locker::RENTED); $this->shouldThrow(BusyLockerException::class)->duringRentLocker($user, $locker); }