Ensures the behat dir exists in moodledata
@param int $runprocess run process for which behat dir is returned.
@return string Full path
11018
public static function get_behat_dir($runprocess = 0) {
        global $CFG;

        // If not set then return empty string.
        if (!isset($CFG->behat_dataroot)) {
            return "";
        }

        // If $CFG->behat_parallel_run starts with index 0 and $runprocess for parallel run starts with 1.
        if (!empty($runprocess) && isset($CFG->behat_parallel_run[$runprocess - 1]['behat_dataroot'])) {
            $behatdir = $CFG->behat_parallel_run[$runprocess - 1]['behat_dataroot'] . '/behat';;
        } else {
            $behatdir = $CFG->behat_dataroot . '/behat';
        }

        if (!is_dir($behatdir)) {
            if (!mkdir($behatdir, $CFG->directorypermissions, true)) {
                behat_error(BEHAT_EXITCODE_PERMISSIONS, 'Directory ' . $behatdir . ' can not be created');
            }
        }

        if (!is_writable($behatdir)) {
            behat_error(BEHAT_EXITCODE_PERMISSIONS, 'Directory ' . $behatdir . ' is not writable');
        }

        return $behatdir;
    }
1024124
private function guessBinaryPath()
    {
        $p = new Process(sprintf('which %s', $this->binaryName));
        $p->run();
        $output = trim($p->getOutput());
        if ('' === $output) {
            throw new \RuntimeException('binary path not found. Is Pygments installed?');
        }

        return $output;
    }
1167166
protected function runningProcesses()
    {
        $count = 0;
        foreach ($this->processes as $process) {
            if ($process->isRunning()) {
                $count++;
            }
        }

        return $count;
    }
394190
public function getFirstProcess()
    {
        $firstProcess = null;
        foreach ($this->process as $process) {
            if ($this->isRunning() && ! $process->isRunning()) {
                $this->detach($process);
                continue;
            }

            if (null !== $firstProcess) {
                continue;
            }
            $firstProcess = $process;
        }

        return $firstProcess;
    }
857313
public static function detectCmdLocationInPath(string $cmd, string $path) : string
    {
        $command = $path . DIRECTORY_SEPARATOR . $cmd;
        $bin     = self::getExecutable($command);
        if (empty($bin)) {
            throw new RuntimeException(sprintf('wrong path specified for \'%s\': %s', $cmd, $path));
        }
        return $bin;
    }
207885
public function create_run_dir() {
		if ( !isset( $this->variables['RUN_DIR'] ) ) {
			self::$run_dir = $this->variables['RUN_DIR'] = sys_get_temp_dir() . '/' . uniqid( 'wp-cli-test-run-' . self::$temp_dir_infix . '-', TRUE );
			mkdir( $this->variables['RUN_DIR'] );
		}
	}
813973
public function start(AbstractProcess $process, string $name = ''): bool
    {
        if ($process->start()) {
            $name = empty($name) ? $process->getName() : $name;
            if (empty($name)) {
                throw new RuntimeException('The process name is not empty');
            }
            $this->processes->put($name, ['pid' => $process->getPid()]);
            $this->processStoreToFile();

            return true;
        }

        return false;
    }
743956
public static function toPath($path, $ext = 'php', $root = '') {
        $ds = static::SEPARATOR;
        $path = static::ds($path);
        $dirs = explode($ds, $path);
        $file = array_pop($dirs);
        $path = implode($ds, $dirs) . $ds . str_replace('_', $ds, $file);

        if ($ext && mb_substr($path, -mb_strlen($ext)) !== $ext) {
            $path .= '.' . $ext;
        }

        if ($root) {
            $path = $root . $path;
        }

        return $path;
    }
773633
public function run(array $paths = array())
    {
        $results = $this->container->get('behat.inspector')
            ->run($paths);

        return new ProcessEvent($this,$results);
    }
979202
public function getRuntimeDir()
    {
        if (!isset($this->runtimeDir)) {
            $this->runtimeDir = ConfigPaths::getRuntimeDir();
        }

        if (!\is_dir($this->runtimeDir)) {
            \mkdir($this->runtimeDir, 0700, true);
        }

        return $this->runtimeDir;
    }
1023827
private function createProcess()
    {
        $descriptorSpec = [
            ['pipe', 'r'], // stdin
            ['pipe', 'w'], // stdout
            ['pipe', 'r']  // stderr
        ];

        $this->process = proc_open($this->cmd, $descriptorSpec, $this->pipes, $this->cwd);

        if (!is_resource($this->process)) {
            throw new \RuntimeException('Could not create the process.');
        }
    }
259609
private static function getPhp($include_args = true)
    {
        $phpFinder = new PhpExecutableFinder();
        if (!$phpPath = $phpFinder->find($include_args)) {
            throw new \RuntimeException('The php executable could not be found, add it to your PATH environment variable and try again');
        }

        return $phpPath;
    }
1179112
public function behat() {
    $copy_map = [
      $this->getConfigValue('blt.root') . '/template/tests/behat/behat.yml' => $this->getConfigValue('repo.root') . '/tests/behat/behat.yml',
      $this->getConfigValue('blt.root') . '/template/tests/behat/example.local.yml' => $this->defaultBehatLocalConfigFile,
      $this->defaultBehatLocalConfigFile => $this->projectBehatLocalConfigFile,
    ];

    $task = $this->taskFilesystemStack()
      ->stopOnFail()
      ->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE);

    // Copy files without overwriting.
    foreach ($copy_map as $from => $to) {
      if (file_exists($to)) {
        unset($copy_map[$from]);
      }
    }

    if ($copy_map) {
      $this->say("Generating Behat configuration files...");
      foreach ($copy_map as $from => $to) {
        $task->copy($from, $to);
      }
      $result = $task->run();
      foreach ($copy_map as $from => $to) {
        $this->getConfig()->expandFileProperties($to);
      }

      if (!$result->wasSuccessful()) {
        $filepath = $this->getInspector()->getFs()->makePathRelative($this->defaultBehatLocalConfigFile, $this->getConfigValue('repo.root'));
        throw new BltException("Unable to copy $filepath into your repository.");
      }
    }
  }
1177762
public function getApacheInstancesPath()
    {
        if ($this->apache_config_path === false &&
            is_array($this->apache_compiles) &&
            array_key_exists('SERVER_CONFIG_FILE', $this->apache_compiles)
        ) {
            $config_file = $this->apache_compiles['SERVER_CONFIG_FILE'];
            if (is_file($config_file)) {
                $base_path = dirname($config_file);
                if (is_dir($base_path . DIRECTORY_SEPARATOR . 'other')) {
                    $this->apache_config_path = $base_path . DIRECTORY_SEPARATOR . 'other';
                } elseif (is_dir($base_path . DIRECTORY_SEPARATOR . 'conf.d')) {
                    $this->apache_config_path = $base_path . DIRECTORY_SEPARATOR . 'conf.d';
                }
            }  elseif (array_key_exists('HTTPD_ROOT', $this->apache_compiles)) {
                $base_path = preg_replace('/"$/', '', preg_replace('/^"/', '', $this->apache_compiles['HTTPD_ROOT']));
                if (is_dir($base_path . DIRECTORY_SEPARATOR . 'conf.d')) {
                    $this->apache_config_path = $base_path . DIRECTORY_SEPARATOR . 'conf.d';
                } elseif (is_dir($base_path . DIRECTORY_SEPARATOR . 'other')) {
                    $this->apache_config_path = $base_path . DIRECTORY_SEPARATOR . 'other';
                }
            }
        }

        return $this->apache_config_path;
    }
766312
def get_and_execute_process_runner tool, options=nil
      runner = get_process_runner
      runner.execute_open4 clean_path(tool), options
      runner
    end
365280
public function run($args)
    {
        $args = $this->parseArgs($args);

        if (!isset($args[0]) || !$args[0]) {
            return "> Producer: Project directory required.\n";
        }

        $projectName = trim($args[0]);
        if (!$this->existsProjectName($projectName)) {
            return "> Producer: Project directory '{$this->projectsDir}/{$projectName}' not found.\n";
        }

        $this->info("Purge project '{$projectName}'");

        $json = null;
        $composerJson = $this->cwd.'/'.$this->projectsDir.'/'.$projectName.'/composer.json';
        if (file_exists($composerJson)) {
            $json = json_decode(file_get_contents($composerJson), true);
        }

        if (isset($json['name']) && $this->existsPackageName($json['name'])) {
            $this->exec('purge', 'remove-package', [$json['name']]);
        }

        return $this->exec('purge', 'remove-project', [$projectName]);
    }
49132
public function getCurrentBranch($dir = null, $mustRun = false)
    {
        $args = ['symbolic-ref', '--short', 'HEAD'];

        return $this->execute($args, $dir, $mustRun);
    }