[Nostromo] Refactor Composer SelfUpdate

This commit is contained in:
Andrés Montañez 2017-02-11 01:53:22 -03:00
parent d8f2359d12
commit f7448e39e7
3 changed files with 37 additions and 2 deletions

View file

@ -2,6 +2,7 @@ CHANGELOG for 3.x
=================
* 3.0.X (2017-XX-XX)
* Add new Composer task, to update phar (composer/self-update)
* [#344] Allow to flag Filesystem tasks
* [PR#346] Add new File System task, to change file's modes (fs/chmod)
* [BUGFIX] [PR#342] Ignore empty exclude lines

View file

@ -52,7 +52,7 @@ class SelfUpdateTask extends AbstractTask
throw new SkipException();
}
$cmdUpdate = sprintf('%s self-update %s', $options['path'], $options['release']);
$cmdUpdate = sprintf('%s self-update %s', $options['path'], $options['version']);
/** @var Process $process */
$process = $this->runtime->runCommand(trim($cmdUpdate));
@ -83,7 +83,7 @@ class SelfUpdateTask extends AbstractTask
protected function getOptions()
{
$options = array_merge(
['path' => 'composer', 'release' => '', 'days' => 60],
['path' => 'composer', 'version' => '', 'days' => 60],
$this->runtime->getMergedOption('composer'),
$this->options
);

View file

@ -104,6 +104,40 @@ 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()
{
$runtime = new RuntimeMockup();