From 55faaaa8f0a83b3ed12205aa58acea3c4d9daefe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Feb 2017 00:06:57 -0300 Subject: [PATCH] [fs/chmod] Allow to not use flags --- src/Task/BuiltIn/FS/ChangeModeTask.php | 10 +++++--- tests/Task/BuiltIn/ChangeModeTaskTest.php | 30 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/Task/BuiltIn/FS/ChangeModeTask.php b/src/Task/BuiltIn/FS/ChangeModeTask.php index 3ad05ba..2f5c5bd 100644 --- a/src/Task/BuiltIn/FS/ChangeModeTask.php +++ b/src/Task/BuiltIn/FS/ChangeModeTask.php @@ -28,7 +28,11 @@ class ChangeModeTask extends AbstractFileTask public function getDescription() { try { - return sprintf('[FS] Change mode of "%s" to "%s" with flags "%s"', $this->getFile('file'), $this->options['mode'], $this->options['flags']); + $description = sprintf('[FS] Change mode of "%s" to "%s"', $this->getFile('file'), $this->options['mode']); + if ($this->options['flags'] != null) { + $description = sprintf('[FS] Change mode of "%s" to "%s" with flags "%s"', $this->getFile('file'), $this->options['mode'], $this->options['flags']); + } + return $description; } catch (Exception $exception) { return '[FS] Chmod [missing parameters]'; } @@ -36,9 +40,7 @@ class ChangeModeTask extends AbstractFileTask public function execute() { - $file = $this->getFile('file'); - - $cmd = sprintf('chmod %s %s %s', $this->options['flags'], $this->options['mode'], $file); + $cmd = sprintf('chmod %s %s %s', $this->options['flags'], $this->options['mode'], $this->getFile('file')); /** @var Process $process */ $process = $this->runtime->runCommand($cmd); diff --git a/tests/Task/BuiltIn/ChangeModeTaskTest.php b/tests/Task/BuiltIn/ChangeModeTaskTest.php index 5408339..d0481a6 100644 --- a/tests/Task/BuiltIn/ChangeModeTaskTest.php +++ b/tests/Task/BuiltIn/ChangeModeTaskTest.php @@ -48,6 +48,36 @@ class ChangeModeTest extends TestCase } } + public function testChangeModeTaskWithoutFlags() + { + $runtime = new RuntimeMockup(); + $runtime->setConfiguration(['environments' => ['test' => []]]); + $runtime->setEnvironment('test'); + + $task = new ChangeModeTask(); + $task->setOptions(['file' => 'a.txt', 'mode' => 'o+w']); + $task->setRuntime($runtime); + + $this->assertContains('a.txt', $task->getDescription()); + $this->assertNotContains('-R', $task->getDescription()); + $this->assertContains('o+w', $task->getDescription()); + $task->execute(); + + $ranCommands = $runtime->getRanCommands(); + + $testCase = array( + 0 => 'chmod o+w a.txt', + ); + + // Check total of Executed Commands + $this->assertEquals(count($testCase), count($ranCommands)); + + // Check Generated Commands + foreach ($testCase as $index => $command) { + $this->assertEquals($command, $ranCommands[$index]); + } + } + public function testChangeModeReplaceTask() { $runtime = new RuntimeMockup();