RequestTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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->fix('bar');
  29. $request->remove('foobar');
  30. $this->assertEquals(
  31. array(
  32. array('cmd' => 'install', 'packageName' => 'foo', 'constraint' => null, 'fixed' => false),
  33. array('cmd' => 'install', 'packageName' => 'bar', 'constraint' => null, 'fixed' => true),
  34. array('cmd' => 'remove', 'packageName' => 'foobar', 'constraint' => null, 'fixed' => false),
  35. ),
  36. $request->getJobs()
  37. );
  38. }
  39. public function testRequestInstallSamePackageFromDifferentRepositories()
  40. {
  41. $repo1 = new ArrayRepository;
  42. $repo2 = new ArrayRepository;
  43. $foo1 = $this->getPackage('foo', '1');
  44. $foo2 = $this->getPackage('foo', '1');
  45. $repo1->addPackage($foo1);
  46. $repo2->addPackage($foo2);
  47. $request = new Request();
  48. $request->install('foo', $constraint = $this->getVersionConstraint('=', '1'));
  49. $this->assertEquals(
  50. array(
  51. array('cmd' => 'install', 'packageName' => 'foo', 'constraint' => $constraint, 'fixed' => false),
  52. ),
  53. $request->getJobs()
  54. );
  55. }
  56. public function testUpdateAll()
  57. {
  58. $request = new Request();
  59. $request->updateAll();
  60. $this->assertEquals(
  61. array(array('cmd' => 'update-all')),
  62. $request->getJobs()
  63. );
  64. }
  65. }