b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / vendor / codeception / codeception / ext /
Filename/home/dev2.destoffenstraat.com/vendor/codeception/codeception/ext/RunProcess.php
Size3.67 kb
Permissionrw-r--r--
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified13-Mar-2022 18:07
Last accessed21-Aug-2025 22:34
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php

namespace Codeception\Extension;

use Codeception\Events;
use Codeception\Exception\ExtensionException;
use Codeception\Extension;
use Symfony\Component\Process\Process;

/**
* Extension to start and stop processes per suite.
* Can be used to start/stop selenium server, chromedriver, mailcatcher, etc.
*
* Can be configured in suite config:
*
* ```yaml
* # acceptance.suite.yml
* extensions:
* enabled:
* - Codeception\Extension\RunProcess:
* - chromedriver
* ```
*
* Multiple parameters can be passed as array:
*
* ```yaml
* # acceptance.suite.yml
*
* extensions:
* enabled:
* - Codeception\Extension\RunProcess:
* - php -S 127.0.0.1:8000 -t tests/data/app
* - java -jar ~/selenium-server.jar
* ```
*
* In the end of a suite all launched processes will be stopped.
*
* To wait for the process to be launched use `sleep` option.
* In this case you need configuration to be specified as object:
*
* ```yaml
* extensions:
* enabled:
* - Codeception\Extension\RunProcess:
* 0: java -jar ~/selenium-server.jar
* 1: mailcatcher
* sleep: 5 # wait 5 seconds for processes to boot
* ```
*
* HINT: you can use different configurations per environment.
*/
class RunProcess extends Extension
{
protected $config = ['sleep' => 0];

protected static $events = [
Events::SUITE_BEFORE => 'runProcess',
Events::SUITE_AFTER => 'stopProcess'
];

private $processes = [];

public function _initialize()
{
if (!class_exists('Symfony\Component\Process\Process')) {
throw new ExtensionException($this, 'symfony/process package is required');
}
}

public function runProcess()
{
$this->processes = [];
foreach ($this->config as $key => $command) {
if (!$command) {
continue;
}
if (!is_int($key)) {
continue; // configuration options
}
if (method_exists(Process::class, 'fromShellCommandline')) {
//Symfony 4.2+
$process = Process::fromShellCommandline($command, $this->getRootDir(), null, null, null);
} else {
$process = new Process($command, $this->getRootDir(), null, null, null);
}
$process->start();
$this->processes[] = $process;
$this->output->debug('[RunProcess] Starting '.$command);
}
sleep($this->config['sleep']);
}

public function __destruct()
{
$this->stopProcess();
}

public function stopProcess()
{
foreach (array_reverse($this->processes) as $process) {
/** @var $process Process **/
if (!$process->isRunning()) {
continue;
}
$this->output->debug('[RunProcess] Stopping ' . $process->getCommandLine());
$process->stop();
}
$this->processes = [];
}

/**
* Disable the deserialization of the class to prevent attacker executing
* code by leveraging the __destruct method.
*
* @see https://owasp.org/www-community/vulnerabilities/PHP_Object_Injection
*/
public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize ' . __CLASS__);
}

/**
* Disable the deserialization of the class to prevent attacker executing
* code by leveraging the __destruct method.
*
* @see https://owasp.org/www-community/vulnerabilities/PHP_Object_Injection
*/
public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize ' . __CLASS__);
}
}