InstallationManagerMock.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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[] = (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[] = (string) $operation;
  57. $repo->removePackage($operation->getInitialPackage());
  58. $repo->addPackage(clone $operation->getTargetPackage());
  59. }
  60. public function uninstall(RepositoryInterface $repo, UninstallOperation $operation)
  61. {
  62. $this->uninstalled[] = $operation->getPackage();
  63. $this->trace[] = (string) $operation;
  64. $repo->removePackage($operation->getPackage());
  65. }
  66. public function markAliasInstalled(RepositoryInterface $repo, MarkAliasInstalledOperation $operation)
  67. {
  68. $package = $operation->getPackage();
  69. $this->installed[] = $package;
  70. $this->trace[] = (string) $operation;
  71. parent::markAliasInstalled($repo, $operation);
  72. }
  73. public function markAliasUninstalled(RepositoryInterface $repo, MarkAliasUninstalledOperation $operation)
  74. {
  75. $this->uninstalled[] = $operation->getPackage();
  76. $this->trace[] = (string) $operation;
  77. parent::markAliasUninstalled($repo, $operation);
  78. }
  79. public function getTrace()
  80. {
  81. return $this->trace;
  82. }
  83. public function getInstalledPackages()
  84. {
  85. return $this->installed;
  86. }
  87. public function getUpdatedPackages()
  88. {
  89. return $this->updated;
  90. }
  91. public function getUninstalledPackages()
  92. {
  93. return $this->uninstalled;
  94. }
  95. }