InstallationManagerMock.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. $package = $operation->getPackage();
  52. $this->installed[] = $package;
  53. $this->trace[] = (string) $operation;
  54. if (!$repo->hasPackage($package)) {
  55. $repo->addPackage($package);
  56. }
  57. }
  58. public function markAliasUninstalled(RepositoryInterface $repo, MarkAliasUninstalledOperation $operation)
  59. {
  60. $this->uninstalled[] = $operation->getPackage();
  61. $this->trace[] = (string) $operation;
  62. $repo->removePackage($operation->getPackage());
  63. }
  64. public function getTrace()
  65. {
  66. return $this->trace;
  67. }
  68. public function getInstalledPackages()
  69. {
  70. return $this->installed;
  71. }
  72. public function getUpdatedPackages()
  73. {
  74. return $this->updated;
  75. }
  76. public function getUninstalledPackages()
  77. {
  78. return $this->uninstalled;
  79. }
  80. }