Browse Source

Add output for metapackage installs/updates/.. fixes #7586

Jordi Boggiano 6 years ago
parent
commit
98a15bc93c

+ 2 - 2
src/Composer/Downloader/FileDownloader.php

@@ -215,8 +215,8 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
     public function update(PackageInterface $initial, PackageInterface $target, $path)
     {
         $name = $target->getName();
-        $from = $initial->getPrettyVersion();
-        $to = $target->getPrettyVersion();
+        $from = $initial->getFullPrettyVersion();
+        $to = $target->getFullPrettyVersion();
 
         $actionName = VersionParser::isUpgrade($initial->getVersion(), $target->getVersion()) ? 'Updating' : 'Downgrading';
         $this->io->writeError("  - " . $actionName . " <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>): ", false);

+ 1 - 1
src/Composer/Factory.php

@@ -546,7 +546,7 @@ class Factory
         $im->addInstaller(new Installer\LibraryInstaller($io, $composer, null));
         $im->addInstaller(new Installer\PearInstaller($io, $composer, 'pear-library'));
         $im->addInstaller(new Installer\PluginInstaller($io, $composer));
-        $im->addInstaller(new Installer\MetapackageInstaller());
+        $im->addInstaller(new Installer\MetapackageInstaller($io));
     }
 
     /**

+ 19 - 0
src/Composer/Installer/MetapackageInstaller.php

@@ -14,6 +14,8 @@ namespace Composer\Installer;
 
 use Composer\Repository\InstalledRepositoryInterface;
 use Composer\Package\PackageInterface;
+use Composer\Package\Version\VersionParser;
+use Composer\IO\IOInterface;
 
 /**
  * Metapackage installation manager.
@@ -22,6 +24,13 @@ use Composer\Package\PackageInterface;
  */
 class MetapackageInstaller implements InstallerInterface
 {
+    private $io;
+
+    public function __construct(IOInterface $io)
+    {
+        $this->io = $io;
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -43,6 +52,8 @@ class MetapackageInstaller implements InstallerInterface
      */
     public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
     {
+        $this->io->writeError("  - Installing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)");
+
         $repo->addPackage(clone $package);
     }
 
@@ -55,6 +66,12 @@ class MetapackageInstaller implements InstallerInterface
             throw new \InvalidArgumentException('Package is not installed: '.$initial);
         }
 
+        $name = $target->getName();
+        $from = $initial->getFullPrettyVersion();
+        $to = $target->getFullPrettyVersion();
+        $actionName = VersionParser::isUpgrade($initial->getVersion(), $target->getVersion()) ? 'Updating' : 'Downgrading';
+        $this->io->writeError("  - " . $actionName . " <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>)");
+
         $repo->removePackage($initial);
         $repo->addPackage(clone $target);
     }
@@ -68,6 +85,8 @@ class MetapackageInstaller implements InstallerInterface
             throw new \InvalidArgumentException('Package is not installed: '.$package);
         }
 
+        $this->io->writeError("  - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)");
+
         $repo->removePackage($package);
     }
 

+ 2 - 2
tests/Composer/Test/Downloader/FileDownloaderTest.php

@@ -210,7 +210,7 @@ class FileDownloaderTest extends TestCase
     {
         $oldPackage = $this->getMock('Composer\Package\PackageInterface');
         $oldPackage->expects($this->once())
-            ->method('getPrettyVersion')
+            ->method('getFullPrettyVersion')
             ->will($this->returnValue('1.2.0'));
         $oldPackage->expects($this->once())
             ->method('getVersion')
@@ -218,7 +218,7 @@ class FileDownloaderTest extends TestCase
 
         $newPackage = $this->getMock('Composer\Package\PackageInterface');
         $newPackage->expects($this->once())
-            ->method('getPrettyVersion')
+            ->method('getFullPrettyVersion')
             ->will($this->returnValue('1.0.0'));
         $newPackage->expects($this->once())
             ->method('getVersion')

+ 7 - 1
tests/Composer/Test/Installer/MetapackageInstallerTest.php

@@ -27,7 +27,7 @@ class MetapackageInstallerTest extends TestCase
 
         $this->io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
 
-        $this->installer = new MetapackageInstaller();
+        $this->installer = new MetapackageInstaller($this->io);
     }
 
     public function testInstall()
@@ -45,7 +45,13 @@ class MetapackageInstallerTest extends TestCase
     public function testUpdate()
     {
         $initial = $this->createPackageMock();
+        $initial->expects($this->once())
+            ->method('getVersion')
+            ->will($this->returnValue('1.0.0'));
         $target = $this->createPackageMock();
+        $target->expects($this->once())
+            ->method('getVersion')
+            ->will($this->returnValue('1.0.1'));
 
         $this->repository
             ->expects($this->exactly(2))