Skip to content

Commit cb5537a

Browse files
drudoimcustiel
authored andcommitted
Issue #16: Log file is not created with PCNTL disabled (#18)
1 parent 9ba67a2 commit cb5537a

File tree

2 files changed

+23
-58
lines changed

2 files changed

+23
-58
lines changed

composer.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@
2626
"type" : "project",
2727
"description" : "Codeception extension for PhireMock. Allows to stub remote services for HTTP requests.",
2828
"license" : "GPL-3.0+",
29-
"require" : {
29+
"require" : {
3030
"php" : ">=5.6",
3131
"mcustiel/phiremock": "^1.3",
3232
"codeception/codeception" : "^2.0",
33-
"symfony/process": "^3.1|^2.7.15"
34-
},
35-
"suggest" : {
36-
"ext-pcntl" : "Allows phiremock-codeception-extension to send system signals to phiremock process"
33+
"symfony/process": "^3.3"
3734
}
3835
}

src/Extension/PhiremockProcess.php

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,20 @@ public function start($ip, $port, $path, $logsPath, $debug, $expectationsPath)
5252
$phiremockPath = is_file($path) ? $path : $path . DIRECTORY_SEPARATOR . 'phiremock';
5353
$expectationsPath = is_dir($expectationsPath) ? $expectationsPath : '';
5454

55-
$this->logPhiremockCommand($ip, $port, $debug, $expectationsPath, $phiremockPath);
5655
$this->initProcess($ip, $port, $debug, $expectationsPath, $phiremockPath);
56+
$this->logPhiremockCommand($debug);
5757
$logFile = $logsPath . DIRECTORY_SEPARATOR . self::LOG_FILE_NAME;
5858
$this->process->start(function ($type, $buffer) use ($logFile) {
5959
file_put_contents($logFile, $buffer, FILE_APPEND);
6060
});
61-
$this->setUpProcessCompatibility();
6261
}
6362

6463
/**
6564
* Stops the process.
6665
*/
6766
public function stop()
6867
{
69-
if ($this->isPcntlEnabled()) {
70-
$this->process->signal(SIGTERM);
71-
$this->process->stop(3, SIGKILL);
72-
}
73-
}
74-
75-
private function setUpProcessCompatibility()
76-
{
77-
$this->process->setEnhanceSigchildCompatibility(true);
78-
if ($this->isWindows()) {
79-
$this->process->setEnhanceWindowsCompatibility(true);
80-
}
68+
$this->process->stop(3);
8169
}
8270

8371
/**
@@ -89,52 +77,32 @@ private function setUpProcessCompatibility()
8977
*/
9078
private function initProcess($ip, $port, $debug, $expectationsPath, $phiremockPath)
9179
{
92-
$this->process = new Process(
93-
$this->getCommandPrefix()
94-
. "{$phiremockPath} -i {$ip} -p {$port}"
95-
. ($debug ? ' -d' : '')
96-
. ($expectationsPath ? " -e {$expectationsPath}" : '')
97-
);
98-
}
99-
100-
/**
101-
* @param string $ip
102-
* @param int $port
103-
* @param bool $debug
104-
* @param string $expectationsPath
105-
* @param string $phiremockPath
106-
*/
107-
private function logPhiremockCommand($ip, $port, $debug, $expectationsPath, $phiremockPath)
108-
{
80+
$commandline = [
81+
$phiremockPath,
82+
'-i',
83+
$ip,
84+
'-p',
85+
$port
86+
];
10987
if ($debug) {
110-
echo 'Running ' . $this->getCommandPrefix()
111-
. "{$phiremockPath} -i {$ip} -p {$port}"
112-
. ($debug ? ' -d' : '')
113-
. ($expectationsPath ? " -e {$expectationsPath}" : '') . PHP_EOL;
88+
$commandline[] = '-d';
89+
}
90+
if ($expectationsPath) {
91+
$commandline[] = '-e';
92+
$commandline[] = $expectationsPath;
11493
}
115-
}
116-
117-
/**
118-
* @return string
119-
*/
120-
private function getCommandPrefix()
121-
{
122-
return $this->isWindows() ? '' : 'exec ';
123-
}
12494

125-
/**
126-
* @return bool
127-
*/
128-
private function isWindows()
129-
{
130-
return PHP_OS === 'WIN32' || PHP_OS === 'WINNT' || PHP_OS === 'Windows';
95+
// Process wraps the command with 'exec' in UNIX OSs.
96+
$this->process = new Process($commandline);
13197
}
13298

13399
/**
134-
* @return bool
100+
* @param bool $debug
135101
*/
136-
private function isPcntlEnabled()
102+
private function logPhiremockCommand($debug)
137103
{
138-
return !$this->isWindows() && defined('SIGTERM');
104+
if ($debug) {
105+
echo 'Running ' . $this->process->getCommandLine() . PHP_EOL;
106+
}
139107
}
140108
}

0 commit comments

Comments
 (0)