Skip to content

Commit 73bb1a3

Browse files
committed
Replace DummyProcess with mocked Process instance.
1 parent 74cbee7 commit 73bb1a3

File tree

4 files changed

+142
-49
lines changed

4 files changed

+142
-49
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@
8989
"padraic/phar-updater": "^1.0"
9090
},
9191
"require-dev": {
92-
"phpunit/phpunit": "^5.7"
92+
"phpunit/phpunit": "^5.7",
93+
"mockery/mockery": "^1.3"
9394
},
9495
"config": {
9596
"platform": {

composer.lock

Lines changed: 113 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Fake/Process/DummyExecute.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,36 @@
1717

1818
class DummyExecute extends Execute
1919
{
20+
private function getMockProcess($cmd)
21+
{
22+
$process = \Mockery::mock('Symfony\Component\Process\Process');
23+
$process->shouldReceive(
24+
'setTimeout',
25+
'run',
26+
'wait',
27+
'stop',
28+
'getExitCode',
29+
'getExitCodeText',
30+
'getWorkingDirectory',
31+
'isOutputDisabled',
32+
'getErrorOutput'
33+
);
34+
35+
$process->shouldReceive('isSuccessful')->andReturn(true);
36+
$process->shouldReceive('getOutput')->andReturn('');
37+
$process->shouldReceive('getCommandLine')->andReturn($cmd);
38+
39+
return $process;
40+
}
41+
2042
public function run($cmd, $error = null)
2143
{
2244
if ($cmd instanceof Process) {
2345
// Get the command line from process.
2446
$cmd = $cmd->getCommandLine();
2547
}
26-
$cmd = new DummyProcess($cmd);
2748

28-
return $this->helper->run($this->output, $cmd, $error);
49+
return $this->helper->run($this->output, $this->getMockProcess($cmd), $error);
2950
}
3051

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

39-
return $this->helper->mustRun($this->output, $cmd, $error);
59+
return $this->helper->mustRun($this->output, $this->getMockProcess($cmd), $error);
4060
}
4161

4262
public function runAll($processes)
@@ -51,15 +71,15 @@ public function mustRunAll($processes)
5171

5272
public function passThrough($commandline, $cwd = null, $timeout = null)
5373
{
54-
return $this->passThroughProcess(new DummyProcess($commandline, $cwd, null, null, $timeout));
74+
return $this->passThroughProcess($this->getMockProcess($commandline));
5575
}
5676

5777
public function passThroughProcess(Process $process)
5878
{
59-
if ($process instanceof DummyProcess) {
79+
if ($process instanceof \Mockery\MockInterface) {
6080
return $process;
6181
}
6282

63-
return new DummyProcess($process->getCommandLine(), $process->getWorkingDirectory(), null, null, $process->getTimeout());
83+
return $this->getMockProcess($process->getCommandLine());
6484
}
6585
}

tests/Fake/Process/DummyProcess.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)