private function canRent(Rental $rental, User $user) { if ($rental->getUser() != $user) { return false; } if ($rental->getReturnAt()) { return false; } if ($user->getIsPenalized()) { return false; } if ($user->getFaculty()->getIsEnabled() === false) { return false; } if (!$rental->getIsRenewable()) { return false; } if ($rental->getIsExpired()) { return false; } if ($rental->getDaysLeft() > $this->days_before_renovation) { return false; } return true; }
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_checks_if_have_pending_penalties(ArrayCollection $collection, ArrayCollection $empty, ObjectManager $manager, PenaltyEvent $event, User $user) { $criteria = Criteria::create()->where(Criteria::expr()->eq('status', Penalty::ACTIVE)); $user->getPenalties()->shouldBeCalled()->willReturn($collection); $collection->matching($criteria)->shouldBeCalled()->willReturn($empty); $empty->count()->shouldBeCalled()->willReturn(1); $this->closedPenalty($event); }
/** * @When /^los siguientes usuarios:$/ */ public function losSiguientesUsuarios(TableNode $table) { foreach ($table->getHash() as $row) { $user = new User(); $user->setUsername($row['email']); $user->setEmail($row['email']); $user->setPlainPassword('secret'); $user->setNic($this->faker->unique()->bothify('########?')); $user->setFullname($this->faker->name); $user->setPhonenumber($this->faker->phoneNumber); $faculty = $this->getEntityManager()->getRepository('SetaUserBundle:Faculty')->findOneBy(['slug' => $row['centro']]); if (!$faculty) { throw new \Exception('Facultad no encontrada: ' . $row['centro']); } $user->setFaculty($faculty); $this->getEntityManager()->persist($user); } $this->getEntityManager()->flush(); }
/** * Preconfigura un usuario. * * @return User */ public function createNewUserEntity() { $user = new User(); $group = $this->get('seta.repository.group')->findOneBy(['name' => 'Usuarios']); $user->addGroup($group); return $user; }
public function it_cannot_renew_a_penalized_user(Rental $rental, User $user) { $user->getIsPenalized()->shouldBeCalled()->willReturn(true); $this->shouldThrow(PenalizedUserException::class)->duringRenewRental($rental); }
public function it_cannot_rent_two_lockers_to_the_same_user(User $user, Locker $locker) { $user->getLocker()->willReturn($locker); $this->shouldThrow(TooManyLockersRentedException::class)->duringRentLocker($user, $locker); }