RequestTest.php 2.5 KB

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