Alex\BehatLauncher\Behat\Run::setUnits PHP Method

setUnits() public method

Changes the unit collection.
public setUnits ( RunUnitList $units ) : Run
$units RunUnitList units to replace with
return Run
    public function setUnits(RunUnitList $units)
    {
        $this->units = $units;
        return $this;
    }

Usage Example

 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;
 }