1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
<?php declare(strict_types=1);
/*
* 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;
use React\Promise\PromiseInterface;
use Composer\Installer\InstallationManager;
use Composer\Repository\InstalledRepositoryInterface;
use Composer\Package\PackageInterface;
use Composer\IO\IOInterface;
use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\DependencyResolver\Operation\UninstallOperation;
use Composer\DependencyResolver\Operation\MarkAliasInstalledOperation;
use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
class InstallationManagerMock extends InstallationManager
{
/**
* @var PackageInterface[]
*/
private $installed = [];
/**
* @var PackageInterface[][]
*/
private $updated = [];
/**
* @var PackageInterface[]
*/
private $uninstalled = [];
/**
* @var string[]
*/
private $trace = [];
public function __construct()
{
}
public function execute(InstalledRepositoryInterface $repo, array $operations, $devMode = true, $runScripts = true, $downloadOnly = false): void
{
foreach ($operations as $operation) {
$method = $operation->getOperationType();
// skipping download() step here for tests
$this->{$method}($repo, $operation);
}
}
public function getInstallPath(PackageInterface $package): string
{
return 'vendor/'.$package->getName();
}
public function isPackageInstalled(InstalledRepositoryInterface $repo, PackageInterface $package): bool
{
return $repo->hasPackage($package);
}
/**
* @inheritDoc
*/
public function install(InstalledRepositoryInterface $repo, InstallOperation $operation): ?PromiseInterface
{
$this->installed[] = $operation->getPackage();
$this->trace[] = strip_tags((string) $operation);
$repo->addPackage(clone $operation->getPackage());
return null;
}
/**
* @inheritDoc
*/
public function update(InstalledRepositoryInterface $repo, UpdateOperation $operation): ?PromiseInterface
{
$this->updated[] = [$operation->getInitialPackage(), $operation->getTargetPackage()];
$this->trace[] = strip_tags((string) $operation);
$repo->removePackage($operation->getInitialPackage());
if (!$repo->hasPackage($operation->getTargetPackage())) {
$repo->addPackage(clone $operation->getTargetPackage());
}
return null;
}
/**
* @inheritDoc
*/
public function uninstall(InstalledRepositoryInterface $repo, UninstallOperation $operation): ?PromiseInterface
{
$this->uninstalled[] = $operation->getPackage();
$this->trace[] = strip_tags((string) $operation);
$repo->removePackage($operation->getPackage());
return null;
}
public function markAliasInstalled(InstalledRepositoryInterface $repo, MarkAliasInstalledOperation $operation): void
{
$package = $operation->getPackage();
$this->installed[] = $package;
$this->trace[] = strip_tags((string) $operation);
parent::markAliasInstalled($repo, $operation);
}
public function markAliasUninstalled(InstalledRepositoryInterface $repo, MarkAliasUninstalledOperation $operation): void
{
$this->uninstalled[] = $operation->getPackage();
$this->trace[] = strip_tags((string) $operation);
parent::markAliasUninstalled($repo, $operation);
}
/** @return string[] */
public function getTrace(): array
{
return $this->trace;
}
/** @return PackageInterface[] */
public function getInstalledPackages(): array
{
return $this->installed;
}
/** @return PackageInterface[][] */
public function getUpdatedPackages(): array
{
return $this->updated;
}
/** @return PackageInterface[] */
public function getUninstalledPackages(): array
{
return $this->uninstalled;
}
public function notifyInstalls(IOInterface $io): void
{
// noop
}
/** @return PackageInterface[] */
public function getInstalledPackagesByType(): array
{
return $this->installed;
}
}
|