InfoCommandTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. use Magento\Composer\MagentoComposerApplication;
  7. use Magento\Composer\InfoCommand;
  8. class InfoCommandTest extends \PHPUnit\Framework\TestCase
  9. {
  10. private $installedOutput = 'name : 3rdp/a
  11. descrip. : Plugin project A
  12. keywords :
  13. versions : * 1.0.0
  14. type : library
  15. names : 3rdp/a
  16. requires
  17. php >=5.4.11
  18. 3rdp/c 1.1.0';
  19. /**
  20. * @var MagentoComposerApplication|\PHPUnit_Framework_MockObject_MockObject
  21. */
  22. protected $application;
  23. /**
  24. * @var InfoCommand
  25. */
  26. protected $infoCommand;
  27. protected function setUp()
  28. {
  29. $this->application = $this->createMock(\Magento\Composer\MagentoComposerApplication::class);
  30. $this->infoCommand = new InfoCommand($this->application);
  31. }
  32. /**
  33. * @dataProvider getCommandOutputDataProvider
  34. */
  35. public function testRun($input, $output)
  36. {
  37. $this->application->expects($this->once())->method('runComposerCommand')->willReturn($input);
  38. $result = $this->infoCommand->run('3rdp/a');
  39. $this->assertEquals($output, $result);
  40. }
  41. public function testRunInstalled()
  42. {
  43. $this->application->expects($this->once())->method('runComposerCommand')->willReturn($this->installedOutput);
  44. $result = $this->infoCommand->run('3rdp/a', true);
  45. $this->assertEquals(
  46. [
  47. 'name' => '3rdp/a',
  48. 'descrip.' => 'Plugin project A',
  49. 'versions' => '* 1.0.0',
  50. 'keywords' => '',
  51. 'type' => 'library',
  52. 'names' => '3rdp/a',
  53. 'current_version' => '1.0.0',
  54. 'available_versions' => [],
  55. 'new_versions' => []
  56. ],
  57. $result
  58. );
  59. }
  60. /**
  61. * Data provider that returns different input and output for composer info command.
  62. *
  63. * @return array
  64. */
  65. public function getCommandOutputDataProvider()
  66. {
  67. return [
  68. 'Package not installed' => [
  69. 'name : 3rdp/a
  70. descrip. : Plugin project A
  71. keywords :
  72. versions : 1.0.0, 1.1.0
  73. type : library
  74. names : 3rdp/a
  75. requires
  76. php >=5.4.11
  77. 3rdp/c 1.1.0',
  78. [
  79. 'name' => '3rdp/a',
  80. 'descrip.' => 'Plugin project A',
  81. 'versions' => '1.0.0, 1.1.0',
  82. 'keywords' => '',
  83. 'type' => 'library',
  84. 'names' => '3rdp/a',
  85. 'current_version' => '',
  86. 'available_versions' => [
  87. '1.0.0',
  88. '1.1.0'
  89. ],
  90. 'new_versions' => [
  91. '1.0.0',
  92. '1.1.0'
  93. ]
  94. ]
  95. ],
  96. 'Package installed' => [
  97. 'name : 3rdp/a
  98. descrip. : Plugin project A
  99. keywords :
  100. versions : 1.0.0, 1.1.0, * 1.1.2, 1.2.0
  101. type : library
  102. names : 3rdp/a
  103. requires
  104. php >=5.4.11
  105. 3rdp/c 1.1.0',
  106. [
  107. 'name' => '3rdp/a',
  108. 'descrip.' => 'Plugin project A',
  109. 'versions' => '1.0.0, 1.1.0, * 1.1.2, 1.2.0',
  110. 'keywords' => '',
  111. 'type' => 'library',
  112. 'names' => '3rdp/a',
  113. 'current_version' => '1.1.2',
  114. 'available_versions' => [
  115. '1.0.0',
  116. '1.1.0',
  117. '1.2.0'
  118. ],
  119. 'new_versions' => [
  120. '1.2.0'
  121. ]
  122. ]
  123. ],
  124. ];
  125. }
  126. }