InstallationManagerMock.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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\OperationInterface;
  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 install(RepositoryInterface $repo, InstallOperation $operation)
  27. {
  28. $this->installed[] = $operation->getPackage();
  29. $this->trace[] = (string) $operation;
  30. $repo->addPackage(clone $operation->getPackage());
  31. }
  32. public function update(RepositoryInterface $repo, UpdateOperation $operation)
  33. {
  34. $this->updated[] = array($operation->getInitialPackage(), $operation->getTargetPackage());
  35. $this->trace[] = (string) $operation;
  36. $repo->removePackage($operation->getInitialPackage());
  37. $repo->addPackage(clone $operation->getTargetPackage());
  38. }
  39. public function uninstall(RepositoryInterface $repo, UninstallOperation $operation)
  40. {
  41. $this->uninstalled[] = $operation->getPackage();
  42. $this->trace[] = (string) $operation;
  43. $repo->removePackage($operation->getPackage());
  44. }
  45. public function markAliasInstalled(RepositoryInterface $repo, MarkAliasInstalledOperation $operation)
  46. {
  47. $this->installed[] = $operation->getPackage();
  48. $this->trace[] = (string) $operation;
  49. $repo->addPackage(clone $operation->getPackage());
  50. }
  51. public function markAliasUninstalled(RepositoryInterface $repo, MarkAliasUninstalledOperation $operation)
  52. {
  53. $this->uninstalled[] = $operation->getPackage();
  54. $this->trace[] = (string) $operation;
  55. $repo->removePackage($operation->getPackage());
  56. }
  57. public function getTrace()
  58. {
  59. return $this->trace;
  60. }
  61. public function getInstalledPackages()
  62. {
  63. return $this->installed;
  64. }
  65. public function getUpdatedPackages()
  66. {
  67. return $this->updated;
  68. }
  69. public function getUninstalledPackages()
  70. {
  71. return $this->uninstalled;
  72. }
  73. }