RequestTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\Request;
  13. use Composer\DependencyResolver\Pool;
  14. use Composer\Repository\ArrayRepository;
  15. use Composer\DependencyResolver\Literal;
  16. use Composer\Test\TestCase;
  17. class RequestTest extends TestCase
  18. {
  19. public function testRequestInstallAndRemove()
  20. {
  21. $pool = new Pool;
  22. $repo = new ArrayRepository;
  23. $foo = $this->getPackage('foo', '1');
  24. $bar = $this->getPackage('bar', '1');
  25. $foobar = $this->getPackage('foobar', '1');
  26. $repo->addPackage($foo);
  27. $repo->addPackage($bar);
  28. $repo->addPackage($foobar);
  29. $pool->addRepository($repo);
  30. $request = new Request($pool);
  31. $request->install('foo');
  32. $request->install('bar');
  33. $request->remove('foobar');
  34. $this->assertEquals(
  35. array(
  36. array('packages' => array($foo), 'cmd' => 'install', 'packageName' => 'foo'),
  37. array('packages' => array($bar), 'cmd' => 'install', 'packageName' => 'bar'),
  38. array('packages' => array($foobar), 'cmd' => 'remove', 'packageName' => 'foobar'),
  39. ),
  40. $request->getJobs());
  41. }
  42. public function testRequestInstallSamePackageFromDifferentRepositories()
  43. {
  44. $pool = new Pool;
  45. $repo1 = new ArrayRepository;
  46. $repo2 = new ArrayRepository;
  47. $foo1 = $this->getPackage('foo', '1');
  48. $foo2 = $this->getPackage('foo', '1');
  49. $repo1->addPackage($foo1);
  50. $repo2->addPackage($foo2);
  51. $pool->addRepository($repo1);
  52. $pool->addRepository($repo2);
  53. $request = new Request($pool);
  54. $request->install('foo', $this->getVersionConstraint('=', '1'));
  55. $this->assertEquals(
  56. array(
  57. array('packages' => array($foo1, $foo2), 'cmd' => 'install', 'packageName' => 'foo'),
  58. ),
  59. $request->getJobs()
  60. );
  61. }
  62. public function testUpdateAll()
  63. {
  64. $pool = new Pool;
  65. $request = new Request($pool);
  66. $request->updateAll();
  67. $this->assertEquals(
  68. array(array('cmd' => 'update-all', 'packages' => array())),
  69. $request->getJobs());
  70. }
  71. }