|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +use Composer\Console\Application; |
| 8 | +use Magento\Composer\MagentoComposerApplication; |
| 9 | +use Magento\Composer\ConsoleArrayInputFactory; |
| 10 | +use Symfony\Component\Console\Output\BufferedOutput; |
| 11 | + |
| 12 | +class MagentoComposerApplicationTest extends PHPUnit_Framework_TestCase { |
| 13 | + |
| 14 | + /** |
| 15 | + * @var MagentoComposerApplication |
| 16 | + */ |
| 17 | + protected $application; |
| 18 | + |
| 19 | + /** |
| 20 | + * @var Application|\PHPUnit_Framework_MockObject_MockObject |
| 21 | + */ |
| 22 | + protected $composerApplication; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var ConsoleArrayInputFactory|\PHPUnit_Framework_MockObject_MockObject |
| 26 | + */ |
| 27 | + protected $inputFactory; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var BufferedOutput|\PHPUnit_Framework_MockObject_MockObject |
| 31 | + */ |
| 32 | + protected $consoleOutput; |
| 33 | + |
| 34 | + protected function setUp() |
| 35 | + { |
| 36 | + $this->composerApplication = $this->getMock( |
| 37 | + 'Composer\Console\Application', |
| 38 | + [ |
| 39 | + 'resetComposer', |
| 40 | + 'create', |
| 41 | + 'run' |
| 42 | + ], |
| 43 | + [], |
| 44 | + '', |
| 45 | + false, |
| 46 | + false |
| 47 | + ); |
| 48 | + $this->inputFactory = $this->getMock('Magento\Composer\ConsoleArrayInputFactory', [], [], '', false); |
| 49 | + $this->consoleOutput = $this->getMock('Symfony\Component\Console\Output\BufferedOutput', [], [], '', false); |
| 50 | + |
| 51 | + $this->application = new MagentoComposerApplication( |
| 52 | + $this->composerApplication, |
| 53 | + $this->inputFactory, |
| 54 | + $this->consoleOutput |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @expectedException \Exception |
| 60 | + * @expectedExceptionMessage Please call setConfig method to configure composer |
| 61 | + */ |
| 62 | + function testMissedConfigSet() |
| 63 | + { |
| 64 | + $this->application->runComposerCommand([]); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @expectedException \RuntimeException |
| 69 | + * @expectedExceptionMessage Command "update" failed |
| 70 | + */ |
| 71 | + function testWrongExitCode() |
| 72 | + { |
| 73 | + $this->application->setConfig('path1', 'path2'); |
| 74 | + $this->composerApplication->expects($this->once())->method('run')->willReturn(1); |
| 75 | + |
| 76 | + $this->application->runComposerCommand(['command'=>'update']); |
| 77 | + } |
| 78 | + |
| 79 | + function testRunCommand() |
| 80 | + { |
| 81 | + $inputData = ['command'=>'update']; |
| 82 | + |
| 83 | + $this->application->setConfig('path1', 'path2'); |
| 84 | + $this->composerApplication->expects($this->once())->method('resetComposer'); |
| 85 | + |
| 86 | + $this->inputFactory->expects($this->once())->method('create')->with($inputData); |
| 87 | + |
| 88 | + $this->consoleOutput->expects($this->once())->method('fetch')->willReturn('Nothing to update'); |
| 89 | + |
| 90 | + $this->composerApplication->expects($this->once())->method('run')->willReturn(0); |
| 91 | + |
| 92 | + $message = $this->application->runComposerCommand($inputData); |
| 93 | + $this->assertEquals('Nothing to update', $message); |
| 94 | + } |
| 95 | +} |
0 commit comments