diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index dbacf89d5..10a54cd06 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -23,7 +23,7 @@ use Composer\Repository\PlatformRepository; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Composer\DependencyResolver\Operation\ReplaceOperation; +use Composer\DependencyResolver\Operation\InstallOperation; /** * @author Jordi Boggiano @@ -135,7 +135,7 @@ EOT if ('install' === $job['cmd']) { foreach ($installedRepo->getPackages() as $package ) { if ($installedRepo->hasPackage($package) && !$package->isPlatform() && !$installationManager->isPackageInstalled($package)) { - $operations[$job['packageName']] = new ReplaceOperation($package, \Composer\DependencyResolver\Solver::RULE_PACKAGE_NOT_EXIST); + $operations[$job['packageName']] = new InstallOperation($package, \Composer\DependencyResolver\Solver::RULE_PACKAGE_NOT_EXIST); } if (in_array($job['packageName'], $package->getNames())) { continue 2; diff --git a/src/Composer/DependencyResolver/Operation/ReplaceOperation.php b/src/Composer/DependencyResolver/Operation/ReplaceOperation.php deleted file mode 100644 index 1944355ac..000000000 --- a/src/Composer/DependencyResolver/Operation/ReplaceOperation.php +++ /dev/null @@ -1,66 +0,0 @@ - - * Jordi Boggiano - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Composer\DependencyResolver\Operation; - -use Composer\Package\PackageInterface; - -/** - * Solver replace operation. - * - * @author Robert Schönthal - */ -class ReplaceOperation extends SolverOperation -{ - protected $package; - - /** - * Initializes operation. - * - * @param PackageInterface $package package instance - * @param string $reason operation reason - */ - public function __construct(PackageInterface $package, $reason = null) - { - parent::__construct($reason); - - $this->package = $package; - } - - /** - * Returns package instance. - * - * @return PackageInterface - */ - public function getPackage() - { - return $this->package; - } - - /** - * Returns job type. - * - * @return string - */ - public function getJobType() - { - return 'replace'; - } - - /** - * {@inheritDoc} - */ - public function __toString() - { - return 'Replacing '.$this->package->getPrettyName().' ('.$this->package->getPrettyVersion().')'; - } -} diff --git a/src/Composer/Installer/InstallationManager.php b/src/Composer/Installer/InstallationManager.php index 2e7404299..04f8b73ec 100644 --- a/src/Composer/Installer/InstallationManager.php +++ b/src/Composer/Installer/InstallationManager.php @@ -161,17 +161,6 @@ class InstallationManager $installer->uninstall($operation->getPackage()); } - /** - * Replaces package. - * - * @param ReplaceOperation $operation operation instance - */ - public function replace(ReplaceOperation $operation) - { - $installer = $this->getInstaller($operation->getPackage()->getType()); - $installer->replace($operation->getPackage()); - } - /** * Returns the installation path of a package * diff --git a/src/Composer/Installer/InstallerInterface.php b/src/Composer/Installer/InstallerInterface.php index 9e8eafdf1..36c023b3b 100644 --- a/src/Composer/Installer/InstallerInterface.php +++ b/src/Composer/Installer/InstallerInterface.php @@ -63,13 +63,6 @@ interface InstallerInterface */ function uninstall(PackageInterface $package); - /** - * Replaces specific package. - * - * @param PackageInterface $package package instance - */ - function replace(PackageInterface $package); - /** * Returns the installation path of a package * diff --git a/src/Composer/Installer/LibraryInstaller.php b/src/Composer/Installer/LibraryInstaller.php index 33624cb47..8aae018c1 100644 --- a/src/Composer/Installer/LibraryInstaller.php +++ b/src/Composer/Installer/LibraryInstaller.php @@ -80,11 +80,20 @@ class LibraryInstaller implements InstallerInterface */ public function install(PackageInterface $package) { - $downloadPath = $this->getInstallPath($package); + $broken = !is_readable($this->getInstallPath($package)); + //remove the binaries first if its missing on filesystem + if ($broken) { + $this->removeBinaries($package); + } + + $downloadPath = $this->getInstallPath($package); $this->downloadManager->download($package, $downloadPath); $this->installBinaries($package); - $this->repository->addPackage(clone $package); + + if($broken) { + $this->repository->addPackage(clone $package); + } } /** @@ -123,23 +132,6 @@ class LibraryInstaller implements InstallerInterface $this->repository->removePackage($package); } - /** - * {@inheritDoc} - */ - public function replace(PackageInterface $package) - { - if (!$this->repository->hasPackage($package)) { - throw new \InvalidArgumentException('Package is not installed: '.$package); - } - - $downloadPath = $this->getInstallPath($package); - - $this->removeBinaries($package); - - $this->downloadManager->download($package, $downloadPath); - $this->installBinaries($package); - } - /** * {@inheritDoc} */ diff --git a/tests/Composer/Test/Installer/Fixtures/installer-v1/Installer/Custom.php b/tests/Composer/Test/Installer/Fixtures/installer-v1/Installer/Custom.php index 393261893..4bb58ded8 100644 --- a/tests/Composer/Test/Installer/Fixtures/installer-v1/Installer/Custom.php +++ b/tests/Composer/Test/Installer/Fixtures/installer-v1/Installer/Custom.php @@ -14,6 +14,5 @@ class Custom implements InstallerInterface public function install(PackageInterface $package) {} public function update(PackageInterface $initial, PackageInterface $target) {} public function uninstall(PackageInterface $package) {} - public function replace(PackageInterface $package) {} public function getInstallPath(PackageInterface $package) {} } diff --git a/tests/Composer/Test/Installer/Fixtures/installer-v2/Installer/Custom2.php b/tests/Composer/Test/Installer/Fixtures/installer-v2/Installer/Custom2.php index b454cbcfd..edd264428 100644 --- a/tests/Composer/Test/Installer/Fixtures/installer-v2/Installer/Custom2.php +++ b/tests/Composer/Test/Installer/Fixtures/installer-v2/Installer/Custom2.php @@ -14,6 +14,5 @@ class Custom2 implements InstallerInterface public function install(PackageInterface $package) {} public function update(PackageInterface $initial, PackageInterface $target) {} public function uninstall(PackageInterface $package) {} - public function replace(PackageInterface $package) {} public function getInstallPath(PackageInterface $package) {} } diff --git a/tests/Composer/Test/Installer/Fixtures/installer-v3/Installer/Custom2.php b/tests/Composer/Test/Installer/Fixtures/installer-v3/Installer/Custom2.php index 8e58c436e..db211bed5 100644 --- a/tests/Composer/Test/Installer/Fixtures/installer-v3/Installer/Custom2.php +++ b/tests/Composer/Test/Installer/Fixtures/installer-v3/Installer/Custom2.php @@ -14,6 +14,5 @@ class Custom2 implements InstallerInterface public function install(PackageInterface $package) {} public function update(PackageInterface $initial, PackageInterface $target) {} public function uninstall(PackageInterface $package) {} - public function replace(PackageInterface $package) {} public function getInstallPath(PackageInterface $package) {} } diff --git a/tests/Composer/Test/Installer/LibraryInstallerTest.php b/tests/Composer/Test/Installer/LibraryInstallerTest.php index 0f85c4b21..c5cb9d538 100644 --- a/tests/Composer/Test/Installer/LibraryInstallerTest.php +++ b/tests/Composer/Test/Installer/LibraryInstallerTest.php @@ -85,7 +85,7 @@ class LibraryInstallerTest extends \PHPUnit_Framework_TestCase $package = $this->createPackageMock(); $package - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getPrettyName') ->will($this->returnValue('some/package')); @@ -175,30 +175,6 @@ class LibraryInstallerTest extends \PHPUnit_Framework_TestCase $library->uninstall($package); } - public function testReplace() - { - $library = new LibraryInstaller($this->vendorDir, $this->binDir, $this->dm, $this->repository, $this->io); - $package = $this->createPackageMock(); - - $package - ->expects($this->once()) - ->method('getPrettyName') - ->will($this->returnValue('pkg')); - - $this->repository - ->expects($this->once()) - ->method('hasPackage') - ->with($package) - ->will($this->onConsecutiveCalls(true, false)); - - $this->dm - ->expects($this->once()) - ->method('download') - ->with($package, $this->vendorDir.'/pkg'); - - $library->replace($package); - } - public function testGetInstallPath() { $library = new LibraryInstaller($this->vendorDir, $this->binDir, $this->dm, $this->repository, $this->io);