InstallationManagerMock.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Mock;
  12. use Composer\Installer\InstallationManager;
  13. use Composer\Repository\RepositoryInterface;
  14. use Composer\Repository\InstalledRepositoryInterface;
  15. use Composer\Package\PackageInterface;
  16. use Composer\DependencyResolver\Operation\InstallOperation;
  17. use Composer\DependencyResolver\Operation\OperationInterface;
  18. use Composer\DependencyResolver\Operation\UpdateOperation;
  19. use Composer\DependencyResolver\Operation\UninstallOperation;
  20. use Composer\DependencyResolver\Operation\MarkAliasInstalledOperation;
  21. use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
  22. class InstallationManagerMock extends InstallationManager
  23. {
  24. private $installed = array();
  25. private $updated = array();
  26. private $uninstalled = array();
  27. private $trace = array();
  28. public function __construct()
  29. {
  30. }
  31. public function execute(RepositoryInterface $repo, array $operations, $devMode = true, $runScripts = true)
  32. {
  33. foreach ($operations as $operation) {
  34. $method = $operation->getOperationType();
  35. // skipping download() step here for tests
  36. $this->$method($repo, $operation);
  37. }
  38. }
  39. public function getInstallPath(PackageInterface $package)
  40. {
  41. return '';
  42. }
  43. public function isPackageInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
  44. {
  45. return $repo->hasPackage($package);
  46. }
  47. public function install(RepositoryInterface $repo, InstallOperation $operation)
  48. {
  49. $this->installed[] = $operation->getPackage();
  50. $this->trace[] = strip_tags((string) $operation);
  51. $repo->addPackage(clone $operation->getPackage());
  52. }
  53. public function update(RepositoryInterface $repo, UpdateOperation $operation)
  54. {
  55. $this->updated[] = array($operation->getInitialPackage(), $operation->getTargetPackage());
  56. $this->trace[] = strip_tags((string) $operation);
  57. $repo->removePackage($operation->getInitialPackage());
  58. if (!$repo->hasPackage($operation->getTargetPackage())) {
  59. $repo->addPackage(clone $operation->getTargetPackage());
  60. }
  61. }
  62. public function uninstall(RepositoryInterface $repo, UninstallOperation $operation)
  63. {
  64. $this->uninstalled[] = $operation->getPackage();
  65. $this->trace[] = strip_tags((string) $operation);
  66. $repo->removePackage($operation->getPackage());
  67. }
  68. public function markAliasInstalled(RepositoryInterface $repo, MarkAliasInstalledOperation $operation)
  69. {
  70. $package = $operation->getPackage();
  71. $this->installed[] = $package;
  72. $this->trace[] = strip_tags((string) $operation);
  73. parent::markAliasInstalled($repo, $operation);
  74. }
  75. public function markAliasUninstalled(RepositoryInterface $repo, MarkAliasUninstalledOperation $operation)
  76. {
  77. $this->uninstalled[] = $operation->getPackage();
  78. $this->trace[] = strip_tags((string) $operation);
  79. parent::markAliasUninstalled($repo, $operation);
  80. }
  81. public function getTrace()
  82. {
  83. return $this->trace;
  84. }
  85. public function getInstalledPackages()
  86. {
  87. return $this->installed;
  88. }
  89. public function getUpdatedPackages()
  90. {
  91. return $this->updated;
  92. }
  93. public function getUninstalledPackages()
  94. {
  95. return $this->uninstalled;
  96. }
  97. }