Exemplo n.º 1
0
 /**
  * @When /^el usuario "([^"]*)" tiene una sanción por la taquilla "([^"]*)" de todo el curso$/
  */
 public function elUsuarioTieneUnaSanciónPorLaTaquillaDeTodoElCurso($username, $code)
 {
     /** @var User $user */
     $user = $this->getRepository('user')->findOneBy(['username' => $username]);
     if (!$user) {
         throw new \Exception('User not found: ' . $username);
     }
     \PHPUnit_Framework_Assert::assertTrue($user->getIsPenalized());
     $this->getEntityManager()->refresh($user);
     $penalties = $user->getPenalties();
     $endSeason = TimePenalty::getEndSeasonPenalty();
     foreach ($penalties as $penalty) {
         if ($penalty instanceof TimePenalty) {
             if ($penalty->getRental()->getLocker()->getCode() == $code) {
                 \PHPUnit_Framework_Assert::assertGreaterThanOrEqual($endSeason, $penalty->getEndAt());
                 return true;
             }
         }
     }
     throw new \Exception('TimePenalty not found.');
 }
 public function it_can_calculate_season_penalty($rental)
 {
     $rental->getDaysLate()->shouldBeCalled()->willReturn(8);
     $this->calculatePenalty($rental)->shouldBeLike(TimePenalty::getEndSeasonPenalty());
 }
Exemplo n.º 3
0
 /**
  * Calcula la fecha de finalización de la sanción.
  *
  * @param Rental $rental
  *
  * @return \DateTime
  */
 public function calculatePenalty(Rental $rental)
 {
     $late = $rental->getDaysLate();
     if ($late === 0) {
         throw new NotExpiredRentalException();
     }
     if ($late >= $this->days_before_suspension) {
         $end = TimePenalty::getEndSeasonPenalty();
     } else {
         $time = $late * 7;
         $end = new \DateTime($time . ' days midnight');
     }
     return $end;
 }