InstallationManagerMock.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\UpdateOperation;
  18. use Composer\DependencyResolver\Operation\UninstallOperation;
  19. use Composer\DependencyResolver\Operation\MarkAliasInstalledOperation;
  20. use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
  21. class InstallationManagerMock extends InstallationManager
  22. {
  23. private $installed = array();
  24. private $updated = array();
  25. private $uninstalled = array();
  26. private $trace = array();
  27. public function getInstallPath(PackageInterface $package)
  28. {
  29. return '';
  30. }
  31. public function install(RepositoryInterface $repo, InstallOperation $operation)
  32. {
  33. $this->installed[] = $operation->getPackage();
  34. $this->trace[] = (string) $operation;
  35. $repo->addPackage(clone $operation->getPackage());
  36. }
  37. public function update(RepositoryInterface $repo, UpdateOperation $operation)
  38. {
  39. $this->updated[] = array($operation->getInitialPackage(), $operation->getTargetPackage());
  40. $this->trace[] = (string) $operation;
  41. $repo->removePackage($operation->getInitialPackage());
  42. $repo->addPackage(clone $operation->getTargetPackage());
  43. }
  44. public function uninstall(RepositoryInterface $repo, UninstallOperation $operation)
  45. {
  46. $this->uninstalled[] = $operation->getPackage();
  47. $this->trace[] = (string) $operation;
  48. $repo->removePackage($operation->getPackage());
  49. }
  50. public function markAliasInstalled(RepositoryInterface $repo, MarkAliasInstalledOperation $operation)
  51. {
  52. $package = $operation->getPackage();
  53. $this->installed[] = $package;
  54. $this->trace[] = (string) $operation;
  55. if (!$repo->hasPackage($package)) {
  56. $repo->addPackage($package);
  57. }
  58. }
  59. public function markAliasUninstalled(RepositoryInterface $repo, MarkAliasUninstalledOperation $operation)
  60. {
  61. $this->uninstalled[] = $operation->getPackage();
  62. $this->trace[] = (string) $operation;
  63. $repo->removePackage($operation->getPackage());
  64. }
  65. public function getTrace()
  66. {
  67. return $this->trace;
  68. }
  69. public function getInstalledPackages()
  70. {
  71. return $this->installed;
  72. }
  73. public function getUpdatedPackages()
  74. {
  75. return $this->updated;
  76. }
  77. public function getUninstalledPackages()
  78. {
  79. return $this->uninstalled;
  80. }
  81. }