Skip to content

Commit

Permalink
Replace DummyProcess with mocked Process instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
kabalin committed Feb 3, 2021
1 parent 74cbee7 commit 73bb1a3
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 49 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
"padraic/phar-updater": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7"
"phpunit/phpunit": "^5.7",
"mockery/mockery": "^1.3"
},
"config": {
"platform": {
Expand Down
114 changes: 113 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 27 additions & 7 deletions tests/Fake/Process/DummyExecute.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,36 @@

class DummyExecute extends Execute
{
private function getMockProcess($cmd)
{
$process = \Mockery::mock('Symfony\Component\Process\Process');
$process->shouldReceive(
'setTimeout',
'run',
'wait',
'stop',
'getExitCode',
'getExitCodeText',
'getWorkingDirectory',
'isOutputDisabled',
'getErrorOutput'
);

$process->shouldReceive('isSuccessful')->andReturn(true);
$process->shouldReceive('getOutput')->andReturn('');
$process->shouldReceive('getCommandLine')->andReturn($cmd);

return $process;
}

public function run($cmd, $error = null)
{
if ($cmd instanceof Process) {
// Get the command line from process.
$cmd = $cmd->getCommandLine();
}
$cmd = new DummyProcess($cmd);

return $this->helper->run($this->output, $cmd, $error);
return $this->helper->run($this->output, $this->getMockProcess($cmd), $error);
}

public function mustRun($cmd, $error = null)
Expand All @@ -34,9 +55,8 @@ public function mustRun($cmd, $error = null)
// Get the command line from process.
$cmd = $cmd->getCommandLine();
}
$cmd = new DummyProcess($cmd);

return $this->helper->mustRun($this->output, $cmd, $error);
return $this->helper->mustRun($this->output, $this->getMockProcess($cmd), $error);
}

public function runAll($processes)
Expand All @@ -51,15 +71,15 @@ public function mustRunAll($processes)

public function passThrough($commandline, $cwd = null, $timeout = null)
{
return $this->passThroughProcess(new DummyProcess($commandline, $cwd, null, null, $timeout));
return $this->passThroughProcess($this->getMockProcess($commandline));
}

public function passThroughProcess(Process $process)
{
if ($process instanceof DummyProcess) {
if ($process instanceof \Mockery\MockInterface) {
return $process;
}

return new DummyProcess($process->getCommandLine(), $process->getWorkingDirectory(), null, null, $process->getTimeout());
return $this->getMockProcess($process->getCommandLine());
}
}
40 changes: 0 additions & 40 deletions tests/Fake/Process/DummyProcess.php

This file was deleted.

0 comments on commit 73bb1a3

Please sign in to comment.