Skip to content

Commit 1717fc3

Browse files
author
Mariano Custiel
committed
Using symfony process
1 parent bc55863 commit 1717fc3

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

src/Extension/Phiremock.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,21 @@
2525
*/
2626
class Phiremock extends CodeceptionExtension
2727
{
28+
/**
29+
* @var array
30+
*/
2831
public static $events = [];
2932

33+
/**
34+
* @var array
35+
*/
3036
protected $config = [
3137
'listen' => '0.0.0.0:8086',
3238
'debug' => false,
3339
'startDelay' => 0
3440
];
3541

3642
/**
37-
*
3843
* @var PhiremockProcess
3944
*/
4045
private $process;
@@ -51,7 +56,7 @@ public function __construct(
5156
array $options,
5257
PhiremockProcess $process = null
5358
) {
54-
$this->config['bin_path'] = Config::projectDir() . '../vendor/bin';
59+
$this->config['bin_path'] = Config::projectDir() . '../vendor/bin/phiremock';
5560
$this->config['logs_path'] = Config::logDir();
5661

5762
parent::__construct($config, $options);

src/Extension/PhiremockProcess.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
namespace Codeception\Extension;
1919

2020
use Symfony\Component\Process\Process;
21-
use Symfony\Component\Process\ProcessBuilder;
2221

2322
/**
2423
* Manages the current running WireMock process.
@@ -37,11 +36,6 @@ class PhiremockProcess
3736
*/
3837
private $process;
3938

40-
/**
41-
* @var resource[]
42-
*/
43-
private $pipes;
44-
4539
/**
4640
* Starts a wiremock process.
4741
*
@@ -53,37 +47,44 @@ class PhiremockProcess
5347
*/
5448
public function start($ip, $port, $path, $logsPath, $debug)
5549
{
56-
$builder = new ProcessBuilder(['-i', $ip, '-p', $port]);
50+
$phiremockPath = is_file($path) ? $path : "{$path}/phiremock";
51+
$this->process = new Process(
52+
$this->getCommandPrefix()
53+
. "{$phiremockPath} -i {$ip} -p {$port}"
54+
. ($debug? ' -d' : '')
55+
);
5756
if ($debug) {
58-
$builder->add('-d');
57+
echo 'Executing: ' . $this->process->getCommandLine() . PHP_EOL;
5958
}
60-
$builder->setPrefix("{$path}/phiremock");
61-
$builder->enableOutput();
62-
$builder->setOption('bypass_shell', true);
63-
64-
$this->process = $builder->getProcess();
6559
$logFile = $logsPath . DIRECTORY_SEPARATOR . self::LOG_FILE_NAME;
6660
$this->process->start(function ($type, $buffer) use ($logFile) {
6761
file_put_contents($logFile, $buffer, FILE_APPEND);
6862
});
63+
$this->process->setEnhanceSigchildCompatibility(true);
64+
if ($this->isWindows()) {
65+
$this->process->setEnhanceWindowsCompatibility(true);
66+
}
6967
}
7068

7169
/**
7270
* Stops the process.
7371
*/
7472
public function stop()
7573
{
76-
$this->process->stop(3, SIGTERM);
74+
$this->process->signal(SIGTERM);
75+
$this->process->stop(3, SIGKILL);
7776
}
7877

7978
/**
8079
* @return string
8180
*/
8281
private function getCommandPrefix()
8382
{
84-
if (PHP_OS == 'WIN32' || PHP_OS == 'WINNT' || PHP_OS == 'Windows') {
85-
return '';
86-
}
87-
return 'exec ';
83+
return $this->isWindows() ? '' : 'exec ';
84+
}
85+
86+
private function isWindows()
87+
{
88+
return PHP_OS == 'WIN32' || PHP_OS == 'WINNT' || PHP_OS == 'Windows';
8889
}
8990
}

0 commit comments

Comments
 (0)