TransactionTest.php 3.5 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\DependencyResolver;
  12. use Composer\DependencyResolver\Transaction;
  13. use Composer\Package\Link;
  14. use Composer\Test\TestCase;
  15. class TransactionTest extends TestCase
  16. {
  17. public function setUp()
  18. {
  19. }
  20. public function testTransactionGenerationAndSorting()
  21. {
  22. $presentPackages = array(
  23. $packageA = $this->getPackage('a/a', 'dev-master'),
  24. $packageAalias = $this->getAliasPackage($packageA, '1.0.x-dev'),
  25. $packageB = $this->getPackage('b/b', '1.0.0'),
  26. $packageE = $this->getPackage('e/e', 'dev-foo'),
  27. $packageEalias = $this->getAliasPackage($packageE, '1.0.x-dev'),
  28. $packageC = $this->getPackage('c/c', '1.0.0'),
  29. );
  30. $resultPackages = array(
  31. $packageA,
  32. $packageAalias,
  33. $packageBnew = $this->getPackage('b/b', '2.1.3'),
  34. $packageD = $this->getPackage('d/d', '1.2.3'),
  35. $packageF = $this->getPackage('f/f', '1.0.0'),
  36. $packageFalias1 = $this->getAliasPackage($packageF, 'dev-foo'),
  37. $packageG = $this->getPackage('g/g', '1.0.0'),
  38. $packageA0first = $this->getPackage('a0/first', '1.2.3'),
  39. $packageFalias2 = $this->getAliasPackage($packageF, 'dev-bar'),
  40. );
  41. $packageD->setRequires(array(
  42. 'f/f' => new Link('d/d', 'f/f', $this->getVersionConstraint('>', '0.2'), 'requires'),
  43. 'g/provider' => new Link('d/d', 'g/provider', $this->getVersionConstraint('>', '0.2'), 'requires'),
  44. ));
  45. $packageG->setProvides(array('g/provider' => new Link('g/g', 'g/provider', $this->getVersionConstraint('==', '1.0.0'), 'provides')));
  46. $expectedOperations = array(
  47. array('job' => 'uninstall', 'package' => $packageC),
  48. array('job' => 'uninstall', 'package' => $packageE),
  49. array('job' => 'markAliasUninstalled', 'package' => $packageEalias),
  50. array('job' => 'install', 'package' => $packageA0first),
  51. array('job' => 'update', 'from' => $packageB, 'to' => $packageBnew),
  52. array('job' => 'install', 'package' => $packageG),
  53. array('job' => 'install', 'package' => $packageF),
  54. array('job' => 'markAliasInstalled', 'package' => $packageFalias1),
  55. array('job' => 'markAliasInstalled', 'package' => $packageFalias2),
  56. array('job' => 'install', 'package' => $packageD),
  57. );
  58. $transaction = new Transaction($presentPackages, $resultPackages);
  59. $this->checkTransactionOperations($transaction, $expectedOperations);
  60. }
  61. protected function checkTransactionOperations(Transaction $transaction, array $expected)
  62. {
  63. $result = array();
  64. foreach ($transaction->getOperations() as $operation) {
  65. if ('update' === $operation->getOperationType()) {
  66. $result[] = array(
  67. 'job' => 'update',
  68. 'from' => $operation->getInitialPackage(),
  69. 'to' => $operation->getTargetPackage(),
  70. );
  71. } else {
  72. $result[] = array(
  73. 'job' => $operation->getOperationType(),
  74. 'package' => $operation->getPackage(),
  75. );
  76. }
  77. }
  78. $this->assertEquals($expected, $result);
  79. }
  80. }