Skip to content

Commit e0a5a54

Browse files
author
Ivan Gavryshko
committed
MAGETWO-38838: Create composer management library and reuse it in both updater and setup wizard
- added unittest
1 parent 46fac17 commit e0a5a54

File tree

3 files changed

+97
-4
lines changed

3 files changed

+97
-4
lines changed

app/code/Magento/Composer/MagentoComposerApplication.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,13 @@ public function getComposer()
104104
*/
105105
public function runComposerCommand(array $commandParams)
106106
{
107-
$this->consoleApplication->resetComposer();
108-
109107
if (!$this->configIsSet) {
110108
throw new \Exception('Please call setConfig method to configure composer');
111109
}
112110

111+
$this->consoleApplication->resetComposer();
112+
113113
$input = $this->consoleArrayInputFactory->create($commandParams);
114-
$this->consoleApplication->setAutoExit(false);
115114

116115
$exitCode = $this->consoleApplication->run($input, $this->consoleOutput);
117116

dev/tests/unit/ConsoleArrayInputFactoryTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ public function testCreate()
2323
$this->assertInstanceOf('\Symfony\Component\Console\Input\ArrayInput', $this->factory->create([]));
2424
}
2525
}
26-
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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

Comments
 (0)