public function start(Project $project, \Closure $output)
{
$path = $project->getPath();
do {
$tmp = 'bl_' . md5(uniqid() . microtime(true));
$configFile = $path . '/' . $tmp;
} while (file_exists($configFile));
$config = $project->getConfig($this->getRun()->getProperties());
file_put_contents($configFile, Yaml::dump($config));
$pb = new ProcessBuilder(array('php', $project->getBehatBin()));
$pb->setWorkingDirectory($project->getPath());
$pb->add('-c')->add($configFile);
$feature = $project->getFeaturesPath() . '/' . $this->feature;
$pb->add($feature);
$pb->setTimeout(null);
$argFormats = array();
$argOutputs = array();
foreach ($project->getFormats() as $format) {
$argFormats[] = $format;
$argOutputs[] = $this->outputFiles->get($format)->getPath();
}
$pb->add('-f')->add(implode(',', $argFormats));
$pb->add('--out')->add(implode(',', $argOutputs));
$pb->add('--ansi');
$this->process = $pb->getProcess();
$this->onFinish = function () use($configFile) {
unlink($configFile);
$this->returnCode = $this->process->getExitCode();
if (null === $this->returnCode) {
$this->returnCode = 255;
}
$this->finishedAt = new \DateTime();
};
$this->process->start(function ($type, $text) use($output) {
$output($text, $type != 'out');
$this->outputFiles->append($type == 'out' ? '_stdout' : '_stderr', $text);
});
}