RequireUpdateDryRunCommandTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. use Magento\Composer\RequireUpdateDryRunCommand;
  9. class RequireUpdateDryRunCommandTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var MagentoComposerApplication|\PHPUnit_Framework_MockObject_MockObject
  13. */
  14. protected $application;
  15. /**
  16. * @var InfoCommand|\PHPUnit_Framework_MockObject_MockObject
  17. */
  18. protected $infoCommand;
  19. /**
  20. * @var RequireUpdateDryRunCommand
  21. */
  22. protected $requireUpdateDryRunCommand;
  23. /**
  24. * @var string
  25. */
  26. private $errorMessage = 'Loading composer repositories with package information
  27. Updating dependencies (including require-dev)
  28. Your requirements could not be resolved to an installable set of packages.
  29. Problem 1
  30. - 3rdp/e 1.0.0 requires 3rdp/d 1.0.0 -> no matching package found.
  31. - 3rdp/e 1.0.0 requires 3rdp/d 1.0.0 -> no matching package found.
  32. - 3rdp/e 1.0.0 requires 3rdp/d 1.0.0 -> no matching package found.
  33. - Installation request for 3rdp/e 1.0.0 -> satisfiable by 3rdp/e[1.0.0].
  34. Potential causes:
  35. - A typo in the package name
  36. - The package is not available in a stable-enough version according to your minimum-stability setting
  37. see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
  38. Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.';
  39. /**
  40. * @var string
  41. */
  42. private $packageInfo = [
  43. 'name' => '3rdp/d',
  44. 'descrip.' => 'Plugin project A',
  45. 'versions' => '* 1.0.0, 1.1.0, 1.2.0',
  46. 'keywords' => '',
  47. 'type' => 'library',
  48. 'names' => '3rdp/d',
  49. 'current_version' => '1.0.0',
  50. 'available_versions' => [
  51. '1.1.0',
  52. '1.2.0'
  53. ]
  54. ];
  55. protected function setUp()
  56. {
  57. $this->application = $this->createMock(\Magento\Composer\MagentoComposerApplication::class);
  58. $this->infoCommand = $this->createMock(\Magento\Composer\InfoCommand::class);
  59. $this->requireUpdateDryRunCommand = new RequireUpdateDryRunCommand(
  60. $this->application,
  61. $this->infoCommand
  62. );
  63. }
  64. public function testRun()
  65. {
  66. $this->application->expects($this->exactly(2))->method('runComposerCommand');
  67. $this->requireUpdateDryRunCommand->run([], '');
  68. }
  69. /**
  70. * @expectedException \RuntimeException
  71. * @expectedExceptionMessage
  72. */
  73. public function testRunException()
  74. {
  75. $this->application->expects($this->at(1))
  76. ->method('runComposerCommand')
  77. ->willThrowException(new \RuntimeException($this->errorMessage));
  78. $this->infoCommand->expects($this->once())->method('run')->willReturn($this->packageInfo);
  79. $this->requireUpdateDryRunCommand->run(['3rdp/e 1.2.0'], '');
  80. }
  81. }