mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01:00 
			
		
		
		
	[Nostromo] Refactor Composer SelfUpdate
This commit is contained in:
		
							parent
							
								
									f7448e39e7
								
							
						
					
					
						commit
						67c3a23bbb
					
				@ -52,7 +52,7 @@ class SelfUpdateTask extends AbstractTask
 | 
				
			|||||||
            throw new SkipException();
 | 
					            throw new SkipException();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $cmdUpdate = sprintf('%s self-update %s', $options['path'], $options['version']);
 | 
					        $cmdUpdate = sprintf('%s self-update', $options['path']);
 | 
				
			||||||
        /** @var Process $process */
 | 
					        /** @var Process $process */
 | 
				
			||||||
        $process = $this->runtime->runCommand(trim($cmdUpdate));
 | 
					        $process = $this->runtime->runCommand(trim($cmdUpdate));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -83,7 +83,7 @@ class SelfUpdateTask extends AbstractTask
 | 
				
			|||||||
    protected function getOptions()
 | 
					    protected function getOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $options = array_merge(
 | 
					        $options = array_merge(
 | 
				
			||||||
            ['path' => 'composer', 'version' => '', 'days' => 60],
 | 
					            ['path' => 'composer', 'days' => 60],
 | 
				
			||||||
            $this->runtime->getMergedOption('composer'),
 | 
					            $this->runtime->getMergedOption('composer'),
 | 
				
			||||||
            $this->options
 | 
					            $this->options
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
				
			|||||||
@ -104,40 +104,6 @@ class SelfUpdateTaskTest extends TestCase
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function testSelfUpdateMustUpdateToVersionTask()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					 | 
				
			||||||
        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
					 | 
				
			||||||
        $runtime->setEnvironment('test');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $task = new SelfUpdateTask();
 | 
					 | 
				
			||||||
        $task->setOptions(['path' => 'composer.phar', 'version' => '1.2.0']);
 | 
					 | 
				
			||||||
        $task->setRuntime($runtime);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            $result = $task->execute();
 | 
					 | 
				
			||||||
            $this->assertTrue($result, 'Result should be successful');
 | 
					 | 
				
			||||||
        } catch (Exception $exception) {
 | 
					 | 
				
			||||||
            if ($exception instanceof SkipException) {
 | 
					 | 
				
			||||||
                $this->assertTrue(false, 'Update should not have been skipped');
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $ranCommands = $runtime->getRanCommands();
 | 
					 | 
				
			||||||
        $testCase = array(
 | 
					 | 
				
			||||||
            0 => 'composer.phar --version',
 | 
					 | 
				
			||||||
            1 => 'composer.phar self-update 1.2.0',
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // 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 testSelfUpdateWrongOutputTask()
 | 
					    public function testSelfUpdateWrongOutputTask()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user