Skip to content

Commit 4bcf705

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 d1480be commit 4bcf705

File tree

4 files changed

+98
-34
lines changed

4 files changed

+98
-34
lines changed

app/code/Magento/Deploy/Model/DeploymentConfig/ImporterPool.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@ class ImporterPool
6060
private $importers = [];
6161

6262
/**
63+
* Sorted list of importers class names.
6364
*
65+
* This list sorted by parameter "sortOrder", that defined in di.xml
66+
*
67+
* ```php
68+
* [
69+
* 'themes' => 'Magento\Theme\Model\ThemeImporter',
70+
* 'scopes' => 'Magento\Store\Model\StoreImporter',
71+
* ...
72+
* ]
73+
* ```
6474
*
6575
* @var array
6676
*/
@@ -127,7 +137,7 @@ public function getImporters()
127137
throw new ConfigurationMismatchException(__('Parameter "class" must be present.'));
128138
}
129139

130-
$sortedImporters[$section] = $importer['class'];
140+
$sortedImporters[$section] = $importer['class'];
131141
}
132142

133143
$this->sortedImporters = $sortedImporters;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Deploy\Test\Unit\Model\DeploymentConfig;
7+
8+
use Magento\Deploy\Model\DeploymentConfig\ImporterFactory;
9+
use Magento\Framework\ObjectManagerInterface;
10+
use Magento\Framework\App\DeploymentConfig\ImporterInterface;
11+
12+
class ImporterFactoryTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
16+
*/
17+
private $objectManagerMock;
18+
19+
/**
20+
* @var ImporterFactory|\PHPUnit_Framework_MockObject_MockObject
21+
*/
22+
private $importerFactory;
23+
24+
protected function setUp()
25+
{
26+
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
27+
->getMockForAbstractClass();
28+
$this->importerFactory = new ImporterFactory($this->objectManagerMock);
29+
}
30+
31+
public function testCreate()
32+
{
33+
$className = 'some/class/name';
34+
35+
/** @var ImporterInterface|\PHPUnit_Framework_MockObject_MockObject $importerMock */
36+
$importerMock = $this->getMockBuilder(ImporterInterface::class)
37+
->getMockForAbstractClass();
38+
39+
$this->objectManagerMock->expects($this->once())
40+
->method('create')
41+
->with($className, [])
42+
->willReturn($importerMock);
43+
44+
$this->assertSame($importerMock, $this->importerFactory->create($className));
45+
}
46+
47+
/**
48+
* @expectedException \InvalidArgumentException
49+
* @codingStandardsIgnoreStart
50+
* @expectedExceptionMessage Type "some/class/name" is not instance on Magento\Framework\App\DeploymentConfig\ImporterInterface
51+
* @codingStandardsIgnoreEnd
52+
*/
53+
public function testCreateWithInvalidArgumentException()
54+
{
55+
$className = 'some/class/name';
56+
57+
/** @var \StdClass|\PHPUnit_Framework_MockObject_MockObject $importerMock */
58+
$importerMock = $this->getMockBuilder(\StdClass::class)
59+
->disableOriginalConstructor()
60+
->getMock();
61+
62+
$this->objectManagerMock->expects($this->once())
63+
->method('create')
64+
->with($className, [])
65+
->willReturn($importerMock);
66+
67+
$this->importerFactory->create($className);
68+
}
69+
}

dev/tests/integration/testsuite/Magento/Deploy/Console/Command/App/ApplicationDumpCommandTest.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class ApplicationDumpCommandTest extends \PHPUnit_Framework_TestCase
5151
private $config;
5252

5353
/**
54-
* @var array
54+
* @var Hash
5555
*/
56-
private $envConfig;
56+
private $hash;
5757

5858
/**
5959
* @inheritdoc
@@ -67,10 +67,10 @@ public function setUp()
6767
$this->reader = $this->objectManager->get(DeploymentConfig\Reader::class);
6868
$this->writer = $this->objectManager->get(DeploymentConfig\Writer::class);
6969
$this->configFilePool = $this->objectManager->get(ConfigFilePool::class);
70+
$this->hash = $this->objectManager->get(Hash::class);
7071

7172
// Snapshot of configuration.
7273
$this->config = $this->loadConfig();
73-
$this->envConfig = $this->loadEnvConfig();
7474
}
7575

7676
/**
@@ -95,7 +95,6 @@ private function loadEnvConfig()
9595
*/
9696
public function testExecute()
9797
{
98-
$this->assertArrayNotHasKey(Hash::CONFIG_KEY, $this->envConfig);
9998
$this->objectManager->configure([
10099
\Magento\Config\Model\Config\Export\ExcludeList::class => [
101100
'arguments' => [
@@ -127,7 +126,7 @@ public function testExecute()
127126

128127
$this->validateSystemSection($config);
129128
$this->validateThemesSection($config);
130-
$this->assertArrayHasKey(Hash::CONFIG_KEY, $this->loadEnvConfig());
129+
$this->assertSame([], $this->hash->get());
131130
}
132131

133132
/**
@@ -214,11 +213,5 @@ public function tearDown()
214213
/** @var DeploymentConfig $deploymentConfig */
215214
$deploymentConfig = $this->objectManager->get(DeploymentConfig::class);
216215
$deploymentConfig->resetData();
217-
218-
$this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile(
219-
$this->configFilePool->getPath(ConfigFilePool::APP_ENV),
220-
"<?php\n return array();\n"
221-
);
222-
$this->writer->saveConfig([ConfigFilePool::APP_ENV => $this->envConfig]);
223216
}
224217
}

dev/tests/integration/testsuite/Magento/Deploy/Console/Command/App/ConfigImportCommandTest.php

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class ConfigImportCommandTest extends \PHPUnit_Framework_TestCase
4949
private $configFilePool;
5050

5151
/**
52-
* @var array
52+
* @var Hash
5353
*/
54-
private $envConfig;
54+
private $hash;
5555

5656
/**
5757
* @var array
@@ -80,8 +80,8 @@ protected function setUp()
8080
$this->writer = $this->objectManager->get(DeploymentConfig\Writer::class);
8181
$this->filesystem = $this->objectManager->get(Filesystem::class);
8282
$this->configFilePool = $this->objectManager->get(ConfigFilePool::class);
83+
$this->hash = $this->objectManager->get(Hash::class);
8384

84-
$this->envConfig = $this->loadEnvConfig();
8585
$this->config = $this->loadConfig();
8686
}
8787

@@ -94,29 +94,28 @@ public function tearDown()
9494
/** @var DeploymentConfig\Writer $writer */
9595
$writer = $this->objectManager->get(DeploymentConfig\Writer::class);
9696
$writer->saveConfig([ConfigFilePool::APP_CONFIG => $this->config]);
97-
98-
$this->filesystem = $this->objectManager->get(Filesystem::class);
99-
$this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile(
100-
$this->configFilePool->getPath(ConfigFilePool::APP_ENV),
101-
"<?php\n return array();\n"
102-
);
103-
$this->writer->saveConfig([ConfigFilePool::APP_ENV => $this->envConfig]);
10497
}
10598

99+
/**
100+
* @magentoDbIsolation enabled
101+
*/
106102
public function testExecuteNothingImport()
107103
{
108-
$this->assertArrayNotHasKey(Hash::CONFIG_KEY, $this->envConfig);
104+
$this->assertEmpty($this->hash->get());
109105
$command = $this->objectManager->create(ConfigImportCommand::class);
110106
$commandTester = new CommandTester($command);
111107
$commandTester->execute([]);
112108
$this->assertSame(Cli::RETURN_SUCCESS, $commandTester->getStatusCode());
113109
$this->assertContains('Nothing to import.', $commandTester->getDisplay());
114-
$this->assertArrayNotHasKey(Hash::CONFIG_KEY, $this->loadEnvConfig());
110+
$this->assertEmpty($this->hash->get());
115111
}
116112

113+
/**
114+
* @magentoDbIsolation enabled
115+
*/
117116
public function testExecuteWithImport()
118117
{
119-
$this->assertArrayNotHasKey(Hash::CONFIG_KEY, $this->envConfig);
118+
$this->assertEmpty($this->hash->get());
120119
$this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile(
121120
$this->configFilePool->getPath(ConfigFilePool::APP_CONFIG),
122121
file_get_contents(__DIR__ . '/../../../_files/config.php')
@@ -130,7 +129,8 @@ public function testExecuteWithImport()
130129
"Integration second test data is imported!\nIntegration test data is imported!",
131130
$commandTester->getDisplay()
132131
);
133-
$this->assertArrayHasKey(Hash::CONFIG_KEY, $this->loadEnvConfig());
132+
$this->assertArrayHasKey('integrationTestImporter', $this->hash->get());
133+
$this->assertArrayHasKey('integrationTestSecondImporter', $this->hash->get());
134134
}
135135

136136
/**
@@ -140,12 +140,4 @@ private function loadConfig()
140140
{
141141
return $this->reader->load(ConfigFilePool::APP_CONFIG);
142142
}
143-
144-
/**
145-
* @return array
146-
*/
147-
private function loadEnvConfig()
148-
{
149-
return $this->reader->load(ConfigFilePool::APP_ENV);
150-
}
151143
}

0 commit comments

Comments
 (0)