Skip to content

Commit e481fe6

Browse files
author
Bohdan Korablov
committed
MAGETWO-65208: Store checksum for every section of configuration file & change behavior on read-only FS & add sorting of importers
1 parent cbdf352 commit e481fe6

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

app/code/Magento/Deploy/Console/Command/App/ConfigImport/Importer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Framework\App\DeploymentConfig\ImporterInterface;
99
use Magento\Framework\App\DeploymentConfig;
10+
use Magento\Framework\Exception\LocalizedException;
1011
use Magento\Framework\Exception\RuntimeException;
1112
use Psr\Log\LoggerInterface as Logger;
1213
use Magento\Deploy\Model\DeploymentConfig\Validator;
@@ -112,11 +113,14 @@ public function import(OutputInterface $output)
112113
if (!$this->configValidator->isValid($section)) {
113114
/** @var ImporterInterface $importer */
114115
$importer = $this->importerFactory->create($importerClassName);
115-
$messages = $importer->import((array) $this->deploymentConfig->getConfigData($section));
116+
$messages = $importer->import((array)$this->deploymentConfig->getConfigData($section));
116117
$output->writeln($messages);
117118
$this->configHash->regenerate($section);
118119
}
119120
}
121+
} catch (LocalizedException $exception) {
122+
$this->logger->error($exception);
123+
$output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
120124
} catch (\Exception $exception) {
121125
$this->logger->error($exception);
122126
throw new RuntimeException(__('Import is failed. Please see the log report.'), $exception);

app/code/Magento/Deploy/Test/Unit/Console/Command/App/ConfigImport/ImporterTest.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ class ImporterTest extends \PHPUnit_Framework_TestCase
5858
*/
5959
private $importer;
6060

61-
/**
62-
* @return void
63-
*/
6461
protected function setUp()
6562
{
6663
$this->importerFactoryMock = $this->getMockBuilder(ImporterFactory::class)
@@ -94,9 +91,6 @@ protected function setUp()
9491
);
9592
}
9693

97-
/**
98-
* @return void
99-
*/
10094
public function testImport()
10195
{
10296
$configData = ['some data'];
@@ -141,13 +135,12 @@ public function testImport()
141135
}
142136

143137
/**
144-
* @return void
145138
* @expectedException \Magento\Framework\Exception\LocalizedException
146139
* @expectedExceptionMessage Import is failed. Please see the log report.
147140
*/
148141
public function testImportWithException()
149142
{
150-
$exception = new LocalizedException(__('Some error'));
143+
$exception = new \Exception('Some error');
151144
$this->outputMock->expects($this->never())
152145
->method('writeln');
153146
$this->configHashMock->expects($this->never())
@@ -166,10 +159,31 @@ public function testImportWithException()
166159
$this->importer->import($this->outputMock);
167160
}
168161

162+
public function testImportWithLocalizedException()
163+
{
164+
$exception = new LocalizedException(__('Some error'));
165+
$this->outputMock->expects($this->once())
166+
->method('writeln')
167+
->with('<error>Some error</error>');
168+
$this->configHashMock->expects($this->never())
169+
->method('regenerate');
170+
$this->configValidatorMock->expects($this->never())
171+
->method('isValid');
172+
$this->deploymentConfigMock->expects($this->never())
173+
->method('getConfigData');
174+
$this->configImporterPoolMock->expects($this->once())
175+
->method('getImporters')
176+
->willThrowException($exception);
177+
$this->loggerMock->expects($this->once())
178+
->method('error')
179+
->with($exception);
180+
181+
$this->importer->import($this->outputMock);
182+
}
183+
169184
/**
170185
* @param array $importers
171186
* @param bool $isValid
172-
* @return void
173187
* @dataProvider importNothingToImportDataProvider
174188
*/
175189
public function testImportNothingToImport(array $importers, $isValid)

0 commit comments

Comments
 (0)