1
0
Fork 0
composer/tests/Composer/Test/Mock/InstallationManagerMock.php

160 lines
4.4 KiB
PHP
Raw Normal View History

2022-02-23 15:58:18 +00:00
<?php declare(strict_types=1);
2017-03-08 14:07:29 +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;
use React\Promise\PromiseInterface;
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;
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;
class InstallationManagerMock extends InstallationManager
{
2021-10-16 08:16:06 +00:00
/**
* @var PackageInterface[]
*/
private $installed = array();
2021-10-16 08:16:06 +00:00
/**
* @var PackageInterface[][]
*/
private $updated = array();
2021-10-16 08:16:06 +00:00
/**
* @var PackageInterface[]
*/
private $uninstalled = array();
2021-10-16 08:16:06 +00:00
/**
* @var string[]
*/
private $trace = array();
public function __construct()
{
}
public function execute(InstalledRepositoryInterface $repo, array $operations, $devMode = true, $runScripts = true): void
{
foreach ($operations as $operation) {
$method = $operation->getOperationType();
// skipping download() step here for tests
$this->$method($repo, $operation);
}
}
public function getInstallPath(PackageInterface $package): string
2012-06-20 10:05:18 +00:00
{
return '';
}
public function isPackageInstalled(InstalledRepositoryInterface $repo, PackageInterface $package): bool
{
return $repo->hasPackage($package);
}
/**
2021-10-27 13:47:42 +00:00
* @inheritDoc
*/
public function install(InstalledRepositoryInterface $repo, InstallOperation $operation): ?PromiseInterface
{
2012-04-29 15:27:37 +00:00
$this->installed[] = $operation->getPackage();
$this->trace[] = strip_tags((string) $operation);
$repo->addPackage(clone $operation->getPackage());
return null;
}
/**
2021-10-27 13:47:42 +00:00
* @inheritDoc
*/
public function update(InstalledRepositoryInterface $repo, UpdateOperation $operation): ?PromiseInterface
{
2012-04-29 15:27:37 +00:00
$this->updated[] = array($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;
}
/**
2021-10-27 13:47:42 +00:00
* @inheritDoc
*/
public function uninstall(InstalledRepositoryInterface $repo, UninstallOperation $operation): ?PromiseInterface
{
2012-04-29 15:27:37 +00:00
$this->uninstalled[] = $operation->getPackage();
$this->trace[] = strip_tags((string) $operation);
$repo->removePackage($operation->getPackage());
return null;
}
public function markAliasInstalled(InstalledRepositoryInterface $repo, MarkAliasInstalledOperation $operation): void
2012-05-13 20:36:48 +00:00
{
$package = $operation->getPackage();
$this->installed[] = $package;
$this->trace[] = strip_tags((string) $operation);
parent::markAliasInstalled($repo, $operation);
2012-05-13 20:36:48 +00:00
}
public function markAliasUninstalled(InstalledRepositoryInterface $repo, MarkAliasUninstalledOperation $operation): void
2012-05-13 20:36:48 +00:00
{
$this->uninstalled[] = $operation->getPackage();
$this->trace[] = strip_tags((string) $operation);
parent::markAliasUninstalled($repo, $operation);
2012-05-13 20:36:48 +00:00
}
/** @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;
}
2020-10-27 13:04:36 +00:00
public function notifyInstalls(IOInterface $io): void
2020-10-27 13:04:36 +00:00
{
// noop
}
/** @return PackageInterface[] */
public function getInstalledPackagesByType(): array
{
return $this->installed;
}
}