From e39fda059794dc9e8699afa12d3031e7a4717c0f Mon Sep 17 00:00:00 2001 From: David Garcia Date: Thu, 2 Mar 2017 18:13:07 +0100 Subject: [PATCH 1/3] Use parent's uninstall implementation, which is more reliable. --- src/Composer/Installers/Installer.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Composer/Installers/Installer.php b/src/Composer/Installers/Installer.php index 271ab73e..539b42c2 100644 --- a/src/Composer/Installers/Installer.php +++ b/src/Composer/Installers/Installer.php @@ -4,6 +4,7 @@ use Composer\IO\IOInterface; use Composer\Installer\LibraryInstaller; use Composer\Package\PackageInterface; +use Composer\Downloader\DownloadManager; use Composer\Repository\InstalledRepositoryInterface; class Installer extends LibraryInstaller @@ -113,14 +114,9 @@ public function getInstallPath(PackageInterface $package) public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) { - if (!$repo->hasPackage($package)) { - throw new \InvalidArgumentException('Package is not installed: '.$package); - } - - $repo->removePackage($package); - - $installPath = $this->getInstallPath($package); - $this->io->write(sprintf('Deleting %s - %s', $installPath, $this->filesystem->removeDirectory($installPath) ? 'deleted' : 'not deleted')); + parent::uninstall($repo, $package); + $installPath = $this->getPackageBasePath($package); + $this->io->write(sprintf('Deleting %s - %s', $installPath, !file_exists($installPath) ? 'deleted' : 'not deleted')); } /** From 63cc62027ed228478cc50eca61c6141d84a9b292 Mon Sep 17 00:00:00 2001 From: David Garcia Date: Thu, 2 Mar 2017 18:36:11 +0100 Subject: [PATCH 2/3] Implementing tests using mock objects is crap: it tests implementation, not functionality. --- tests/Composer/Installers/Test/InstallerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Composer/Installers/Test/InstallerTest.php b/tests/Composer/Installers/Test/InstallerTest.php index fa5c1cac..1a381955 100644 --- a/tests/Composer/Installers/Test/InstallerTest.php +++ b/tests/Composer/Installers/Test/InstallerTest.php @@ -495,7 +495,7 @@ public function testUninstallAndDeletePackageFromLocalRepo() $package = new Package('foo', '1.0.0', '1.0.0'); $installer = $this->getMock('Composer\Installers\Installer', array('getInstallPath'), array($this->io, $this->composer)); - $installer->expects($this->once())->method('getInstallPath')->with($package)->will($this->returnValue(sys_get_temp_dir().'/foo')); + $installer->expects($this->exactly(2))->method('getInstallPath')->with($package)->will($this->returnValue(sys_get_temp_dir().'/foo')); $repo = $this->getMock('Composer\Repository\InstalledRepositoryInterface'); $repo->expects($this->once())->method('hasPackage')->with($package)->will($this->returnValue(true)); From f890590b09d6b63f6f7d1b06a22605c2877f5f34 Mon Sep 17 00:00:00 2001 From: David Garcia Date: Thu, 2 Mar 2017 18:42:14 +0100 Subject: [PATCH 3/3] -- --- tests/Composer/Installers/Test/InstallerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Composer/Installers/Test/InstallerTest.php b/tests/Composer/Installers/Test/InstallerTest.php index 1a381955..24ddf40c 100644 --- a/tests/Composer/Installers/Test/InstallerTest.php +++ b/tests/Composer/Installers/Test/InstallerTest.php @@ -495,7 +495,7 @@ public function testUninstallAndDeletePackageFromLocalRepo() $package = new Package('foo', '1.0.0', '1.0.0'); $installer = $this->getMock('Composer\Installers\Installer', array('getInstallPath'), array($this->io, $this->composer)); - $installer->expects($this->exactly(2))->method('getInstallPath')->with($package)->will($this->returnValue(sys_get_temp_dir().'/foo')); + $installer->expects($this->atLeastOnce())->method('getInstallPath')->with($package)->will($this->returnValue(sys_get_temp_dir().'/foo')); $repo = $this->getMock('Composer\Repository\InstalledRepositoryInterface'); $repo->expects($this->once())->method('hasPackage')->with($package)->will($this->returnValue(true));