Skip to content

Commit

Permalink
Remove extra space from resulting command; Add omitErrors to build co…
Browse files Browse the repository at this point in the history
…mmand unit test
  • Loading branch information
kstkn committed Mar 29, 2020
1 parent e97bac5 commit bb19640
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ protected function runCommandInForeground(Application $app)
*/
public function buildCommand()
{
$command = $this->command . $this->_redirect . $this->_output . ' ' . (($this->_omitErrors) ? ' 2>&1 &' : '');
$command = $this->command . $this->_redirect . $this->_output . (($this->_omitErrors) ? ' 2>&1 &' : '');
return $this->_user ? 'sudo -u ' . $this->_user . ' ' . $command : $command;
}

Expand Down
16 changes: 10 additions & 6 deletions tests/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ class EventTest extends \PHPUnit_Framework_TestCase
public function buildCommandData()
{
return [
['php -i', '/dev/null', "php -i > /dev/null &"],
['php -i', '/my folder/foo.log', "php -i > /my folder/foo.log &"],
[false, 'php -i', '/dev/null', 'php -i > /dev/null'],
[false, 'php -i', '/my folder/foo.log', 'php -i > /my folder/foo.log'],
[true, 'php -i', '/dev/null', 'php -i > /dev/null 2>&1 &'],
[true, 'php -i', '/my folder/foo.log', 'php -i > /my folder/foo.log 2>&1 &'],
];
}

/**
* @dataProvider buildCommandData
* @param $command
* @param $outputTo
* @param $result
* @param bool $omitErrors
* @param string $command
* @param string $outputTo
* @param string $result
*/
public function testBuildCommandSendOutputTo($command, $outputTo, $result)
public function testBuildCommandSendOutputTo($omitErrors, $command, $outputTo, $result)
{
$event = new Event($this->getMock(Mutex::className()), $command);
$event->omitErrors($omitErrors);
$event->sendOutputTo($outputTo);
$this->assertSame($result, $event->buildCommand());
}
Expand Down

0 comments on commit bb19640

Please sign in to comment.