InstallationManagerMock.php 2.6 KB

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