MagentoComposerApplicationTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. use Composer\Console\Application;
  7. use Magento\Composer\MagentoComposerApplication;
  8. use Magento\Composer\ConsoleArrayInputFactory;
  9. use Symfony\Component\Console\Output\BufferedOutput;
  10. class MagentoComposerApplicationTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var MagentoComposerApplication
  14. */
  15. protected $application;
  16. /**
  17. * @var Application|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $composerApplication;
  20. /**
  21. * @var ConsoleArrayInputFactory|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. protected $inputFactory;
  24. /**
  25. * @var BufferedOutput|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. protected $consoleOutput;
  28. protected function setUp()
  29. {
  30. $this->composerApplication = $this->createMock(\Composer\Console\Application::class);
  31. $this->inputFactory = $this->createMock(\Magento\Composer\ConsoleArrayInputFactory::class);
  32. $this->consoleOutput = $this->createMock(\Symfony\Component\Console\Output\BufferedOutput::class);
  33. $this->application = new MagentoComposerApplication(
  34. 'path1',
  35. 'path2',
  36. $this->composerApplication,
  37. $this->inputFactory,
  38. $this->consoleOutput
  39. );
  40. }
  41. /**
  42. * @expectedException \RuntimeException
  43. * @expectedExceptionMessage Command "update" failed
  44. */
  45. function testWrongExitCode()
  46. {
  47. $this->composerApplication->expects($this->once())->method('run')->willReturn(1);
  48. $this->application->runComposerCommand(['command'=>'update']);
  49. }
  50. function testRunCommand()
  51. {
  52. $inputData = ['command' => 'update', MagentoComposerApplication::COMPOSER_WORKING_DIR => '.'];
  53. $this->composerApplication->expects($this->once())->method('resetComposer');
  54. $this->inputFactory->expects($this->once())->method('create')->with($inputData);
  55. $this->consoleOutput->expects($this->once())->method('fetch')->willReturn('Nothing to update');
  56. $this->composerApplication->expects($this->once())->method('run')->willReturn(0);
  57. $message = $this->application->runComposerCommand($inputData);
  58. $this->assertEquals('Nothing to update', $message);
  59. }
  60. }