Skip to content

Commit c00303f

Browse files
MAGETWO-71890: Magento fails with deploymentConfig present on new install
1 parent 4381a6b commit c00303f

File tree

6 files changed

+187
-3
lines changed

6 files changed

+187
-3
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Deploy\Console;
7+
8+
use Magento\Framework\ObjectManagerInterface;
9+
10+
/**
11+
* Provides list of commands to be available for uninstalled application
12+
*/
13+
class CommandList implements \Magento\Framework\Console\CommandListInterface
14+
{
15+
/**
16+
* Object Manager
17+
*
18+
* @var ObjectManagerInterface
19+
*/
20+
private $objectManager;
21+
22+
/**
23+
* @param ObjectManagerInterface $objectManager Object Manager
24+
*/
25+
public function __construct(ObjectManagerInterface $objectManager)
26+
{
27+
$this->objectManager = $objectManager;
28+
}
29+
30+
/**
31+
* Gets list of command classes
32+
*
33+
* @return string[]
34+
*/
35+
private function getCommandsClasses()
36+
{
37+
return [
38+
\Magento\Deploy\Console\Command\App\ConfigImportCommand::class,
39+
];
40+
}
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
public function getCommands()
46+
{
47+
$commands = [];
48+
foreach ($this->getCommandsClasses() as $class) {
49+
if (class_exists($class)) {
50+
$commands[] = $this->objectManager->get($class);
51+
} else {
52+
throw new \Exception('Class ' . $class . ' does not exist');
53+
}
54+
}
55+
56+
return $commands;
57+
}
58+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Deploy\Test\Unit\Console;
7+
8+
use Magento\Deploy\Console\Command\App\ConfigImportCommand;
9+
use Magento\Deploy\Console\CommandList;
10+
use Magento\Framework\ObjectManagerInterface;
11+
use PHPUnit\Framework\TestCase;
12+
13+
/**
14+
* @inheritdoc
15+
*/
16+
class CommandListTest extends TestCase
17+
{
18+
/**
19+
* @var CommandList
20+
*/
21+
private $model;
22+
23+
/**
24+
* @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $objectManagerMock;
27+
28+
/**
29+
* @inheritdoc
30+
*/
31+
protected function setUp()
32+
{
33+
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
34+
->getMockForAbstractClass();
35+
36+
$this->model = new CommandList(
37+
$this->objectManagerMock
38+
);
39+
}
40+
41+
public function testGetCommands()
42+
{
43+
$this->objectManagerMock->expects($this->once())
44+
->method('get')
45+
->withConsecutive([
46+
ConfigImportCommand::class,
47+
]);
48+
49+
$this->model->getCommands();
50+
}
51+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
if (PHP_SAPI == 'cli') {
7+
\Magento\Framework\Console\CommandLocator::register(\Magento\Deploy\Console\CommandList::class);
8+
}

app/code/Magento/Deploy/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"autoload": {
1919
"files": [
20+
"cli_commands.php",
2021
"registration.php"
2122
],
2223
"psr-4": {

setup/src/Magento/Setup/Console/Command/InstallCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Setup\Console\Command;
77

8+
use Magento\Deploy\Console\Command\App\ConfigImportCommand;
9+
use Symfony\Component\Console\Input\ArrayInput;
810
use Symfony\Component\Console\Input\InputInterface;
911
use Symfony\Component\Console\Output\OutputInterface;
1012
use Magento\Setup\Model\InstallerFactory;
@@ -123,6 +125,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
123125
$consoleLogger = new ConsoleLogger($output);
124126
$installer = $this->installerFactory->create($consoleLogger);
125127
$installer->install($input->getOptions());
128+
129+
$importConfigCommand = $this->getApplication()->find(ConfigImportCommand::COMMAND_NAME);
130+
$arrayInput = new ArrayInput([]);
131+
$arrayInput->setInteractive($input->isInteractive());
132+
$importConfigCommand->run($arrayInput, $output);
126133
}
127134

128135
/**

setup/src/Magento/Setup/Test/Unit/Console/Command/InstallCommandTest.php

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
namespace Magento\Setup\Test\Unit\Console\Command;
88

9+
use Magento\Deploy\Console\Command\App\ConfigImportCommand;
910
use Magento\Setup\Console\Command\InstallCommand;
11+
use Symfony\Component\Console\Application;
12+
use Symfony\Component\Console\Helper\HelperSet;
13+
use Symfony\Component\Console\Input\InputDefinition;
1014
use Symfony\Component\Console\Tester\CommandTester;
1115
use Magento\Setup\Model\AdminAccount;
1216
use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList;
@@ -38,6 +42,26 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase
3842
*/
3943
private $installer;
4044

45+
/**
46+
* @var Application|\PHPUnit_Framework_MockObject_MockObject
47+
*/
48+
private $applicationMock;
49+
50+
/**
51+
* @var HelperSet|\PHPUnit_Framework_MockObject_MockObject
52+
*/
53+
private $helperSetMock;
54+
55+
/**
56+
* @var InputDefinition|\PHPUnit_Framework_MockObject_MockObject
57+
*/
58+
private $definitionMock;
59+
60+
/**
61+
* @var ConfigImportCommand|\PHPUnit_Framework_MockObject_MockObject
62+
*/
63+
private $configImportMock;
64+
4165
public function setUp()
4266
{
4367
$this->input = [
@@ -88,12 +112,42 @@ public function setUp()
88112

89113
$this->installerFactory = $this->createMock(\Magento\Setup\Model\InstallerFactory::class);
90114
$this->installer = $this->createMock(\Magento\Setup\Model\Installer::class);
115+
$this->applicationMock = $this->getMockBuilder(Application::class)
116+
->disableOriginalConstructor()
117+
->getMock();
118+
$this->helperSetMock = $this->getMockBuilder(HelperSet::class)
119+
->disableOriginalConstructor()
120+
->getMock();
121+
$this->definitionMock = $this->getMockBuilder(InputDefinition::class)
122+
->disableOriginalConstructor()
123+
->getMock();
124+
$this->configImportMock = $this->getMockBuilder(ConfigImportCommand::class)
125+
->disableOriginalConstructor()
126+
->getMock();
127+
128+
$this->applicationMock->expects($this->any())
129+
->method('getHelperSet')
130+
->willReturn($this->helperSetMock);
131+
$this->applicationMock->expects($this->any())
132+
->method('getDefinition')
133+
->willReturn($this->definitionMock);
134+
$this->definitionMock->expects($this->any())
135+
->method('getOptions')
136+
->willReturn([]);
137+
$this->applicationMock->expects($this->any())
138+
->method('find')
139+
->with(ConfigImportCommand::COMMAND_NAME)
140+
->willReturn($this->configImportMock);
141+
91142
$this->command = new InstallCommand(
92143
$this->installerFactory,
93144
$configModel,
94145
$userConfig,
95146
$adminUser
96147
);
148+
$this->command->setApplication(
149+
$this->applicationMock
150+
);
97151
}
98152

99153
public function testExecute()
@@ -102,6 +156,8 @@ public function testExecute()
102156
->method('create')
103157
->will($this->returnValue($this->installer));
104158
$this->installer->expects($this->once())->method('install');
159+
$this->configImportMock->expects($this->once())
160+
->method('run');
105161

106162
$commandTester = new CommandTester($this->command);
107163
$commandTester->execute($this->input);
@@ -134,6 +190,7 @@ private function getOptionsListDeployConfig()
134190
->expects($this->any())
135191
->method('getName')
136192
->will($this->returnValue(BackendConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME));
193+
137194
return [$option1, $option2, $option3, $option4];
138195
}
139196

@@ -164,6 +221,7 @@ private function getOptionsListUserConfig()
164221
->expects($this->any())
165222
->method('getName')
166223
->will($this->returnValue(StoreConfigurationDataMapper::KEY_CURRENCY));
224+
167225
return [$option1, $option2, $option3, $option4];
168226
}
169227

@@ -199,6 +257,7 @@ private function getOptionsListAdminUser()
199257
->expects($this->any())
200258
->method('getName')
201259
->will($this->returnValue(AdminAccount::KEY_LAST_NAME));
260+
202261
return [$option1, $option2, $option3, $option4, $option5];
203262
}
204263

@@ -246,8 +305,8 @@ public function validateDataProvider()
246305
{
247306
return [
248307
'without option' => ['', ''],
249-
'normal case' => ['abcde', ''],
250-
'20 chars' => ['12345678901234567890', '']
308+
'normal case' => ['abcde', ''],
309+
'20 chars' => ['12345678901234567890', ''],
251310
];
252311
}
253312

@@ -258,7 +317,7 @@ public function validateWithExceptionDataProvider()
258317
{
259318
return [
260319
['123456789012345678901', 'InvalidArgumentException'],
261-
['abcdefghijk12345678fdgsdfgsdfgsdfsgsdfg90abcdefgdfddgsdfg', 'InvalidArgumentException']
320+
['abcdefghijk12345678fdgsdfgsdfgsdfsgsdfg90abcdefgdfddgsdfg', 'InvalidArgumentException'],
262321
];
263322
}
264323
}

0 commit comments

Comments
 (0)