/** * @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(); }