InstallationManagerMock.php 2.8 KB

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