RequestTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\Repository\ArrayRepository;
  14. use Composer\Test\TestCase;
  15. class RequestTest extends TestCase
  16. {
  17. public function testRequestInstallAndRemove()
  18. {
  19. $repo = new ArrayRepository;
  20. $foo = $this->getPackage('foo', '1');
  21. $bar = $this->getPackage('bar', '1');
  22. $foobar = $this->getPackage('foobar', '1');
  23. $repo->addPackage($foo);
  24. $repo->addPackage($bar);
  25. $repo->addPackage($foobar);
  26. $request = new Request();
  27. $request->install('foo');
  28. $request->remove('foobar');
  29. $this->assertEquals(
  30. array(
  31. array('cmd' => 'install', 'packageName' => 'foo', 'constraint' => null),
  32. array('cmd' => 'remove', 'packageName' => 'foobar', 'constraint' => null),
  33. ),
  34. $request->getJobs()
  35. );
  36. }
  37. public function testRequestInstallSamePackageFromDifferentRepositories()
  38. {
  39. $repo1 = new ArrayRepository;
  40. $repo2 = new ArrayRepository;
  41. $foo1 = $this->getPackage('foo', '1');
  42. $foo2 = $this->getPackage('foo', '1');
  43. $repo1->addPackage($foo1);
  44. $repo2->addPackage($foo2);
  45. $request = new Request();
  46. $request->install('foo', $constraint = $this->getVersionConstraint('=', '1'));
  47. $this->assertEquals(
  48. array(
  49. array('cmd' => 'install', 'packageName' => 'foo', 'constraint' => $constraint),
  50. ),
  51. $request->getJobs()
  52. );
  53. }
  54. }