RootAliasPackageTest.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\Package;
  12. use Composer\Package\Link;
  13. use Composer\Package\RootAliasPackage;
  14. use Composer\Test\TestCase;
  15. use Prophecy\Argument;
  16. class RootAliasPackageTest extends TestCase
  17. {
  18. public function testUpdateRequires()
  19. {
  20. $root = $this->getMockRootPackageInterface();
  21. $root->setRequires(Argument::type('array'))->shouldBeCalled();
  22. $alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
  23. $this->assertEmpty($alias->getRequires());
  24. $links = array(new Link('a', 'b', null, 'foo', 'self.version'));
  25. $alias->setRequires($links);
  26. $this->assertNotEmpty($alias->getRequires());
  27. }
  28. public function testUpdateDevRequires()
  29. {
  30. $root = $this->getMockRootPackageInterface();
  31. $root->setDevRequires(Argument::type('array'))->shouldBeCalled();
  32. $alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
  33. $this->assertEmpty($alias->getDevRequires());
  34. $links = array(new Link('a', 'b', null, 'foo', 'self.version'));
  35. $alias->setDevRequires($links);
  36. $this->assertNotEmpty($alias->getDevRequires());
  37. }
  38. public function testUpdateConflicts()
  39. {
  40. $root = $this->getMockRootPackageInterface();
  41. $root->setConflicts(Argument::type('array'))->shouldBeCalled();
  42. $alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
  43. $this->assertEmpty($alias->getConflicts());
  44. $links = array(new Link('a', 'b', null, 'foo', 'self.version'));
  45. $alias->setConflicts($links);
  46. $this->assertNotEmpty($alias->getConflicts());
  47. }
  48. public function testUpdateProvides()
  49. {
  50. $root = $this->getMockRootPackageInterface();
  51. $root->setProvides(Argument::type('array'))->shouldBeCalled();
  52. $alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
  53. $this->assertEmpty($alias->getProvides());
  54. $links = array(new Link('a', 'b', null, 'foo', 'self.version'));
  55. $alias->setProvides($links);
  56. $this->assertNotEmpty($alias->getProvides());
  57. }
  58. public function testUpdateReplaces()
  59. {
  60. $root = $this->getMockRootPackageInterface();
  61. $root->setReplaces(Argument::type('array'))->shouldBeCalled();
  62. $alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
  63. $this->assertEmpty($alias->getReplaces());
  64. $links = array(new Link('a', 'b', null, 'foo', 'self.version'));
  65. $alias->setReplaces($links);
  66. $this->assertNotEmpty($alias->getReplaces());
  67. }
  68. protected function getMockRootPackageInterface()
  69. {
  70. $root = $this->prophesize('Composer\\Package\\RootPackageInterface');
  71. $root->getName()->willReturn('something/something')->shouldBeCalled();
  72. $root->getRequires()->willReturn(array())->shouldBeCalled();
  73. $root->getDevRequires()->willReturn(array())->shouldBeCalled();
  74. $root->getConflicts()->willReturn(array())->shouldBeCalled();
  75. $root->getProvides()->willReturn(array())->shouldBeCalled();
  76. $root->getReplaces()->willReturn(array())->shouldBeCalled();
  77. return $root;
  78. }
  79. }