Browse Source

Fix calculation of lock transaction updates and start updating output in tests

Nils Adermann 5 years ago
parent
commit
06d11f2f38

+ 3 - 2
src/Composer/DependencyResolver/LocalRepoTransaction.php

@@ -12,6 +12,8 @@
 
 
 namespace Composer\DependencyResolver;
 namespace Composer\DependencyResolver;
 
 
+use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
+use Composer\DependencyResolver\Operation\UninstallOperation;
 use Composer\Package\AliasPackage;
 use Composer\Package\AliasPackage;
 use Composer\Repository\PlatformRepository;
 use Composer\Repository\PlatformRepository;
 use Composer\Repository\RepositoryInterface;
 use Composer\Repository\RepositoryInterface;
@@ -86,7 +88,6 @@ class LocalRepoTransaction
         $operations = $this->movePluginsToFront($operations);
         $operations = $this->movePluginsToFront($operations);
         $operations = $this->moveUninstallsToFront($operations);
         $operations = $this->moveUninstallsToFront($operations);
 
 
-
         // TODO skip updates which don't update? is this needed? we shouldn't schedule this update in the first place?
         // TODO skip updates which don't update? is this needed? we shouldn't schedule this update in the first place?
         /*
         /*
         if ('update' === $jobType) {
         if ('update' === $jobType) {
@@ -175,7 +176,7 @@ class LocalRepoTransaction
     {
     {
         $uninstOps = array();
         $uninstOps = array();
         foreach ($operations as $idx => $op) {
         foreach ($operations as $idx => $op) {
-            if ($op instanceof UninstallOperation) {
+            if ($op instanceof UninstallOperation || $op instanceof MarkAliasUninstalledOperation) {
                 $uninstOps[] = $op;
                 $uninstOps[] = $op;
                 unset($operations[$idx]);
                 unset($operations[$idx]);
             }
             }

+ 1 - 1
src/Composer/DependencyResolver/LockTransaction.php

@@ -78,8 +78,8 @@ class LockTransaction
                     $operations[] = new Operation\UpdateOperation($lockMeansUpdateMap[abs($literal)], $package, $reason);
                     $operations[] = new Operation\UpdateOperation($lockMeansUpdateMap[abs($literal)], $package, $reason);
 
 
                     // avoid updates to one package from multiple origins
                     // avoid updates to one package from multiple origins
+                    $ignoreRemove[$lockMeansUpdateMap[abs($literal)]->id] = true;
                     unset($lockMeansUpdateMap[abs($literal)]);
                     unset($lockMeansUpdateMap[abs($literal)]);
-                    $ignoreRemove[$source->id] = true;
                 } else {
                 } else {
                     if ($package instanceof AliasPackage) {
                     if ($package instanceof AliasPackage) {
                         $operations[] = new Operation\MarkAliasInstalledOperation($package, $reason);
                         $operations[] = new Operation\MarkAliasInstalledOperation($package, $reason);

+ 1 - 1
src/Composer/DependencyResolver/Request.php

@@ -90,7 +90,7 @@ class Request
         $presentMap = array();
         $presentMap = array();
 
 
         if ($this->lockedRepository) {
         if ($this->lockedRepository) {
-            foreach ($this->lockedRepository as $package) {
+            foreach ($this->lockedRepository->getPackages() as $package) {
                 $presentMap[$package->id] = $package;
                 $presentMap[$package->id] = $package;
             }
             }
         }
         }

+ 25 - 26
src/Composer/Installer.php

@@ -351,7 +351,7 @@ class Installer
         }
         }
         // TODO can we drop any locked packages that we have matching remote versions for?
         // TODO can we drop any locked packages that we have matching remote versions for?
 
 
-        $request = $this->createRequest($this->fixedRootPackage, $platformRepo);
+        $request = $this->createRequest($this->fixedRootPackage, $platformRepo, $lockedRepository);
 
 
         if ($lockedRepository) {
         if ($lockedRepository) {
             // TODO do we really always need this? Maybe only to skip fix() in updateWhitelist case cause these packages get removed on full update automatically?
             // TODO do we really always need this? Maybe only to skip fix() in updateWhitelist case cause these packages get removed on full update automatically?
@@ -422,23 +422,6 @@ class Installer
         $platformReqs = $this->extractPlatformRequirements($this->package->getRequires());
         $platformReqs = $this->extractPlatformRequirements($this->package->getRequires());
         $platformDevReqs = $this->extractPlatformRequirements($this->package->getDevRequires());
         $platformDevReqs = $this->extractPlatformRequirements($this->package->getDevRequires());
 
 
-        $updatedLock = $this->locker->setLockData(
-            $lockTransaction->getNewLockNonDevPackages(),
-            $lockTransaction->getNewLockDevPackages(),
-            $platformReqs,
-            $platformDevReqs,
-            $aliases,
-            $this->package->getMinimumStability(),
-            $this->package->getStabilityFlags(),
-            $this->preferStable || $this->package->getPreferStable(),
-            $this->preferLowest,
-            $this->config->get('platform') ?: array(),
-            $this->writeLock && $this->executeOperations
-        );
-        if ($updatedLock && $this->writeLock && $this->executeOperations) {
-            $this->io->writeError('<info>Writing lock file</info>');
-        }
-
         if ($lockTransaction->getOperations()) {
         if ($lockTransaction->getOperations()) {
             $installs = $updates = $uninstalls = array();
             $installs = $updates = $uninstalls = array();
             foreach ($lockTransaction->getOperations() as $operation) {
             foreach ($lockTransaction->getOperations() as $operation) {
@@ -501,7 +484,22 @@ class Installer
             }
             }
         }
         }
 
 
-        $this->io->write('foo');
+        $updatedLock = $this->locker->setLockData(
+            $lockTransaction->getNewLockNonDevPackages(),
+            $lockTransaction->getNewLockDevPackages(),
+            $platformReqs,
+            $platformDevReqs,
+            $aliases,
+            $this->package->getMinimumStability(),
+            $this->package->getStabilityFlags(),
+            $this->preferStable || $this->package->getPreferStable(),
+            $this->preferLowest,
+            $this->config->get('platform') ?: array(),
+            $this->writeLock && $this->executeOperations
+        );
+        if ($updatedLock && $this->writeLock && $this->executeOperations) {
+            $this->io->writeError('<info>Writing lock file</info>');
+        }
 
 
         if ($doInstall) {
         if ($doInstall) {
             // TODO ensure lock is used from locker as-is, since it may not have been written to disk in case of executeOperations == false
             // TODO ensure lock is used from locker as-is, since it may not have been written to disk in case of executeOperations == false
@@ -530,7 +528,7 @@ class Installer
         $repositorySet = $this->createRepositorySet($platformRepo, $aliases, $lockedRepository);
         $repositorySet = $this->createRepositorySet($platformRepo, $aliases, $lockedRepository);
         $repositorySet->addRepository($lockedRepository);
         $repositorySet->addRepository($lockedRepository);
 
 
-        $this->io->writeError('<info>Installing dependencies'.($this->devMode ? ' (including require-dev)' : '').' from lock file</info>');
+        $this->io->writeError('<info>Installing dependencies from lock file'.($this->devMode ? ' (including require-dev)' : '').'</info>');
 
 
         // verify that the lock file works with the current platform repository
         // verify that the lock file works with the current platform repository
         // we can skip this part if we're doing this as the second step after an update
         // we can skip this part if we're doing this as the second step after an update
@@ -538,7 +536,7 @@ class Installer
             $this->io->writeError('<info>Verifying lock file contents can be installed on current platform.</info>');
             $this->io->writeError('<info>Verifying lock file contents can be installed on current platform.</info>');
 
 
             // creating requirements request
             // creating requirements request
-            $request = $this->createRequest($this->fixedRootPackage, $platformRepo);
+            $request = $this->createRequest($this->fixedRootPackage, $platformRepo, $lockedRepository);
 
 
             if (!$this->locker->isFresh()) {
             if (!$this->locker->isFresh()) {
                 $this->io->writeError('<warning>Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.</warning>', true, IOInterface::QUIET);
                 $this->io->writeError('<warning>Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.</warning>', true, IOInterface::QUIET);
@@ -627,7 +625,7 @@ class Installer
             }
             }
 
 
             // output op, but alias op only in debug verbosity
             // output op, but alias op only in debug verbosity
-            if (false === strpos($operation->getJobType(), 'Alias') || $this->io->isDebug()) {
+            if ((!$this->executeOperations && false === strpos($operation->getJobType(), 'Alias')) || $this->io->isDebug()) {
                 $this->io->writeError('  - ' . $operation);
                 $this->io->writeError('  - ' . $operation);
             }
             }
 
 
@@ -736,13 +734,14 @@ class Installer
     }
     }
 
 
     /**
     /**
-     * @param  RootPackageInterface $rootPackage
-     * @param  PlatformRepository   $platformRepo
+     * @param RootPackageInterface $rootPackage
+     * @param PlatformRepository   $platformRepo
+     * @param RepositoryInterface|null $lockedRepository
      * @return Request
      * @return Request
      */
      */
-    private function createRequest(RootPackageInterface $rootPackage, PlatformRepository $platformRepo)
+    private function createRequest(RootPackageInterface $rootPackage, PlatformRepository $platformRepo, $lockedRepository = null)
     {
     {
-        $request = new Request();
+        $request = new Request($lockedRepository);
 
 
         $request->fixPackage($rootPackage, false);
         $request->fixPackage($rootPackage, false);
 
 

+ 1 - 1
tests/Composer/Test/Fixtures/installer/broken-deps-do-not-replace.test

@@ -22,7 +22,7 @@ Broken dependencies should not lead to a replacer being installed which is not m
 install
 install
 --EXPECT-OUTPUT--
 --EXPECT-OUTPUT--
 Loading composer repositories with package information
 Loading composer repositories with package information
-Updating dependencies (including require-dev)
+Updating dependencies
 Your requirements could not be resolved to an installable set of packages.
 Your requirements could not be resolved to an installable set of packages.
 
 
   Problem 1
   Problem 1

+ 1 - 1
tests/Composer/Test/Fixtures/installer/github-issues-4319.test

@@ -32,7 +32,7 @@ install
 
 
 --EXPECT-OUTPUT--
 --EXPECT-OUTPUT--
 Loading composer repositories with package information
 Loading composer repositories with package information
-Updating dependencies (including require-dev)
+Updating dependencies
 Your requirements could not be resolved to an installable set of packages.
 Your requirements could not be resolved to an installable set of packages.
 
 
   Problem 1
   Problem 1

+ 25 - 3
tests/Composer/Test/Fixtures/installer/github-issues-4795-2.test

@@ -29,15 +29,37 @@ that are also a root package, when that root package is also explicitly whitelis
     { "name": "a/a", "version": "1.0.0" },
     { "name": "a/a", "version": "1.0.0" },
     { "name": "b/b", "version": "1.0.0", "require": { "a/a": "~1.0" } }
     { "name": "b/b", "version": "1.0.0", "require": { "a/a": "~1.0" } }
 ]
 ]
-
+--LOCK--
+{
+    "packages": [
+        {
+            "name": "a/a", "version": "1.0.0"
+        },
+        {
+            "name": "b/b", "version": "1.0.0", "require": { "a/a": "~1.0" }
+        }
+    ],
+    "packages-dev": [],
+    "aliases": [],
+    "minimum-stability": "stable",
+    "stability-flags": {},
+    "prefer-stable": false,
+    "prefer-lowest": false,
+    "platform": [],
+    "platform-dev": []
+}
 --RUN--
 --RUN--
 update a/a b/b --with-dependencies
 update a/a b/b --with-dependencies
 
 
 --EXPECT-OUTPUT--
 --EXPECT-OUTPUT--
 Loading composer repositories with package information
 Loading composer repositories with package information
-Updating dependencies (including require-dev)
-Package operations: 0 installs, 2 updates, 0 removals
+Updating dependencies
+Lock file operations: 0 installs, 2 updates, 0 removals
+  - Updating b/b (1.0.0) to b/b (1.1.0)
+  - Updating a/a (1.0.0) to a/a (1.1.0)
 Writing lock file
 Writing lock file
+Installing dependencies from lock file (including require-dev)
+Package operations: 0 installs, 2 updates, 0 removals
 Generating autoload files
 Generating autoload files
 
 
 --EXPECT--
 --EXPECT--

+ 4 - 1
tests/Composer/Test/Fixtures/installer/suggest-prod.test

@@ -19,8 +19,11 @@ install --no-dev
 --EXPECT-OUTPUT--
 --EXPECT-OUTPUT--
 Loading composer repositories with package information
 Loading composer repositories with package information
 Updating dependencies
 Updating dependencies
-Package operations: 1 install, 0 updates, 0 removals
+Lock file operations: 1 install, 0 updates, 0 removals
+  - Installing a/a (1.0.0)
 Writing lock file
 Writing lock file
+Installing dependencies from lock file
+Package operations: 1 install, 0 updates, 0 removals
 Generating autoload files
 Generating autoload files
 
 
 --EXPECT--
 --EXPECT--

+ 5 - 2
tests/Composer/Test/Fixtures/installer/suggest-uninstalled.test

@@ -18,10 +18,13 @@ Suggestions are displayed
 install
 install
 --EXPECT-OUTPUT--
 --EXPECT-OUTPUT--
 Loading composer repositories with package information
 Loading composer repositories with package information
-Updating dependencies (including require-dev)
+Updating dependencies
+Lock file operations: 1 install, 0 updates, 0 removals
+  - Installing a/a (1.0.0)
+Writing lock file
+Installing dependencies from lock file (including require-dev)
 Package operations: 1 install, 0 updates, 0 removals
 Package operations: 1 install, 0 updates, 0 removals
 a/a suggests installing b/b (an obscure reason)
 a/a suggests installing b/b (an obscure reason)
-Writing lock file
 Generating autoload files
 Generating autoload files
 
 
 --EXPECT--
 --EXPECT--

+ 1 - 1
tests/Composer/Test/Fixtures/installer/updating-dev-from-lock-removes-old-deps.test

@@ -16,7 +16,7 @@ Installing locked dev packages should remove old dependencies
             "require": {}
             "require": {}
         }
         }
     ],
     ],
-    "packages-dev": null,
+    "packages-dev": [],
     "aliases": [],
     "aliases": [],
     "minimum-stability": "dev",
     "minimum-stability": "dev",
     "stability-flags": [],
     "stability-flags": [],