Skip to content

Commit

Permalink
Merge 9e54436 into c372743
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Jan 16, 2019
2 parents c372743 + 9e54436 commit 2537483
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/CosyComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -781,10 +781,10 @@ public function run()
if ($update_with_deps) {
$with_dep_suffix = '--update-with-dependencies';
}
$command = sprintf('COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_DISCARD_CHANGES=true composer --no-ansi --ignore-platform-reqs %s %s:%s%s %s', $req_command, $package_name, $constraint, $version_to, $with_dep_suffix);
$command = sprintf('COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_DISCARD_CHANGES=true composer --no-ansi %s %s:%s%s %s', $req_command, $package_name, $constraint, $version_to, $with_dep_suffix);
$this->execCommand($command, false, 600);
} else {
$command = sprintf('COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_DISCARD_CHANGES=true composer --no-ansi --ignore-platform-reqs update -n --no-scripts %s %s', $package_name, $with_dep_suffix);
$command = sprintf('COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_DISCARD_CHANGES=true composer --no-ansi update -n --no-scripts %s %s', $package_name, $with_dep_suffix);
$this->log('Running composer update for package ' . $package_name);
// If exit code is not 0, there was a problem.
if ($this->execCommand($command, false, 600)) {
Expand Down Expand Up @@ -981,7 +981,7 @@ public function setOutput(OutputInterface $output)
private function cleanUp()
{
// Run composer install again, so we can get rid of newly installed updates for next run.
$this->execCommand('COMPOSER_DISCARD_CHANGES=true COMPOSER_ALLOW_SUPERUSER=1 composer install --ignore-platform-reqs --no-ansi -n --no-scripts', false, 1200);
$this->execCommand('COMPOSER_DISCARD_CHANGES=true COMPOSER_ALLOW_SUPERUSER=1 composer install --no-ansi -n --no-scripts', false, 1200);
$this->chdir('/tmp');
$this->log('Cleaning up after update check.');
$this->log('Storing custom composer cache for later');
Expand Down
28 changes: 10 additions & 18 deletions test/integration/UpdatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@ private function createUpdateJsonFromData($package, $version, $new_version)
return sprintf('{"installed": [{"name": "%s", "version": "%s", "latest": "%s", "latest-status": "semver-safe-update"}]}', $package, $version, $new_version);
}

private function createExpectedCommandForPackageUpdate($package, $update_with_dependencies = true)
private function createExpectedCommandForPackage($package)
{
$with_deps = $update_with_dependencies ? '--with-dependencies' : '';
return "COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_DISCARD_CHANGES=true composer --no-ansi --ignore-platform-reqs update -n --no-scripts $package $with_deps";
}

private function createExpectedCommandForPackageRequire($package, $constraint)
{
return "COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_DISCARD_CHANGES=true composer --no-ansi --ignore-platform-reqs require $package:$constraint --update-with-dependencies";
return "COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_DISCARD_CHANGES=true composer --no-ansi update -n --no-scripts $package --with-dependencies";
}

public function testUpdatesFoundButProviderDoesNotAuthenticate()
Expand Down Expand Up @@ -309,7 +303,7 @@ public function testUpdatesFoundButComposerUpdateFails()
->will($this->returnCallback(
function ($cmd) use (&$called, &$composer_update_called) {
$return = 0;
if ($cmd == $this->createExpectedCommandForPackageUpdate('psr/log')) {
if ($cmd == 'COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_DISCARD_CHANGES=true composer --no-ansi update -n --no-scripts psr/log --with-dependencies') {
$composer_update_called = true;
$return = 1;
}
Expand Down Expand Up @@ -449,7 +443,7 @@ public function testUpdatesRunButErrorCommiting()
->will($this->returnCallback(
function ($cmd) use (&$called, $dir) {
$return = 0;
if ($cmd == $this->createExpectedCommandForPackageUpdate('psr/log')) {
if ($cmd == 'COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_DISCARD_CHANGES=true composer --no-ansi update -n --no-scripts psr/log --with-dependencies') {
file_put_contents("$dir/composer.lock", file_get_contents(__DIR__ . '/../fixtures/composer-psr-log.lock-updated'));
}
if ($cmd == 'GIT_AUTHOR_NAME="" GIT_AUTHOR_EMAIL="" GIT_COMMITTER_NAME="" GIT_COMMITTER_EMAIL="" git commit composer.* -m "Update psr/log"') {
Expand Down Expand Up @@ -522,7 +516,7 @@ public function testUpdatesRunButErrorPushing()
->will($this->returnCallback(
function ($cmd) use (&$called, $dir) {
$return = 0;
if ($cmd == $this->createExpectedCommandForPackageUpdate('psr/log')) {
if ($cmd == 'COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_DISCARD_CHANGES=true composer --no-ansi update -n --no-scripts psr/log --with-dependencies') {
file_put_contents("$dir/composer.lock", file_get_contents(__DIR__ . '/../fixtures/composer-psr-log.lock-updated'));
}
if ($cmd == 'git push origin psrlog100102 --force') {
Expand Down Expand Up @@ -595,7 +589,7 @@ public function testEndToEnd()
->will($this->returnCallback(
function ($cmd) use (&$called, $dir) {
$return = 0;
if ($cmd == $this->createExpectedCommandForPackageUpdate('psr/log')) {
if ($cmd == 'COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_DISCARD_CHANGES=true composer --no-ansi update -n --no-scripts psr/log --with-dependencies') {
file_put_contents("$dir/composer.lock", file_get_contents(__DIR__ . '/../fixtures/composer-psr-log.lock-updated'));
}
if (strpos($cmd, 'rm -rf /tmp/') === 0) {
Expand Down Expand Up @@ -670,7 +664,7 @@ public function testEndToEndNotPrivate()
->will($this->returnCallback(
function ($cmd) use (&$called, $dir) {
$return = 0;
if ($cmd == $this->createExpectedCommandForPackageUpdate('psr/log')) {
if ($cmd == 'COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_DISCARD_CHANGES=true composer --no-ansi update -n --no-scripts psr/log --with-dependencies') {
file_put_contents("$dir/composer.lock", file_get_contents(__DIR__ . '/../fixtures/composer-psr-log.lock-updated'));
}
if (strpos($cmd, 'rm -rf /tmp/') === 0) {
Expand Down Expand Up @@ -748,8 +742,7 @@ public function testUpdatesFoundButNotSemverValidButStillAllowed()
$mock_executer->method('executeCommand')
->will($this->returnCallback(
function ($cmd) use (&$called, &$install_called, $dir) {
$expected_command = $this->createExpectedCommandForPackageRequire('psr/log', '^2.0.1');
if ($cmd == $expected_command) {
if ($cmd == 'COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_DISCARD_CHANGES=true composer --no-ansi require psr/log:^2.0.1 --update-with-dependencies') {
$install_called = true;
file_put_contents("$dir/composer.lock", file_get_contents(__DIR__ . '/../fixtures/composer-psr-log.lock-updated'));
}
Expand Down Expand Up @@ -818,8 +811,7 @@ public function testEndToEndButNotUpdatedWithDependencies()
$mock_executer = $this->getMockExecuterWithReturnCallback(
function ($cmd) use (&$called, $dir) {
$return = 0;
$expected_command = $this->createExpectedCommandForPackageUpdate('psr/log', false);
if (strpos($cmd, $expected_command) === 0) {
if ($cmd == 'COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_DISCARD_CHANGES=true composer --no-ansi update -n --no-scripts psr/log ') {
file_put_contents("$dir/composer.lock", file_get_contents(__DIR__ . '/../fixtures/composer-psr-log.lock-updated'));
}
if (strpos($cmd, 'rm -rf /tmp/') === 0) {
Expand Down Expand Up @@ -892,7 +884,7 @@ public function testUpdateAvailableButUpdatedToOther()
$mock_executer = $this->getMockExecuterWithReturnCallback(
function ($cmd) use (&$called, $dir) {
$return = 0;
$expected_command = $this->createExpectedCommandForPackageUpdate('drupal/core');
$expected_command = $this->createExpectedCommandForPackage('drupal/core');
if ($cmd == $expected_command) {
file_put_contents("$dir/composer.lock", file_get_contents(__DIR__ . '/../fixtures/composer-drupal-847-updated.lock'));
}
Expand Down

0 comments on commit 2537483

Please sign in to comment.