Skip to content

Commit

Permalink
Fixes #18: Do not pass the project as an argument to the 'update' com…
Browse files Browse the repository at this point in the history
…mand
  • Loading branch information
greg-1-anderson authored Mar 14, 2017
2 parents 52f6fab + d407e99 commit 2211ff2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
35 changes: 33 additions & 2 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,34 @@ public function generalCommand($composerCommand, $execPath, $composerArgs, $proj
return $result;
}

/**
* Command handler for commands where the project should not be provided
* as a parameter to Composer (e.g. 'update').
*
* @param string $composerCommand The composer command to run e.g. require
* @param string $execPath The path to composer
* @param array $composerArgs Anything from the global $argv to be passed
* on to Composer
* @param array $projects A list of projects to install, with the key
* specifying the project name, and the value specifying its version.
* @param array $options User options from the command line; see
* $optionDefaultValues in the main() function.
* @return array
*/
public function noProjectArgCommand($composerCommand, $execPath, $composerArgs, $projects, $options)
{
$globalBaseDir = $options['base-dir'];
$binDir = $options['bin-dir'];
$env = array("COMPOSER_BIN_DIR" => $binDir);
$result = array();
foreach ($projects as $project => $version) {
$installLocation = "$globalBaseDir/$project";
$commandToExec = $this->buildGlobalCommand($composerCommand, $execPath, $composerArgs, '', $env, $installLocation);
$result[] = $commandToExec;
}
return $result;
}

/**
* If --stability VALUE is provided, then run a `composer config minimum-stability VALUE`
* command to configure composer.json appropriately.
Expand Down Expand Up @@ -423,7 +451,7 @@ public function updateCommand($execPath, $composerArgs, $projects, $options)
$projects = FileSystemUtils::allInstalledProjectsInBaseDir($options['base-dir']);
$projects = $this->flipProjectsArray($projects);
}
return $this->generalCommand('update', $execPath, $composerArgs, $projects, $options);
return $this->noProjectArgCommand('update', $execPath, $composerArgs, $projects, $options);
}

/**
Expand Down Expand Up @@ -467,7 +495,10 @@ public function projectWithVersion($project, $version)
*/
public function buildGlobalCommand($composerCommand, $execPath, $composerArgs, $projectWithVersion, $env, $installLocation)
{
$projectSpecificArgs = array("--working-dir=$installLocation", $composerCommand, $projectWithVersion);
$projectSpecificArgs = array("--working-dir=$installLocation", $composerCommand);
if (!empty($projectWithVersion)) {
$projectSpecificArgs[] = $projectWithVersion;
}
$arguments = array_merge($composerArgs, $projectSpecificArgs);
return new CommandToExec($execPath, $arguments, $env, $installLocation);
}
Expand Down
10 changes: 5 additions & 5 deletions tests/testCgr.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ public function testApplicationCommandStringsValues()
'd/e',
);
$expectedCgrUpdate = <<<EOT
composer '--working-dir={workdir}/.composer/global/x/y' 'update' 'x/y'
composer '--working-dir={workdir}/.composer/global/a/b' 'update' 'a/b'
composer '--working-dir={workdir}/.composer/global/p/q' 'update' 'p/q'
composer '--working-dir={workdir}/.composer/global/d/e' 'update' 'd/e'
composer '--working-dir={workdir}/.composer/global/x/y' 'update'
composer '--working-dir={workdir}/.composer/global/a/b' 'update'
composer '--working-dir={workdir}/.composer/global/p/q' 'update'
composer '--working-dir={workdir}/.composer/global/d/e' 'update'
EOT;

$argvCgrUpdateWithoutArgs = array(
'cgr',
'update',
);
$expectedCgrUpdateWithoutArgs = <<<EOT
composer '--working-dir={workdir}/.composer/global/testorg/testproject' 'update' 'testorg/testproject'
composer '--working-dir={workdir}/.composer/global/testorg/testproject' 'update'
EOT;

$argvCgrInfo = array(
Expand Down

0 comments on commit 2211ff2

Please sign in to comment.