Skip to content

Commit 707ce70

Browse files
author
Ivan Gavryshko
committed
MAGETWO-38838: Create composer management library and reuse it in both updater and setup wizard
- chenge in lib interface
1 parent bf16037 commit 707ce70

File tree

2 files changed

+8
-34
lines changed

2 files changed

+8
-34
lines changed

Tests/Composer/MagentoComposerApplicationTest.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,20 @@ protected function setUp()
4949
$this->consoleOutput = $this->getMock('Symfony\Component\Console\Output\BufferedOutput', [], [], '', false);
5050

5151
$this->application = new MagentoComposerApplication(
52+
'path1',
53+
'path2',
5254
$this->composerApplication,
5355
$this->inputFactory,
5456
$this->consoleOutput
5557
);
5658
}
5759

58-
/**
59-
* @expectedException \Exception
60-
* @expectedExceptionMessage Please call setConfig method to configure composer
61-
*/
62-
function testMissedConfigSet()
63-
{
64-
$this->application->runComposerCommand([]);
65-
}
66-
6760
/**
6861
* @expectedException \RuntimeException
6962
* @expectedExceptionMessage Command "update" failed
7063
*/
7164
function testWrongExitCode()
7265
{
73-
$this->application->setConfig('path1', 'path2');
7466
$this->composerApplication->expects($this->once())->method('run')->willReturn(1);
7567

7668
$this->application->runComposerCommand(['command'=>'update']);
@@ -80,7 +72,6 @@ function testRunCommand()
8072
{
8173
$inputData = ['command' => 'update', MagentoComposerApplication::COMPOSER_WORKING_DIR => '.'];
8274

83-
$this->application->setConfig('path1', 'path2');
8475
$this->composerApplication->expects($this->once())->method('resetComposer');
8576

8677
$this->inputFactory->expects($this->once())->method('create')->with($inputData);

src/MagentoComposerApplication.php

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@ class MagentoComposerApplication
6363
/**
6464
* Constructs class
6565
*
66+
* @param string $pathToComposerHome
67+
* @param string $pathToComposerJson
6668
* @param Application $consoleApplication
6769
* @param ConsoleArrayInputFactory $consoleArrayInputFactory
6870
* @param BufferedOutput $consoleOutput
6971
*/
7072
public function __construct(
73+
$pathToComposerHome,
74+
$pathToComposerJson,
7175
Application $consoleApplication = null,
7276
ConsoleArrayInputFactory $consoleArrayInputFactory = null,
7377
BufferedOutput $consoleOutput = null
@@ -76,56 +80,35 @@ public function __construct(
7680
$this->consoleArrayInputFactory = $consoleArrayInputFactory ? $consoleArrayInputFactory
7781
: new ConsoleArrayInputFactory();
7882
$this->consoleOutput = $consoleOutput ? $consoleOutput : new BufferedOutput();
79-
}
8083

81-
/**
82-
* Sets composer environment config
83-
*
84-
* @param string $pathToComposerHome
85-
* @param string $pathToComposerJson
86-
*/
87-
public function setConfig($pathToComposerHome, $pathToComposerJson)
88-
{
8984
$this->composerJson = $pathToComposerJson;
9085
$this->composerHome = $pathToComposerHome;
9186

9287
putenv('COMPOSER_HOME=' . $pathToComposerHome);
9388

9489
$this->consoleApplication->setAutoExit(false);
95-
$this->configIsSet = true;
96-
9790
}
9891

9992
/**
100-
* Returns composer object
93+
* Creates composer object
10194
*
10295
* @return \Composer\Composer
10396
* @throws \Exception
10497
*/
105-
public function getComposer()
98+
public function createComposer()
10699
{
107-
if (!$this->configIsSet) {
108-
throw new \Exception('Please call setConfig method to configure composer');
109-
}
110-
111100
return ComposerFactory::create(new BufferIO(), $this->composerJson);
112-
113101
}
114102

115103
/**
116104
* Runs composer command
117105
*
118106
* @param array $commandParams
119107
* @return bool
120-
* @throws \Exception
121108
* @throws \RuntimeException
122109
*/
123110
public function runComposerCommand(array $commandParams)
124111
{
125-
if (!$this->configIsSet) {
126-
throw new \Exception('Please call setConfig method to configure composer');
127-
}
128-
129112
$this->consoleApplication->resetComposer();
130113

131114
$commandParams[self::COMPOSER_WORKING_DIR] = dirname($this->composerJson);

0 commit comments

Comments
 (0)