InstallationManagerMock.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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, OperationInterface $operation)
  32. {
  33. $method = $operation->getJobType();
  34. // skipping download() step here for tests
  35. $this->$method($repo, $operation);
  36. }
  37. public function getInstallPath(PackageInterface $package)
  38. {
  39. return '';
  40. }
  41. public function isPackageInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
  42. {
  43. return $repo->hasPackage($package);
  44. }
  45. public function install(RepositoryInterface $repo, InstallOperation $operation)
  46. {
  47. $this->installed[] = $operation->getPackage();
  48. $this->trace[] = (string) $operation;
  49. $repo->addPackage(clone $operation->getPackage());
  50. }
  51. public function update(RepositoryInterface $repo, UpdateOperation $operation)
  52. {
  53. $this->updated[] = array($operation->getInitialPackage(), $operation->getTargetPackage());
  54. $this->trace[] = (string) $operation;
  55. $repo->removePackage($operation->getInitialPackage());
  56. $repo->addPackage(clone $operation->getTargetPackage());
  57. }
  58. public function uninstall(RepositoryInterface $repo, UninstallOperation $operation)
  59. {
  60. $this->uninstalled[] = $operation->getPackage();
  61. $this->trace[] = (string) $operation;
  62. $repo->removePackage($operation->getPackage());
  63. }
  64. public function markAliasInstalled(RepositoryInterface $repo, MarkAliasInstalledOperation $operation)
  65. {
  66. $package = $operation->getPackage();
  67. $this->installed[] = $package;
  68. $this->trace[] = (string) $operation;
  69. parent::markAliasInstalled($repo, $operation);
  70. }
  71. public function markAliasUninstalled(RepositoryInterface $repo, MarkAliasUninstalledOperation $operation)
  72. {
  73. $this->uninstalled[] = $operation->getPackage();
  74. $this->trace[] = (string) $operation;
  75. parent::markAliasUninstalled($repo, $operation);
  76. }
  77. public function getTrace()
  78. {
  79. return $this->trace;
  80. }
  81. public function getInstalledPackages()
  82. {
  83. return $this->installed;
  84. }
  85. public function getUpdatedPackages()
  86. {
  87. return $this->updated;
  88. }
  89. public function getUninstalledPackages()
  90. {
  91. return $this->uninstalled;
  92. }
  93. }