SolverTest.php 24 KB

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