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