Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #23 from niels-nijens/retrieve-process-execution-r…
Browse files Browse the repository at this point in the history
…esult

Add ProcessExecutor::getLastProcessExecutionResult
  • Loading branch information
niels-nijens committed May 13, 2016
2 parents 2a7177d + ff62ba4 commit d393b64
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Process/ProcessExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
*/
class ProcessExecutor implements ProcessExecutorInterface
{
/**
* The ProcessExecutionResult instance of the last executed command.
*
* @var ProcessExecutionResult
*/
private $lastProcessExecutionResult;

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -42,6 +49,16 @@ public function execute($command, $workingDirectory = null)
$process->setTimeout(300);
$process->run();

return new ProcessExecutionResult($process->getExitCode(), $process->getOutput(), $process->getErrorOutput());
$this->lastProcessExecutionResult = new ProcessExecutionResult($process->getExitCode(), $process->getOutput(), $process->getErrorOutput());

return $this->lastProcessExecutionResult;
}

/**
* {@inheritdoc}
*/
public function getLastProcessExecutionResult()
{
return $this->lastProcessExecutionResult;
}
}
7 changes: 7 additions & 0 deletions src/Process/ProcessExecutorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ public function isDirectory($path);
* @return ProcessExecutionResult
*/
public function execute($command, $workingDirectory = null);

/**
* Returns the ProcessExecutionResult instance of the last executed command.
*
* @return ProcessExecutionResult
*/
public function getLastProcessExecutionResult();
}
11 changes: 11 additions & 0 deletions tests/Process/ProcessExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,15 @@ public function testExecute()
$this->assertSame('test'.PHP_EOL, $processExecutionResult->getOutput());
$this->assertEquals('', $processExecutionResult->getErrorOutput());
}

/**
* Tests if ProcessExecutor::getLastProcessExecutionResult returns the same ProcessExecutionResult instance as ProcessExecutor::execute.
*/
public function testGetLastProcessExecutionResult()
{
$processExecutor = new ProcessExecutor();
$processExecutionResult = $processExecutor->execute('echo test');

$this->assertSame($processExecutionResult, $processExecutor->getLastProcessExecutionResult());
}
}

0 comments on commit d393b64

Please sign in to comment.