2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2017-03-08 14:07:29 +00:00
|
|
|
|
2012-04-27 09:42:58 +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\Mock;
|
|
|
|
|
2022-02-18 10:22:01 +00:00
|
|
|
use React\Promise\PromiseInterface;
|
2012-04-27 09:42:58 +00:00
|
|
|
use Composer\Installer\InstallationManager;
|
2013-03-03 16:18:50 +00:00
|
|
|
use Composer\Repository\InstalledRepositoryInterface;
|
2012-06-20 10:05:18 +00:00
|
|
|
use Composer\Package\PackageInterface;
|
2020-10-27 13:04:36 +00:00
|
|
|
use Composer\IO\IOInterface;
|
2012-04-27 09:42:58 +00:00
|
|
|
use Composer\DependencyResolver\Operation\InstallOperation;
|
|
|
|
use Composer\DependencyResolver\Operation\UpdateOperation;
|
|
|
|
use Composer\DependencyResolver\Operation\UninstallOperation;
|
2012-05-13 20:36:48 +00:00
|
|
|
use Composer\DependencyResolver\Operation\MarkAliasInstalledOperation;
|
|
|
|
use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
|
2012-04-27 09:42:58 +00:00
|
|
|
|
|
|
|
class InstallationManagerMock extends InstallationManager
|
|
|
|
{
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var PackageInterface[]
|
|
|
|
*/
|
2022-08-17 12:20:07 +00:00
|
|
|
private $installed = [];
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var PackageInterface[][]
|
|
|
|
*/
|
2022-08-17 12:20:07 +00:00
|
|
|
private $updated = [];
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var PackageInterface[]
|
|
|
|
*/
|
2022-08-17 12:20:07 +00:00
|
|
|
private $uninstalled = [];
|
2021-10-16 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
*/
|
2022-08-17 12:20:07 +00:00
|
|
|
private $trace = [];
|
2012-04-27 09:42:58 +00:00
|
|
|
|
2019-01-17 16:12:33 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function execute(InstalledRepositoryInterface $repo, array $operations, $devMode = true, $runScripts = true): void
|
2019-01-17 16:12:33 +00:00
|
|
|
{
|
2019-11-14 14:20:50 +00:00
|
|
|
foreach ($operations as $operation) {
|
2020-01-19 22:11:36 +00:00
|
|
|
$method = $operation->getOperationType();
|
2019-11-14 14:20:50 +00:00
|
|
|
// skipping download() step here for tests
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->{$method}($repo, $operation);
|
2019-11-14 14:20:50 +00:00
|
|
|
}
|
2019-01-17 16:12:33 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 10:22:01 +00:00
|
|
|
public function getInstallPath(PackageInterface $package): string
|
2012-06-20 10:05:18 +00:00
|
|
|
{
|
2022-06-09 09:43:59 +00:00
|
|
|
return 'vendor/'.$package->getName();
|
2012-06-20 10:05:18 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 10:22:01 +00:00
|
|
|
public function isPackageInstalled(InstalledRepositoryInterface $repo, PackageInterface $package): bool
|
2013-03-10 18:55:26 +00:00
|
|
|
{
|
|
|
|
return $repo->hasPackage($package);
|
|
|
|
}
|
|
|
|
|
2021-10-25 08:44:29 +00:00
|
|
|
/**
|
2021-10-27 13:47:42 +00:00
|
|
|
* @inheritDoc
|
2021-10-25 08:44:29 +00:00
|
|
|
*/
|
2022-02-18 10:22:01 +00:00
|
|
|
public function install(InstalledRepositoryInterface $repo, InstallOperation $operation): ?PromiseInterface
|
2012-04-27 09:42:58 +00:00
|
|
|
{
|
2012-04-29 15:27:37 +00:00
|
|
|
$this->installed[] = $operation->getPackage();
|
2020-04-08 13:18:28 +00:00
|
|
|
$this->trace[] = strip_tags((string) $operation);
|
2012-05-13 19:40:42 +00:00
|
|
|
$repo->addPackage(clone $operation->getPackage());
|
2021-10-25 08:44:29 +00:00
|
|
|
|
|
|
|
return null;
|
2012-04-27 09:42:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-25 08:44:29 +00:00
|
|
|
/**
|
2021-10-27 13:47:42 +00:00
|
|
|
* @inheritDoc
|
2021-10-25 08:44:29 +00:00
|
|
|
*/
|
2022-02-18 10:22:01 +00:00
|
|
|
public function update(InstalledRepositoryInterface $repo, UpdateOperation $operation): ?PromiseInterface
|
2012-04-27 09:42:58 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->updated[] = [$operation->getInitialPackage(), $operation->getTargetPackage()];
|
2020-04-08 13:18:28 +00:00
|
|
|
$this->trace[] = strip_tags((string) $operation);
|
2012-05-13 19:40:42 +00:00
|
|
|
$repo->removePackage($operation->getInitialPackage());
|
2020-04-20 19:46:56 +00:00
|
|
|
if (!$repo->hasPackage($operation->getTargetPackage())) {
|
|
|
|
$repo->addPackage(clone $operation->getTargetPackage());
|
|
|
|
}
|
2021-10-25 08:44:29 +00:00
|
|
|
|
|
|
|
return null;
|
2012-04-27 09:42:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-25 08:44:29 +00:00
|
|
|
/**
|
2021-10-27 13:47:42 +00:00
|
|
|
* @inheritDoc
|
2021-10-25 08:44:29 +00:00
|
|
|
*/
|
2022-02-18 10:22:01 +00:00
|
|
|
public function uninstall(InstalledRepositoryInterface $repo, UninstallOperation $operation): ?PromiseInterface
|
2012-04-27 09:42:58 +00:00
|
|
|
{
|
2012-04-29 15:27:37 +00:00
|
|
|
$this->uninstalled[] = $operation->getPackage();
|
2020-04-08 13:18:28 +00:00
|
|
|
$this->trace[] = strip_tags((string) $operation);
|
2012-05-13 19:40:42 +00:00
|
|
|
$repo->removePackage($operation->getPackage());
|
2021-10-25 08:44:29 +00:00
|
|
|
|
|
|
|
return null;
|
2012-05-13 19:40:42 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function markAliasInstalled(InstalledRepositoryInterface $repo, MarkAliasInstalledOperation $operation): void
|
2012-05-13 20:36:48 +00:00
|
|
|
{
|
2012-07-01 16:41:58 +00:00
|
|
|
$package = $operation->getPackage();
|
|
|
|
|
|
|
|
$this->installed[] = $package;
|
2020-04-08 13:18:28 +00:00
|
|
|
$this->trace[] = strip_tags((string) $operation);
|
2012-07-01 16:41:58 +00:00
|
|
|
|
2013-04-01 06:10:15 +00:00
|
|
|
parent::markAliasInstalled($repo, $operation);
|
2012-05-13 20:36:48 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function markAliasUninstalled(InstalledRepositoryInterface $repo, MarkAliasUninstalledOperation $operation): void
|
2012-05-13 20:36:48 +00:00
|
|
|
{
|
|
|
|
$this->uninstalled[] = $operation->getPackage();
|
2020-04-08 13:18:28 +00:00
|
|
|
$this->trace[] = strip_tags((string) $operation);
|
2013-04-01 06:10:15 +00:00
|
|
|
|
|
|
|
parent::markAliasUninstalled($repo, $operation);
|
2012-05-13 20:36:48 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 12:56:39 +00:00
|
|
|
/** @return string[] */
|
2022-02-18 10:22:01 +00:00
|
|
|
public function getTrace(): array
|
2012-05-13 19:40:42 +00:00
|
|
|
{
|
|
|
|
return $this->trace;
|
2012-04-27 09:42:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 12:56:39 +00:00
|
|
|
/** @return PackageInterface[] */
|
2022-02-18 10:22:01 +00:00
|
|
|
public function getInstalledPackages(): array
|
2012-04-27 09:42:58 +00:00
|
|
|
{
|
|
|
|
return $this->installed;
|
|
|
|
}
|
|
|
|
|
2021-10-27 12:56:39 +00:00
|
|
|
/** @return PackageInterface[][] */
|
2022-02-18 10:22:01 +00:00
|
|
|
public function getUpdatedPackages(): array
|
2012-04-27 09:42:58 +00:00
|
|
|
{
|
|
|
|
return $this->updated;
|
|
|
|
}
|
|
|
|
|
2021-10-27 12:56:39 +00:00
|
|
|
/** @return PackageInterface[] */
|
2022-02-18 10:22:01 +00:00
|
|
|
public function getUninstalledPackages(): array
|
2012-04-27 09:42:58 +00:00
|
|
|
{
|
|
|
|
return $this->uninstalled;
|
|
|
|
}
|
2020-10-27 13:04:36 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function notifyInstalls(IOInterface $io): void
|
2020-10-27 13:04:36 +00:00
|
|
|
{
|
|
|
|
// noop
|
|
|
|
}
|
2021-02-25 09:00:36 +00:00
|
|
|
|
2021-10-27 12:56:39 +00:00
|
|
|
/** @return PackageInterface[] */
|
2022-02-18 10:22:01 +00:00
|
|
|
public function getInstalledPackagesByType(): array
|
2021-02-25 09:00:36 +00:00
|
|
|
{
|
|
|
|
return $this->installed;
|
|
|
|
}
|
2012-04-27 09:42:58 +00:00
|
|
|
}
|