Skip to content

Commit 3eae7b3

Browse files
NaktibaldaDavertMik
authored andcommitted
RunProcess and RunBefore extensions compatible with Symfony 5 (Codeception#5785)
1 parent c145d60 commit 3eae7b3

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

ext/RunBefore.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ private function runProcesses()
8080
private function runProcess($command)
8181
{
8282
$this->output->debug('[RunBefore] Starting ' . $command);
83-
$process = new Process($command, $this->getRootDir());
83+
84+
if (method_exists(Process::class, 'fromShellCommandline')) {
85+
//Symfony 4.2+
86+
$process = Process::fromShellCommandline($command, $this->getRootDir());
87+
} else {
88+
$process = new Process($command, $this->getRootDir());
89+
}
8490
$process->start();
8591

8692
return $process;

ext/RunProcess.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@
5151
*/
5252
class RunProcess extends Extension
5353
{
54-
public $config = ['sleep' => 0];
55-
56-
static $events = [
54+
protected $config = ['sleep' => 0];
55+
56+
protected static $events = [
5757
Events::SUITE_BEFORE => 'runProcess',
5858
Events::SUITE_AFTER => 'stopProcess'
5959
];
6060

61-
protected $processes = [];
62-
61+
private $processes = [];
62+
6363
public function _initialize()
6464
{
6565
if (!class_exists('Symfony\Component\Process\Process')) {
@@ -77,7 +77,12 @@ public function runProcess()
7777
if (!is_int($key)) {
7878
continue; // configuration options
7979
}
80-
$process = new Process($command, $this->getRootDir(), null, null, null);
80+
if (method_exists(Process::class, 'fromShellCommandline')) {
81+
//Symfony 4.2+
82+
$process = Process::fromShellCommandline($command, $this->getRootDir(), null, null, null);
83+
} else {
84+
$process = new Process($command, $this->getRootDir(), null, null, null);
85+
}
8186
$process->start();
8287
$this->processes[] = $process;
8388
$this->output->debug('[RunProcess] Starting '.$command);

0 commit comments

Comments
 (0)