コード例 #1
0
 /**
  * @When /^las siguientes sanciones de tiempo:$/
  */
 public function lasSiguientesSanciones(TableNode $table)
 {
     foreach ($table->getHash() as $row) {
         $user = $this->getEntityManager()->getRepository('SetaUserBundle:User')->findOneBy(['email' => $row['usuario']]);
         if (!$user) {
             throw new \Exception('Usuario no encontrado: ' . $row['usuario']);
         }
         $end = new \DateTime($row['dias_sancion'] . ' days midnight');
         $comment = 'Sanción automática';
         $penalty = new TimePenalty();
         $penalty->setUser($user);
         $penalty->setEndAt($end);
         $penalty->setComment($comment);
         $this->getEntityManager()->persist($penalty);
         $this->dispatch(PenaltyEvents::PENALTY_CREATED, new PenaltyEvent($penalty));
     }
     $this->getEntityManager()->flush();
 }
コード例 #2
0
 public function it_can_calculate_season_penalty($rental)
 {
     $rental->getDaysLate()->shouldBeCalled()->willReturn(8);
     $this->calculatePenalty($rental)->shouldBeLike(TimePenalty::getEndSeasonPenalty());
 }
コード例 #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;
 }