SolverTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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\Repository\ArrayRepository;
  13. use Composer\Repository\PlatformRepository;
  14. use Composer\Repository\ComposerRepository;
  15. use Composer\DependencyResolver\DefaultPolicy;
  16. use Composer\DependencyResolver\Pool;
  17. use Composer\DependencyResolver\Request;
  18. use Composer\DependencyResolver\Solver;
  19. use Composer\DependencyResolver\SolverProblemsException;
  20. use Composer\Package\Link;
  21. use Composer\Package\LinkConstraint\VersionConstraint;
  22. use Composer\Test\TestCase;
  23. class SolverTest extends TestCase
  24. {
  25. protected $pool;
  26. protected $repo;
  27. protected $repoInstalled;
  28. protected $request;
  29. protected $policy;
  30. public function setUp()
  31. {
  32. $this->pool = new Pool;
  33. $this->repo = new ArrayRepository;
  34. $this->repoInstalled = new ArrayRepository;
  35. $this->request = new Request($this->pool);
  36. $this->policy = new DefaultPolicy;
  37. $this->solver = new Solver($this->policy, $this->pool, $this->repoInstalled);
  38. }
  39. public function testSolverInstallSingle()
  40. {
  41. $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
  42. $this->reposComplete();
  43. $this->request->install('A');
  44. $this->checkSolverResult(array(
  45. array('job' => 'install', 'package' => $packageA),
  46. ));
  47. }
  48. public function testInstallNonExistingPackageFails()
  49. {
  50. $this->repo->addPackage($this->getPackage('A', '1.0'));
  51. $this->reposComplete();
  52. $this->request->install('B');
  53. try {
  54. $transaction = $this->solver->solve($this->request);
  55. $this->fail('Unsolvable conflict did not resolve in exception.');
  56. } catch (SolverProblemsException $e) {
  57. // TODO assert problem properties
  58. }
  59. }
  60. public function testSolverInstallSamePackageFromDifferentRepositories()
  61. {
  62. $repo1 = new ArrayRepository;
  63. $repo2 = new ArrayRepository;
  64. $repo1->addPackage($foo1 = $this->getPackage('foo', '1'));
  65. $repo2->addPackage($foo2 = $this->getPackage('foo', '1'));
  66. $this->pool->addRepository($this->repoInstalled);
  67. $this->pool->addRepository($repo1);
  68. $this->pool->addRepository($repo2);
  69. $this->request->install('foo');
  70. $this->checkSolverResult(array(
  71. array('job' => 'install', 'package' => $foo1),
  72. ));
  73. }
  74. public function testSolverInstallWithDeps()
  75. {
  76. $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
  77. $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
  78. $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
  79. $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('<', '1.1'), 'requires')));
  80. $this->reposComplete();
  81. $this->request->install('A');
  82. $this->checkSolverResult(array(
  83. array('job' => 'install', 'package' => $packageB),
  84. array('job' => 'install', 'package' => $packageA),
  85. ));
  86. }
  87. public function testSolverInstallInstalled()
  88. {
  89. $this->repoInstalled->addPackage($this->getPackage('A', '1.0'));
  90. $this->reposComplete();
  91. $this->request->install('A');
  92. $this->checkSolverResult(array());
  93. }
  94. public function testSolverInstallInstalledWithAlternative()
  95. {
  96. $this->repo->addPackage($this->getPackage('A', '1.0'));
  97. $this->repoInstalled->addPackage($this->getPackage('A', '1.0'));
  98. $this->reposComplete();
  99. $this->request->install('A');
  100. $this->checkSolverResult(array());
  101. }
  102. public function testSolverRemoveSingle()
  103. {
  104. $this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0'));
  105. $this->reposComplete();
  106. $this->request->remove('A');
  107. $this->checkSolverResult(array(
  108. array('job' => 'remove', 'package' => $packageA),
  109. ));
  110. }
  111. public function testSolverRemoveUninstalled()
  112. {
  113. $this->repo->addPackage($this->getPackage('A', '1.0'));
  114. $this->reposComplete();
  115. $this->request->remove('A');
  116. $this->checkSolverResult(array());
  117. }
  118. public function testSolverUpdateDoesOnlyUpdate()
  119. {
  120. $this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0'));
  121. $this->repoInstalled->addPackage($packageB = $this->getPackage('B', '1.0'));
  122. $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
  123. $this->reposComplete();
  124. $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '1.0.0.0'), 'requires')));
  125. $this->request->install('A', $this->getVersionConstraint('=', '1.0.0.0'));
  126. $this->request->install('B', $this->getVersionConstraint('=', '1.1.0.0'));
  127. $this->request->update('A', $this->getVersionConstraint('=', '1.0.0.0'));
  128. $this->request->update('B', $this->getVersionConstraint('=', '1.0.0.0'));
  129. $this->checkSolverResult(array(
  130. array('job' => 'update', 'from' => $packageB, 'to' => $newPackageB),
  131. ));
  132. }
  133. public function testSolverUpdateSingle()
  134. {
  135. $this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0'));
  136. $this->repo->addPackage($newPackageA = $this->getPackage('A', '1.1'));
  137. $this->reposComplete();
  138. $this->request->update('A');
  139. $this->checkSolverResult(array(
  140. array('job' => 'update', 'from' => $packageA, 'to' => $newPackageA),
  141. ));
  142. }
  143. public function testSolverUpdateAll()
  144. {
  145. $this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0'));
  146. $this->repoInstalled->addPackage($packageB = $this->getPackage('B', '1.0'));
  147. $this->repo->addPackage($newPackageA = $this->getPackage('A', '1.1'));
  148. $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
  149. $packageA->setRequires(array(new Link('A', 'B', null, 'requires')));
  150. $this->reposComplete();
  151. $this->request->install('A');
  152. $this->request->updateAll();
  153. $this->checkSolverResult(array(
  154. array('job' => 'update', 'from' => $packageB, 'to' => $newPackageB),
  155. array('job' => 'update', 'from' => $packageA, 'to' => $newPackageA),
  156. ));
  157. }
  158. public function testSolverUpdateCurrent()
  159. {
  160. $this->repoInstalled->addPackage($this->getPackage('A', '1.0'));
  161. $this->repo->addPackage($this->getPackage('A', '1.0'));
  162. $this->reposComplete();
  163. $this->request->update('A');
  164. $this->checkSolverResult(array());
  165. }
  166. public function testSolverUpdateOnlyUpdatesSelectedPackage()
  167. {
  168. $this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0'));
  169. $this->repoInstalled->addPackage($packageB = $this->getPackage('B', '1.0'));
  170. $this->repo->addPackage($packageAnewer = $this->getPackage('A', '1.1'));
  171. $this->repo->addPackage($packageBnewer = $this->getPackage('B', '1.1'));
  172. $this->reposComplete();
  173. $this->request->update('A');
  174. $this->checkSolverResult(array(
  175. array('job' => 'update', 'from' => $packageA, 'to' => $packageAnewer),
  176. ));
  177. }
  178. public function testSolverUpdateConstrained()
  179. {
  180. $this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0'));
  181. $this->repo->addPackage($newPackageA = $this->getPackage('A', '1.2'));
  182. $this->repo->addPackage($this->getPackage('A', '2.0'));
  183. $this->reposComplete();
  184. $this->request->install('A', $this->getVersionConstraint('<', '2.0.0.0'));
  185. $this->request->update('A');
  186. $this->checkSolverResult(array(array(
  187. 'job' => 'update',
  188. 'from' => $packageA,
  189. 'to' => $newPackageA,
  190. )));
  191. }
  192. public function testSolverUpdateFullyConstrained()
  193. {
  194. $this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0'));
  195. $this->repo->addPackage($newPackageA = $this->getPackage('A', '1.2'));
  196. $this->repo->addPackage($this->getPackage('A', '2.0'));
  197. $this->reposComplete();
  198. $this->request->install('A', $this->getVersionConstraint('<', '2.0.0.0'));
  199. $this->request->update('A', $this->getVersionConstraint('=', '1.0.0.0'));
  200. $this->checkSolverResult(array(array(
  201. 'job' => 'update',
  202. 'from' => $packageA,
  203. 'to' => $newPackageA,
  204. )));
  205. }
  206. public function testSolverUpdateFullyConstrainedPrunesInstalledPackages()
  207. {
  208. $this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0'));
  209. $this->repoInstalled->addPackage($this->getPackage('B', '1.0'));
  210. $this->repo->addPackage($newPackageA = $this->getPackage('A', '1.2'));
  211. $this->repo->addPackage($this->getPackage('A', '2.0'));
  212. $this->reposComplete();
  213. $this->request->install('A', $this->getVersionConstraint('<', '2.0.0.0'));
  214. $this->request->update('A', $this->getVersionConstraint('=', '1.0.0.0'));
  215. $this->checkSolverResult(array(array(
  216. 'job' => 'update',
  217. 'from' => $packageA,
  218. 'to' => $newPackageA,
  219. )));
  220. }
  221. public function testSolverAllJobs()
  222. {
  223. $this->repoInstalled->addPackage($packageD = $this->getPackage('D', '1.0'));
  224. $this->repoInstalled->addPackage($oldPackageC = $this->getPackage('C', '1.0'));
  225. $this->repo->addPackage($packageA = $this->getPackage('A', '2.0'));
  226. $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
  227. $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
  228. $this->repo->addPackage($packageC = $this->getPackage('C', '1.1'));
  229. $this->repo->addPackage($this->getPackage('D', '1.0'));
  230. $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('<', '1.1'), 'requires')));
  231. $this->reposComplete();
  232. $this->request->install('A');
  233. $this->request->update('C');
  234. $this->request->remove('D');
  235. $this->checkSolverResult(array(
  236. array('job' => 'update', 'from' => $oldPackageC, 'to' => $packageC),
  237. array('job' => 'install', 'package' => $packageB),
  238. array('job' => 'remove', 'package' => $packageD),
  239. array('job' => 'install', 'package' => $packageA),
  240. ));
  241. }
  242. public function testSolverThreeAlternativeRequireAndConflict()
  243. {
  244. $this->repo->addPackage($packageA = $this->getPackage('A', '2.0'));
  245. $this->repo->addPackage($middlePackageB = $this->getPackage('B', '1.0'));
  246. $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
  247. $this->repo->addPackage($oldPackageB = $this->getPackage('B', '0.9'));
  248. $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('<', '1.1'), 'requires')));
  249. $packageA->setConflicts(array(new Link('A', 'B', $this->getVersionConstraint('<', '1.0'), 'conflicts')));
  250. $this->reposComplete();
  251. $this->request->install('A');
  252. $this->checkSolverResult(array(
  253. array('job' => 'install', 'package' => $middlePackageB),
  254. array('job' => 'install', 'package' => $packageA),
  255. ));
  256. }
  257. public function testSolverObsolete()
  258. {
  259. $this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0'));
  260. $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
  261. $packageB->setReplaces(array(new Link('B', 'A', null)));
  262. $this->reposComplete();
  263. $this->request->install('B');
  264. $this->checkSolverResult(array(
  265. array('job' => 'update', 'from' => $packageA, 'to' => $packageB),
  266. ));
  267. }
  268. public function testInstallOneOfTwoAlternatives()
  269. {
  270. $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
  271. $this->repo->addPackage($packageB = $this->getPackage('A', '1.0'));
  272. $this->reposComplete();
  273. $this->request->install('A');
  274. $this->checkSolverResult(array(
  275. array('job' => 'install', 'package' => $packageA),
  276. ));
  277. }
  278. public function testInstallProvider()
  279. {
  280. $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
  281. $this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
  282. $this->repo->addPackage($packageB = $this->getPackage('B', '0.8'));
  283. $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
  284. $packageQ->setProvides(array(new Link('Q', 'B', $this->getVersionConstraint('=', '1.0'), 'provides')));
  285. $this->reposComplete();
  286. $this->request->install('A');
  287. $this->checkSolverResult(array(
  288. array('job' => 'install', 'package' => $packageQ),
  289. array('job' => 'install', 'package' => $packageA),
  290. ));
  291. }
  292. public function testSkipReplacerOfExistingPackage()
  293. {
  294. $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
  295. $this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
  296. $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
  297. $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
  298. $packageQ->setReplaces(array(new Link('Q', 'B', $this->getVersionConstraint('>=', '1.0'), 'replaces')));
  299. $this->reposComplete();
  300. $this->request->install('A');
  301. $this->checkSolverResult(array(
  302. array('job' => 'install', 'package' => $packageB),
  303. array('job' => 'install', 'package' => $packageA),
  304. ));
  305. }
  306. public function testInstallReplacerOfMissingPackage()
  307. {
  308. $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
  309. $this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
  310. $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
  311. $packageQ->setReplaces(array(new Link('Q', 'B', $this->getVersionConstraint('>=', '1.0'), 'replaces')));
  312. $this->reposComplete();
  313. $this->request->install('A');
  314. $this->checkSolverResult(array(
  315. array('job' => 'install', 'package' => $packageQ),
  316. array('job' => 'install', 'package' => $packageA),
  317. ));
  318. }
  319. public function testSkipReplacedPackageIfReplacerIsSelected()
  320. {
  321. $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
  322. $this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
  323. $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
  324. $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
  325. $packageQ->setReplaces(array(new Link('Q', 'B', $this->getVersionConstraint('>=', '1.0'), 'replaces')));
  326. $this->reposComplete();
  327. $this->request->install('A');
  328. $this->request->install('Q');
  329. $this->checkSolverResult(array(
  330. array('job' => 'install', 'package' => $packageQ),
  331. array('job' => 'install', 'package' => $packageA),
  332. ));
  333. }
  334. public function testPickOlderIfNewerConflicts()
  335. {
  336. $this->repo->addPackage($packageX = $this->getPackage('X', '1.0'));
  337. $packageX->setRequires(array(
  338. new Link('X', 'A', $this->getVersionConstraint('>=', '2.0.0.0'), 'requires'),
  339. new Link('X', 'B', $this->getVersionConstraint('>=', '2.0.0.0'), 'requires')));
  340. $this->repo->addPackage($packageA = $this->getPackage('A', '2.0.0'));
  341. $this->repo->addPackage($newPackageA = $this->getPackage('A', '2.1.0'));
  342. $this->repo->addPackage($newPackageB = $this->getPackage('B', '2.1.0'));
  343. $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '2.0.0.0'), 'requires')));
  344. // new package A depends on version of package B that does not exist
  345. // => new package A is not installable
  346. $newPackageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '2.2.0.0'), 'requires')));
  347. // add a package S replacing both A and B, so that S and B or S and A cannot be simultaneously installed
  348. // but an alternative option for A and B both exists
  349. // this creates a more difficult so solve conflict
  350. $this->repo->addPackage($packageS = $this->getPackage('S', '2.0.0'));
  351. $packageS->setReplaces(array(new Link('S', 'A', $this->getVersionConstraint('>=', '2.0.0.0'), 'replaces'), new Link('S', 'B', $this->getVersionConstraint('>=', '2.0.0.0'), 'replaces')));
  352. $this->reposComplete();
  353. $this->request->install('X');
  354. $this->checkSolverResult(array(
  355. array('job' => 'install', 'package' => $packageA),
  356. array('job' => 'install', 'package' => $newPackageB),
  357. array('job' => 'install', 'package' => $packageX),
  358. ));
  359. }
  360. public function testInstallCircularRequire()
  361. {
  362. $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
  363. $this->repo->addPackage($packageB1 = $this->getPackage('B', '0.9'));
  364. $this->repo->addPackage($packageB2 = $this->getPackage('B', '1.1'));
  365. $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
  366. $packageB2->setRequires(array(new Link('B', 'A', $this->getVersionConstraint('>=', '1.0'), 'requires')));
  367. $this->reposComplete();
  368. $this->request->install('A');
  369. $this->checkSolverResult(array(
  370. array('job' => 'install', 'package' => $packageB2),
  371. array('job' => 'install', 'package' => $packageA),
  372. ));
  373. }
  374. public function testInstallAlternativeWithCircularRequire()
  375. {
  376. $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
  377. $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
  378. $this->repo->addPackage($packageC = $this->getPackage('C', '1.0'));
  379. $this->repo->addPackage($packageD = $this->getPackage('D', '1.0'));
  380. $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
  381. $packageB->setRequires(array(new Link('B', 'Virtual', $this->getVersionConstraint('>=', '1.0'), 'requires')));
  382. $packageC->setProvides(array(new Link('C', 'Virtual', $this->getVersionConstraint('==', '1.0'), 'provides')));
  383. $packageD->setProvides(array(new Link('D', 'Virtual', $this->getVersionConstraint('==', '1.0'), 'provides')));
  384. $packageC->setRequires(array(new Link('C', 'A', $this->getVersionConstraint('==', '1.0'), 'requires')));
  385. $packageD->setRequires(array(new Link('D', 'A', $this->getVersionConstraint('==', '1.0'), 'requires')));
  386. $this->reposComplete();
  387. $this->request->install('A');
  388. $this->checkSolverResult(array(
  389. array('job' => 'install', 'package' => $packageC),
  390. array('job' => 'install', 'package' => $packageB),
  391. array('job' => 'install', 'package' => $packageA),
  392. ));
  393. }
  394. /**
  395. * If a replacer D replaces B and C with C not otherwise available,
  396. * D must be installed instead of the original B.
  397. */
  398. public function testUseReplacerIfNecessary()
  399. {
  400. $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
  401. $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
  402. $this->repo->addPackage($packageD = $this->getPackage('D', '1.0'));
  403. $this->repo->addPackage($packageD2 = $this->getPackage('D', '1.1'));
  404. $packageA->setRequires(array(
  405. new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires'),
  406. new Link('A', 'C', $this->getVersionConstraint('>=', '1.0'), 'requires'),
  407. ));
  408. $packageD->setReplaces(array(
  409. new Link('D', 'B', $this->getVersionConstraint('>=', '1.0'), 'replaces'),
  410. new Link('D', 'C', $this->getVersionConstraint('>=', '1.0'), 'replaces'),
  411. ));
  412. $packageD2->setReplaces(array(
  413. new Link('D', 'B', $this->getVersionConstraint('>=', '1.0'), 'replaces'),
  414. new Link('D', 'C', $this->getVersionConstraint('>=', '1.0'), 'replaces'),
  415. ));
  416. $this->reposComplete();
  417. $this->request->install('A');
  418. $this->checkSolverResult(array(
  419. array('job' => 'install', 'package' => $packageD2),
  420. array('job' => 'install', 'package' => $packageA),
  421. ));
  422. }
  423. public function testIssue265()
  424. {
  425. $this->repo->addPackage($packageA1 = $this->getPackage('A', '2.0.999999-dev'));
  426. $this->repo->addPackage($packageA2 = $this->getPackage('A', '2.1-dev'));
  427. $this->repo->addPackage($packageA3 = $this->getPackage('A', '2.2-dev'));
  428. $this->repo->addPackage($packageB1 = $this->getPackage('B', '2.0.10'));
  429. $this->repo->addPackage($packageB2 = $this->getPackage('B', '2.0.9'));
  430. $this->repo->addPackage($packageC = $this->getPackage('C', '2.0-dev'));
  431. $this->repo->addPackage($packageD = $this->getPackage('D', '2.0.9'));
  432. $packageC->setRequires(array(
  433. new Link('C', 'A', $this->getVersionConstraint('>=', '2.0'), 'requires'),
  434. new Link('C', 'D', $this->getVersionConstraint('>=', '2.0'), 'requires'),
  435. ));
  436. $packageD->setRequires(array(
  437. new Link('D', 'A', $this->getVersionConstraint('>=', '2.1'), 'requires'),
  438. new Link('D', 'B', $this->getVersionConstraint('>=', '2.0-dev'), 'requires'),
  439. ));
  440. $packageB1->setRequires(array(new Link('B', 'A', $this->getVersionConstraint('==', '2.1.0.0-dev'), 'requires')));
  441. $packageB2->setRequires(array(new Link('B', 'A', $this->getVersionConstraint('==', '2.1.0.0-dev'), 'requires')));
  442. $packageB2->setReplaces(array(new Link('B', 'D', $this->getVersionConstraint('==', '2.0.9.0'), 'replaces')));
  443. $this->reposComplete();
  444. $this->request->install('C', $this->getVersionConstraint('==', '2.0.0.0-dev'));
  445. $this->setExpectedException('Composer\DependencyResolver\SolverProblemsException');
  446. $this->solver->solve($this->request);
  447. }
  448. public function testConflictResultEmpty()
  449. {
  450. $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
  451. $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));;
  452. $packageA->setConflicts(array(
  453. new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'conflicts'),
  454. ));
  455. $this->reposComplete();
  456. $this->request->install('A');
  457. $this->request->install('B');
  458. try {
  459. $transaction = $this->solver->solve($this->request);
  460. $this->fail('Unsolvable conflict did not resolve in exception.');
  461. } catch (SolverProblemsException $e) {
  462. // TODO assert problem properties
  463. }
  464. }
  465. public function testUnsatisfiableRequires()
  466. {
  467. $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
  468. $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
  469. $packageA->setRequires(array(
  470. new Link('A', 'B', $this->getVersionConstraint('>=', '2.0'), 'requires'),
  471. ));
  472. $this->reposComplete();
  473. $this->request->install('A');
  474. try {
  475. $transaction = $this->solver->solve($this->request);
  476. $this->fail('Unsolvable conflict did not resolve in exception.');
  477. } catch (SolverProblemsException $e) {
  478. // TODO assert problem properties
  479. }
  480. }
  481. protected function reposComplete()
  482. {
  483. $this->pool->addRepository($this->repoInstalled);
  484. $this->pool->addRepository($this->repo);
  485. }
  486. protected function checkSolverResult(array $expected)
  487. {
  488. $transaction = $this->solver->solve($this->request);
  489. $result = array();
  490. foreach ($transaction as $operation) {
  491. if ('update' === $operation->getJobType()) {
  492. $result[] = array(
  493. 'job' => 'update',
  494. 'from' => $operation->getInitialPackage(),
  495. 'to' => $operation->getTargetPackage()
  496. );
  497. } else {
  498. $job = ('uninstall' === $operation->getJobType() ? 'remove' : 'install');
  499. $result[] = array(
  500. 'job' => $job,
  501. 'package' => $operation->getPackage()
  502. );
  503. }
  504. }
  505. $this->assertEquals($expected, $result);
  506. }
  507. }