Skip to content

Commit

Permalink
Using the command line to write log file instead of symfony process c…
Browse files Browse the repository at this point in the history
…allback
  • Loading branch information
mcustiel committed Jan 24, 2018
1 parent bf18a6d commit 8589023
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Extension/PhiremockProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ public function start($ip, $port, $path, $logsPath, $debug, $expectationsPath)
{
$phiremockPath = is_file($path) ? $path : $path . DIRECTORY_SEPARATOR . 'phiremock';
$expectationsPath = is_dir($expectationsPath) ? $expectationsPath : '';

$this->initProcess($ip, $port, $debug, $expectationsPath, $phiremockPath);
$this->logPhiremockCommand($debug);
$logFile = $logsPath . DIRECTORY_SEPARATOR . self::LOG_FILE_NAME;
$this->process->start(function ($type, $buffer) use ($logFile) {
file_put_contents($logFile, $buffer, FILE_APPEND);
});
$this->initProcess($ip, $port, $debug, $expectationsPath, $phiremockPath, $logFile);
$this->logPhiremockCommand($debug);
$this->process->start();
}

/**
Expand All @@ -74,8 +71,9 @@ public function stop()
* @param bool $debug
* @param string $expectationsPath
* @param string $phiremockPath
* @param string $logFile
*/
private function initProcess($ip, $port, $debug, $expectationsPath, $phiremockPath)
private function initProcess($ip, $port, $debug, $expectationsPath, $phiremockPath, $logFile)
{
$commandline = [
$this->getCommandPrefix() . $phiremockPath,
Expand All @@ -91,8 +89,10 @@ private function initProcess($ip, $port, $debug, $expectationsPath, $phiremockPa
$commandline[] = '-e';
$commandline[] = $expectationsPath;
}
$commandline[] = '>';
$commandline[] = $logFile;
$commandline[] = '2>&1';

// Process wraps the command with 'exec' in UNIX OSs.
$this->process = new Process(implode(' ', $commandline));
}

Expand All @@ -119,6 +119,6 @@ private function getCommandPrefix()
*/
private function isWindows()
{
return PHP_OS === 'WIN32' || PHP_OS === 'WINNT' || PHP_OS === 'Windows';
return DIRECTORY_SEPARATOR === '\\';
}
}

0 comments on commit 8589023

Please sign in to comment.