mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01:00 
			
		
		
		
	[fs/chmod] Allow to not use flags
This commit is contained in:
		
							parent
							
								
									abf10b05f8
								
							
						
					
					
						commit
						55faaaa8f0
					
				@ -28,7 +28,11 @@ class ChangeModeTask extends AbstractFileTask
 | 
				
			|||||||
    public function getDescription()
 | 
					    public function getDescription()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        try {
 | 
					        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) {
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
            return '[FS] Chmod [missing parameters]';
 | 
					            return '[FS] Chmod [missing parameters]';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -36,9 +40,7 @@ class ChangeModeTask extends AbstractFileTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function execute()
 | 
					    public function execute()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $file = $this->getFile('file');
 | 
					        $cmd = sprintf('chmod %s %s %s', $this->options['flags'], $this->options['mode'], $this->getFile('file'));
 | 
				
			||||||
 | 
					 | 
				
			||||||
        $cmd = sprintf('chmod %s %s %s', $this->options['flags'], $this->options['mode'], $file);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /** @var Process $process */
 | 
					        /** @var Process $process */
 | 
				
			||||||
        $process = $this->runtime->runCommand($cmd);
 | 
					        $process = $this->runtime->runCommand($cmd);
 | 
				
			||||||
 | 
				
			|||||||
@ -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()
 | 
					    public function testChangeModeReplaceTask()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user