Skip to content

Commit 550f08f

Browse files
committed
Merge pull request consolidation#36 from boedah/bugfix/issue-35-command-is-stripped
Bugfix/issue 35 command is stripped
2 parents cd4a8c5 + bce8ba7 commit 550f08f

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/Task/Shared/CommandStack.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,21 @@ public function exec($command)
2727
$command = implode(' ', array_filter($command));
2828
}
2929

30-
$command = $this->executable . ' ' . trim(ltrim($command, $this->executable));
30+
$command = $this->executable . ' ' . $this->stripExecutableFromCommand($command);
3131
array_push($this->exec, trim($command));
3232
return $this;
3333
}
3434

35+
protected function stripExecutableFromCommand($command)
36+
{
37+
$command = trim($command);
38+
$executable = $this->executable . ' ';
39+
if (strpos($command, $executable) === 0) {
40+
$command = substr($command, strlen($executable));
41+
}
42+
return $command;
43+
}
44+
3545
public function run()
3646
{
3747
if (empty($this->exec)) {

tests/unit/CommandStackTest.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
use Codeception\Util\Stub;
3+
4+
class CommandStackTest extends \Codeception\TestCase\Test
5+
{
6+
public function testExecStackExecutableIsTrimmedFromCommand()
7+
{
8+
$commandStack = Stub::make('Robo\Task\Shared\CommandStack', array(
9+
'executable' => 'some-executable'
10+
));
11+
verify($commandStack
12+
->exec('some-executable status')
13+
->getCommand()
14+
)->equals('some-executable status');
15+
}
16+
17+
public function testExecStackCommandIsNotTrimmedIfHavingSameCharsAsExecutable()
18+
{
19+
$commandStack = Stub::make('Robo\Task\Shared\CommandStack', array(
20+
'executable' => 'some-executable'
21+
));
22+
verify($commandStack
23+
->exec('status')
24+
->getCommand()
25+
)->equals('some-executable status');
26+
}
27+
}

0 commit comments

Comments
 (0)