2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2011-09-25 16:30:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Installer;
|
|
|
|
|
|
|
|
use Composer\Installer\InstallationManager;
|
2019-01-17 16:12:33 +00:00
|
|
|
use Composer\Installer\NoopInstaller;
|
2011-09-25 16:30:22 +00:00
|
|
|
use Composer\DependencyResolver\Operation\InstallOperation;
|
|
|
|
use Composer\DependencyResolver\Operation\UpdateOperation;
|
|
|
|
use Composer\DependencyResolver\Operation\UninstallOperation;
|
2020-02-07 03:18:45 +00:00
|
|
|
use Composer\Test\TestCase;
|
2011-09-25 16:30:22 +00:00
|
|
|
|
2017-11-04 14:52:13 +00:00
|
|
|
class InstallationManagerTest extends TestCase
|
2011-09-25 16:30:22 +00:00
|
|
|
{
|
2021-10-27 12:41:30 +00:00
|
|
|
/**
|
|
|
|
* @var \Composer\Repository\InstalledRepositoryInterface&\PHPUnit\Framework\MockObject\MockObject
|
|
|
|
*/
|
2018-01-06 14:05:39 +00:00
|
|
|
protected $repository;
|
2021-10-27 12:41:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Composer\Util\Loop&\PHPUnit\Framework\MockObject\MockObject
|
|
|
|
*/
|
2019-01-17 16:12:33 +00:00
|
|
|
protected $loop;
|
2021-10-27 12:41:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject
|
|
|
|
*/
|
2019-11-14 14:20:50 +00:00
|
|
|
protected $io;
|
2018-01-06 14:05:39 +00:00
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
public function setUp(): void
|
2012-04-14 13:45:25 +00:00
|
|
|
{
|
2019-01-17 16:12:33 +00:00
|
|
|
$this->loop = $this->getMockBuilder('Composer\Util\Loop')->disableOriginalConstructor()->getMock();
|
2018-04-12 08:24:56 +00:00
|
|
|
$this->repository = $this->getMockBuilder('Composer\Repository\InstalledRepositoryInterface')->getMock();
|
2019-11-14 14:20:50 +00:00
|
|
|
$this->io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
2012-04-14 13:45:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testAddGetInstaller(): void
|
2011-09-25 16:30:22 +00:00
|
|
|
{
|
|
|
|
$installer = $this->createInstallerMock();
|
2011-10-22 18:20:19 +00:00
|
|
|
|
|
|
|
$installer
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('supports')
|
2022-08-17 12:20:07 +00:00
|
|
|
->will($this->returnCallback(static function ($arg): bool {
|
2011-10-22 18:20:19 +00:00
|
|
|
return $arg === 'vendor';
|
|
|
|
}));
|
|
|
|
|
2019-11-14 14:20:50 +00:00
|
|
|
$manager = new InstallationManager($this->loop, $this->io);
|
2011-09-25 16:30:22 +00:00
|
|
|
|
2011-10-22 18:20:19 +00:00
|
|
|
$manager->addInstaller($installer);
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($installer, $manager->getInstaller('vendor'));
|
2011-09-25 16:30:22 +00:00
|
|
|
|
2021-12-09 19:55:26 +00:00
|
|
|
self::expectException('InvalidArgumentException');
|
2011-09-25 16:30:22 +00:00
|
|
|
$manager->getInstaller('unregistered');
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testAddRemoveInstaller(): void
|
2012-11-29 08:24:28 +00:00
|
|
|
{
|
|
|
|
$installer = $this->createInstallerMock();
|
|
|
|
|
|
|
|
$installer
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('supports')
|
2022-08-17 12:20:07 +00:00
|
|
|
->will($this->returnCallback(static function ($arg): bool {
|
2012-11-29 08:24:28 +00:00
|
|
|
return $arg === 'vendor';
|
|
|
|
}));
|
|
|
|
|
|
|
|
$installer2 = $this->createInstallerMock();
|
|
|
|
|
|
|
|
$installer2
|
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('supports')
|
2022-08-17 12:20:07 +00:00
|
|
|
->will($this->returnCallback(static function ($arg): bool {
|
2012-11-29 08:24:28 +00:00
|
|
|
return $arg === 'vendor';
|
|
|
|
}));
|
|
|
|
|
2019-11-14 14:20:50 +00:00
|
|
|
$manager = new InstallationManager($this->loop, $this->io);
|
2012-11-29 08:24:28 +00:00
|
|
|
|
|
|
|
$manager->addInstaller($installer);
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($installer, $manager->getInstaller('vendor'));
|
2012-11-29 08:24:28 +00:00
|
|
|
$manager->addInstaller($installer2);
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($installer2, $manager->getInstaller('vendor'));
|
2012-11-29 08:24:28 +00:00
|
|
|
$manager->removeInstaller($installer2);
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame($installer, $manager->getInstaller('vendor'));
|
2012-11-29 08:24:28 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testExecute(): void
|
2011-09-25 16:30:22 +00:00
|
|
|
{
|
|
|
|
$manager = $this->getMockBuilder('Composer\Installer\InstallationManager')
|
2022-08-17 12:20:07 +00:00
|
|
|
->setConstructorArgs([$this->loop, $this->io])
|
|
|
|
->onlyMethods(['install', 'update', 'uninstall'])
|
2011-09-25 16:30:22 +00:00
|
|
|
->getMock();
|
|
|
|
|
2019-01-17 16:12:33 +00:00
|
|
|
$installOperation = new InstallOperation($package = $this->createPackageMock());
|
|
|
|
$removeOperation = new UninstallOperation($package);
|
2017-03-08 14:07:29 +00:00
|
|
|
$updateOperation = new UpdateOperation(
|
2019-01-17 16:12:33 +00:00
|
|
|
$package,
|
|
|
|
$package
|
2011-09-25 16:30:22 +00:00
|
|
|
);
|
|
|
|
|
2019-01-17 16:12:33 +00:00
|
|
|
$package->expects($this->any())
|
|
|
|
->method('getType')
|
|
|
|
->will($this->returnValue('library'));
|
|
|
|
|
2011-09-25 16:30:22 +00:00
|
|
|
$manager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('install')
|
2012-04-14 13:45:25 +00:00
|
|
|
->with($this->repository, $installOperation);
|
2011-09-25 16:30:22 +00:00
|
|
|
$manager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('uninstall')
|
2012-04-14 13:45:25 +00:00
|
|
|
->with($this->repository, $removeOperation);
|
2011-09-25 16:30:22 +00:00
|
|
|
$manager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('update')
|
2012-04-14 13:45:25 +00:00
|
|
|
->with($this->repository, $updateOperation);
|
2011-09-25 16:30:22 +00:00
|
|
|
|
2019-01-17 16:12:33 +00:00
|
|
|
$manager->addInstaller(new NoopInstaller());
|
2022-08-17 12:20:07 +00:00
|
|
|
$manager->execute($this->repository, [$installOperation, $removeOperation, $updateOperation]);
|
2011-09-25 16:30:22 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testInstall(): void
|
2011-09-25 16:30:22 +00:00
|
|
|
{
|
|
|
|
$installer = $this->createInstallerMock();
|
2019-11-14 14:20:50 +00:00
|
|
|
$manager = new InstallationManager($this->loop, $this->io);
|
2011-10-22 18:20:19 +00:00
|
|
|
$manager->addInstaller($installer);
|
2011-09-25 16:30:22 +00:00
|
|
|
|
2017-03-08 14:07:29 +00:00
|
|
|
$package = $this->createPackageMock();
|
2020-10-12 10:31:54 +00:00
|
|
|
$operation = new InstallOperation($package);
|
2011-09-25 16:30:22 +00:00
|
|
|
|
|
|
|
$package
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getType')
|
|
|
|
->will($this->returnValue('library'));
|
|
|
|
|
2011-10-22 18:20:19 +00:00
|
|
|
$installer
|
|
|
|
->expects($this->once())
|
|
|
|
->method('supports')
|
|
|
|
->with('library')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2011-09-25 16:30:22 +00:00
|
|
|
$installer
|
|
|
|
->expects($this->once())
|
|
|
|
->method('install')
|
2012-04-14 13:45:25 +00:00
|
|
|
->with($this->repository, $package);
|
2011-09-25 16:30:22 +00:00
|
|
|
|
2012-04-14 13:45:25 +00:00
|
|
|
$manager->install($this->repository, $operation);
|
2011-09-25 16:30:22 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testUpdateWithEqualTypes(): void
|
2011-09-25 16:30:22 +00:00
|
|
|
{
|
|
|
|
$installer = $this->createInstallerMock();
|
2019-11-14 14:20:50 +00:00
|
|
|
$manager = new InstallationManager($this->loop, $this->io);
|
2011-10-22 18:20:19 +00:00
|
|
|
$manager->addInstaller($installer);
|
2011-09-25 16:30:22 +00:00
|
|
|
|
2017-03-08 14:07:29 +00:00
|
|
|
$initial = $this->createPackageMock();
|
|
|
|
$target = $this->createPackageMock();
|
2020-10-12 10:31:54 +00:00
|
|
|
$operation = new UpdateOperation($initial, $target);
|
2011-09-25 16:30:22 +00:00
|
|
|
|
|
|
|
$initial
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getType')
|
|
|
|
->will($this->returnValue('library'));
|
|
|
|
$target
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getType')
|
|
|
|
->will($this->returnValue('library'));
|
|
|
|
|
2011-10-22 18:20:19 +00:00
|
|
|
$installer
|
|
|
|
->expects($this->once())
|
|
|
|
->method('supports')
|
|
|
|
->with('library')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2011-09-25 16:30:22 +00:00
|
|
|
$installer
|
|
|
|
->expects($this->once())
|
|
|
|
->method('update')
|
2012-04-14 13:45:25 +00:00
|
|
|
->with($this->repository, $initial, $target);
|
2011-09-25 16:30:22 +00:00
|
|
|
|
2012-04-14 13:45:25 +00:00
|
|
|
$manager->update($this->repository, $operation);
|
2011-09-25 16:30:22 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testUpdateWithNotEqualTypes(): void
|
2011-09-25 16:30:22 +00:00
|
|
|
{
|
2011-10-22 18:20:19 +00:00
|
|
|
$libInstaller = $this->createInstallerMock();
|
|
|
|
$bundleInstaller = $this->createInstallerMock();
|
2019-11-14 14:20:50 +00:00
|
|
|
$manager = new InstallationManager($this->loop, $this->io);
|
2011-10-22 18:20:19 +00:00
|
|
|
$manager->addInstaller($libInstaller);
|
|
|
|
$manager->addInstaller($bundleInstaller);
|
2011-09-25 16:30:22 +00:00
|
|
|
|
2017-03-08 14:07:29 +00:00
|
|
|
$initial = $this->createPackageMock();
|
2011-09-25 16:30:22 +00:00
|
|
|
$initial
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getType')
|
|
|
|
->will($this->returnValue('library'));
|
2019-01-17 16:12:33 +00:00
|
|
|
|
|
|
|
$target = $this->createPackageMock();
|
2011-09-25 16:30:22 +00:00
|
|
|
$target
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getType')
|
|
|
|
->will($this->returnValue('bundles'));
|
|
|
|
|
2011-10-22 18:20:19 +00:00
|
|
|
$bundleInstaller
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('supports')
|
2022-08-17 12:20:07 +00:00
|
|
|
->will($this->returnCallback(static function ($arg): bool {
|
2011-10-22 18:20:19 +00:00
|
|
|
return $arg === 'bundles';
|
|
|
|
}));
|
|
|
|
|
|
|
|
$libInstaller
|
|
|
|
->expects($this->once())
|
|
|
|
->method('supports')
|
|
|
|
->with('library')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$libInstaller
|
2011-09-25 16:30:22 +00:00
|
|
|
->expects($this->once())
|
|
|
|
->method('uninstall')
|
2012-04-14 13:45:25 +00:00
|
|
|
->with($this->repository, $initial);
|
2011-09-25 16:30:22 +00:00
|
|
|
|
2011-10-22 18:20:19 +00:00
|
|
|
$bundleInstaller
|
2011-09-25 16:30:22 +00:00
|
|
|
->expects($this->once())
|
|
|
|
->method('install')
|
2012-04-14 13:45:25 +00:00
|
|
|
->with($this->repository, $target);
|
2011-09-25 16:30:22 +00:00
|
|
|
|
2020-10-12 10:31:54 +00:00
|
|
|
$operation = new UpdateOperation($initial, $target);
|
2012-04-14 13:45:25 +00:00
|
|
|
$manager->update($this->repository, $operation);
|
2011-09-25 16:30:22 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testUninstall(): void
|
2011-09-25 16:30:22 +00:00
|
|
|
{
|
|
|
|
$installer = $this->createInstallerMock();
|
2019-11-14 14:20:50 +00:00
|
|
|
$manager = new InstallationManager($this->loop, $this->io);
|
2011-10-22 18:20:19 +00:00
|
|
|
$manager->addInstaller($installer);
|
2011-09-25 16:30:22 +00:00
|
|
|
|
2017-03-08 14:07:29 +00:00
|
|
|
$package = $this->createPackageMock();
|
2020-10-12 10:31:54 +00:00
|
|
|
$operation = new UninstallOperation($package);
|
2011-09-25 16:30:22 +00:00
|
|
|
|
|
|
|
$package
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getType')
|
|
|
|
->will($this->returnValue('library'));
|
|
|
|
|
|
|
|
$installer
|
|
|
|
->expects($this->once())
|
|
|
|
->method('uninstall')
|
2012-04-14 13:45:25 +00:00
|
|
|
->with($this->repository, $package);
|
2011-09-25 16:30:22 +00:00
|
|
|
|
2011-10-22 18:20:19 +00:00
|
|
|
$installer
|
|
|
|
->expects($this->once())
|
|
|
|
->method('supports')
|
|
|
|
->with('library')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2012-04-14 13:45:25 +00:00
|
|
|
$manager->uninstall($this->repository, $operation);
|
2011-09-25 16:30:22 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testInstallBinary(): void
|
2016-03-28 21:15:13 +00:00
|
|
|
{
|
|
|
|
$installer = $this->getMockBuilder('Composer\Installer\LibraryInstaller')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2019-11-14 14:20:50 +00:00
|
|
|
$manager = new InstallationManager($this->loop, $this->io);
|
2016-03-28 21:15:13 +00:00
|
|
|
$manager->addInstaller($installer);
|
|
|
|
|
2017-03-08 14:07:29 +00:00
|
|
|
$package = $this->createPackageMock();
|
2016-03-28 21:15:13 +00:00
|
|
|
|
|
|
|
$package
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getType')
|
|
|
|
->will($this->returnValue('library'));
|
|
|
|
|
|
|
|
$installer
|
|
|
|
->expects($this->once())
|
|
|
|
->method('supports')
|
|
|
|
->with('library')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$installer
|
|
|
|
->expects($this->once())
|
2016-07-02 15:35:09 +00:00
|
|
|
->method('ensureBinariesPresence')
|
2016-03-28 21:15:13 +00:00
|
|
|
->with($package);
|
|
|
|
|
2016-07-02 15:35:09 +00:00
|
|
|
$manager->ensureBinariesPresence($package);
|
2016-03-28 21:15:13 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 12:41:30 +00:00
|
|
|
/**
|
|
|
|
* @return \Composer\Installer\InstallerInterface&\PHPUnit\Framework\MockObject\MockObject
|
|
|
|
*/
|
2011-09-25 16:30:22 +00:00
|
|
|
private function createInstallerMock()
|
|
|
|
{
|
|
|
|
return $this->getMockBuilder('Composer\Installer\InstallerInterface')
|
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
|
2021-10-27 12:41:30 +00:00
|
|
|
/**
|
|
|
|
* @return \Composer\Package\PackageInterface&\PHPUnit\Framework\MockObject\MockObject
|
|
|
|
*/
|
2011-09-25 16:30:22 +00:00
|
|
|
private function createPackageMock()
|
|
|
|
{
|
2019-01-17 16:12:33 +00:00
|
|
|
$mock = $this->getMockBuilder('Composer\Package\PackageInterface')
|
2011-09-25 16:30:22 +00:00
|
|
|
->getMock();
|
2019-01-17 16:12:33 +00:00
|
|
|
|
|
|
|
return $mock;
|
2011-09-25 16:30:22 +00:00
|
|
|
}
|
|
|
|
}
|