Inheritance: implements Symfony\Component\Serializer\Normalizer\NormalizableInterface, implements Symfony\Component\Serializer\Normalizer\DenormalizableInterface
 /**
  * @Given /^following run for "([^"]+)":$/
  */
 public function followingRunFor($name, TableNode $table)
 {
     $app = $this->getApplication();
     $project = $app['project_list']->get($name);
     $methods = array('created_at' => function (RunUnit $unit, $val) {
         $int = new \DateInterval($val);
         $now = new \DateTime();
         $unit->setCreatedAt($now->sub($int));
     }, 'started_at' => function (RunUnit $unit, $val) {
         $int = new \DateInterval($val);
         $now = new \DateTime();
         $unit->setStartedAt($now->sub($int));
     }, 'finished_at' => function (RunUnit $unit, $val) {
         $int = new \DateInterval($val);
         $now = new \DateTime();
         if (!$unit->getStartedAt()) {
             $unit->setStartedAt($now->sub($int));
         }
         $unit->setFinishedAt($now->sub($int));
     }, 'feature' => function (RunUnit $unit, $val) {
         $unit->setFeature($val);
     }, 'return_code' => function (RunUnit $unit, $val) {
         $unit->setReturnCode($val);
     });
     $headers = $table->getRow(0);
     foreach ($headers as $col) {
         if (!isset($methods[$col])) {
             throw new \RuntimeException(sprintf('No handler for column "%s".', $col));
         }
     }
     $run = new Run();
     $run->setProjectName($name);
     $units = $run->getUnits();
     foreach ($table->getRows() as $i => $row) {
         if ($i == 0) {
             continue;
         }
         $unit = new RunUnit();
         foreach ($headers as $i => $header) {
             $value = $row[$i];
             if ($value === '@null') {
                 continue;
             }
             $methods[$header]($unit, $row[$i]);
         }
         $units->add($unit);
     }
     $app['run_storage']->saveRun($run);
 }
 private function getRunsByWhere($where, array $params = array(), $offset = 0, $limit = 100)
 {
     $stmt = $this->connection->prepare('
         SELECT
             R.id AS id,
             R.title AS title,
             R.project_name AS project_name,
             R.properties AS properties,
             R.created_at AS created_at,
             SUM(IF(U.id IS NOT NULL AND U.started_at IS NULL, 1, 0)) AS count_pending,
             SUM(IF(U.id IS NOT NULL AND U.started_at IS NOT NULL AND U.finished_at IS NULL, 1, 0)) AS count_running,
             SUM(IF(U.id IS NOT NULL AND U.finished_at IS NOT NULL AND U.return_code = 0, 1, 0)) AS count_succeeded,
             SUM(IF(U.id IS NOT NULL AND U.finished_at IS NOT NULL AND U.return_code != 0, 1, 0)) AS count_failed,
             MIN(U.started_at) AS started_at,
             MAX(U.finished_at) AS finished_at
         FROM
             bl_run R
             LEFT JOIN bl_run_unit U ON R.id = U.run_id
         WHERE
             ' . $where . '
         GROUP BY R.id
         ORDER BY U.created_at DESC
         LIMIT :offset, :limit
     ');
     $stmt->bindValue('offset', $offset, \PDO::PARAM_INT);
     $stmt->bindValue('limit', $limit, \PDO::PARAM_INT);
     foreach ($params as $name => $value) {
         $stmt->bindValue($name, $value);
     }
     $stmt->execute();
     $runs = array();
     while ($row = $stmt->fetch()) {
         $run = new Run();
         $run->setId($row['id'])->setTitle($row['title'])->setProjectName($row['project_name'])->setProperties(json_decode($row['properties'], true))->setStartedAt(null !== $row['started_at'] ? new \DateTime($row['started_at']) : null)->setFinishedAt(null !== $row['finished_at'] ? new \DateTime($row['finished_at']) : null)->setCreatedAt(new \DateTime($row['created_at']));
         $list = new LazyRunUnitList($this, $run, $row['count_pending'], $row['count_running'], $row['count_succeeded'], $row['count_failed']);
         $run->setUnits($list);
         $runs[] = $run;
     }
     return $runs;
 }
Exemplo n.º 3
0
 /**
  * Creates a run for the project.
  *
  * @return Run
  */
 public function createRun()
 {
     $run = new Run();
     $run->setProjectName($this->name);
     return $run;
 }