InstallationManagerMock.php 3.0 KB

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