Skip to content

Commit c045c81

Browse files
committed
MAGECLOUD-3668: Custom data in env.php removed after redeploy
1 parent b8edf25 commit c045c81

File tree

1 file changed

+176
-49
lines changed

1 file changed

+176
-49
lines changed

src/Test/Unit/Process/Deploy/InstallUpdate/ConfigUpdate/SearchEngineTest.php

Lines changed: 176 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77

88
namespace Magento\MagentoCloud\Test\Unit\Process\Deploy\InstallUpdate\ConfigUpdate;
99

10+
use Magento\MagentoCloud\Config\Deploy\Reader as EnvReader;
1011
use Magento\MagentoCloud\Config\Deploy\Writer as EnvWriter;
12+
use Magento\MagentoCloud\Config\SearchEngine as SearchEngineConfig;
13+
use Magento\MagentoCloud\Config\Shared\Reader as SharedReader;
1114
use Magento\MagentoCloud\Config\Shared\Writer as SharedWriter;
1215
use Magento\MagentoCloud\Filesystem\FileSystemException;
1316
use Magento\MagentoCloud\Package\MagentoVersion;
1417
use Magento\MagentoCloud\Package\UndefinedPackageException;
1518
use Magento\MagentoCloud\Process\Deploy\InstallUpdate\ConfigUpdate\SearchEngine;
16-
use Magento\MagentoCloud\Config\SearchEngine as SearchEngineConfig;
1719
use Magento\MagentoCloud\Process\ProcessException;
20+
use PHPUnit\Framework\MockObject\Matcher\InvokedCount;
1821
use PHPUnit\Framework\MockObject\MockObject;
1922
use PHPUnit\Framework\TestCase;
2023
use Psr\Log\LoggerInterface;
@@ -54,36 +57,65 @@ class SearchEngineTest extends TestCase
5457
*/
5558
private $configMock;
5659

60+
/**
61+
* @var EnvReader|MockObject
62+
*/
63+
private $envReaderMock;
64+
65+
/**
66+
* @var SharedReader|MockObject
67+
*/
68+
private $sharedReaderMock;
69+
5770
/**
5871
* @inheritdoc
5972
*/
6073
protected function setUp()
6174
{
6275
$this->envWriterMock = $this->createMock(EnvWriter::class);
76+
$this->envReaderMock = $this->createMock(EnvReader::class);
6377
$this->sharedWriterMock = $this->createMock(SharedWriter::class);
78+
$this->sharedReaderMock = $this->createMock(SharedReader::class);
6479
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
6580
$this->magentoVersionMock = $this->createMock(MagentoVersion::class);
6681
$this->configMock = $this->createMock(SearchEngineConfig::class);
6782

6883
$this->process = new SearchEngine(
6984
$this->loggerMock,
7085
$this->envWriterMock,
86+
$this->envReaderMock,
7187
$this->sharedWriterMock,
88+
$this->sharedReaderMock,
7289
$this->magentoVersionMock,
7390
$this->configMock
7491
);
7592
}
7693

7794
/**
95+
* @param bool $is21
96+
* @param InvokedCount $useSharedWriter
97+
* @param InvokedCount $useSharedReader
98+
* @param InvokedCount $useEnvWriter
99+
* @param InvokedCount $useEnvReader
100+
* @param array $searchConfig
101+
* @param array $fileConfig
102+
* @param array $expectedConfig
78103
* @throws ProcessException
104+
* @dataProvider executeDataProvider
79105
*/
80-
public function testExecute()
81-
{
82-
$config['system']['default']['catalog']['search'] = ['engine' => 'mysql'];
83-
106+
public function testExecute(
107+
bool $is21,
108+
InvokedCount $useSharedWriter,
109+
InvokedCount $useSharedReader,
110+
InvokedCount $useEnvWriter,
111+
InvokedCount $useEnvReader,
112+
array $searchConfig,
113+
array $fileConfig,
114+
array $expectedConfig
115+
) {
84116
$this->configMock->expects($this->once())
85117
->method('getConfig')
86-
->willReturn($config);
118+
->willReturn($searchConfig);
87119
$this->configMock->expects($this->once())
88120
->method('getName')
89121
->willReturn('mysql');
@@ -96,46 +128,19 @@ public function testExecute()
96128
$this->magentoVersionMock->expects($this->once())
97129
->method('satisfies')
98130
->with('2.1.*')
99-
->willReturn(false);
100-
$this->sharedWriterMock->expects($this->never())
101-
->method('update')
102-
->with($config);
103-
$this->envWriterMock->expects($this->once())
104-
->method('update')
105-
->with($config);
106-
107-
$this->process->execute();
108-
}
109-
110-
/**
111-
* @throws ProcessException
112-
*/
113-
public function testExecute21()
114-
{
115-
$config['system']['default']['catalog']['search'] = ['engine' => 'mysql'];
116-
117-
$this->configMock->expects($this->once())
118-
->method('getConfig')
119-
->willReturn($config);
120-
$this->configMock->expects($this->once())
121-
->method('getName')
122-
->willReturn('mysql');
123-
$this->loggerMock->expects($this->exactly(2))
124-
->method('info')
125-
->withConsecutive(
126-
['Updating search engine configuration.'],
127-
['Set search engine to: mysql']
128-
);
129-
$this->magentoVersionMock->expects($this->once())
130-
->method('satisfies')
131-
->with('2.1.*')
132-
->willReturn(true);
133-
$this->sharedWriterMock->expects($this->once())
134-
->method('update')
135-
->with($config);
136-
$this->envWriterMock->expects($this->never())
137-
->method('update')
138-
->with($config);
131+
->willReturn($is21);
132+
$this->sharedReaderMock->expects($useSharedReader)
133+
->method('read')
134+
->willReturn($fileConfig);
135+
$this->sharedWriterMock->expects($useSharedWriter)
136+
->method('create')
137+
->with($expectedConfig);
138+
$this->envReaderMock->expects($useEnvReader)
139+
->method('read')
140+
->willReturn($fileConfig);
141+
$this->envWriterMock->expects($useEnvWriter)
142+
->method('create')
143+
->with($expectedConfig);
139144

140145
$this->process->execute();
141146
}
@@ -145,17 +150,139 @@ public function testExecute21()
145150
*/
146151
public function executeDataProvider(): array
147152
{
153+
$mysqlSearchConfig['system']['default']['catalog']['search'] = ['engine' => 'mysql'];
154+
$elasticSearchConfig = [
155+
'system' => [
156+
'default' => [
157+
'smile_elasticsuite_core_base_settings' => [
158+
'option3' => 'value3',
159+
'option4' => 'value4'
160+
],
161+
'catalog' => [
162+
'search' => [
163+
'engine' => 'elasticsearch5',
164+
'elasticsearh5_host' => 'localhost',
165+
'elasticsearh5_port' => '9200',
166+
]
167+
]
168+
]
169+
]
170+
];
171+
$fileConfig = [
172+
'config' => 'value',
173+
'system' => [
174+
'default' => [
175+
'smile_elasticsuite_core_base_settings' => [
176+
'option1' => 'value1',
177+
'option2' => 'value2'
178+
],
179+
'category' => [
180+
'option' => 'value'
181+
],
182+
'catalog' => [
183+
'search' => [
184+
'engine' => 'elasticsearch',
185+
'elasticsearh_host' => 'localhost',
186+
'elasticsearh_port' => '9200',
187+
]
188+
]
189+
],
190+
'store1' => [
191+
'category' => [
192+
'option' => 'value'
193+
],
194+
],
195+
]
196+
];
197+
$mysqlExpectedConfig = [
198+
'config' => 'value',
199+
'system' => [
200+
'default' => [
201+
'catalog' => [
202+
'search' => [
203+
'engine' => 'mysql'
204+
],
205+
],
206+
'category' => [
207+
'option' => 'value'
208+
],
209+
],
210+
'store1' => [
211+
'category' => [
212+
'option' => 'value'
213+
],
214+
],
215+
]
216+
];
217+
$elasticExpectedConfig = [
218+
'config' => 'value',
219+
'system' => [
220+
'default' => [
221+
'smile_elasticsuite_core_base_settings' => [
222+
'option3' => 'value3',
223+
'option4' => 'value4'
224+
],
225+
'category' => [
226+
'option' => 'value'
227+
],
228+
'catalog' => [
229+
'search' => [
230+
'engine' => 'elasticsearch5',
231+
'elasticsearh5_host' => 'localhost',
232+
'elasticsearh5_port' => '9200',
233+
]
234+
]
235+
],
236+
'store1' => [
237+
'category' => [
238+
'option' => 'value'
239+
],
240+
],
241+
]
242+
];
243+
148244
return [
149-
[
245+
'magento version 2.1 mysql config' => [
246+
'is21' => true,
247+
'useSharedWriter' => $this->once(),
248+
'useSharedReader' => $this->once(),
249+
'useEnvWriter' => $this->never(),
250+
'useEnvReader' => $this->never(),
251+
'searchConfig' => $mysqlSearchConfig,
252+
'fileConfig' => $fileConfig,
253+
'expectedConfig' => $mysqlExpectedConfig
254+
],
255+
'magento version > 2.1 mysql config' => [
150256
'is21' => false,
151257
'useSharedWriter' => $this->never(),
258+
'useSharedReader' => $this->never(),
152259
'useEnvWriter' => $this->once(),
260+
'useEnvReader' => $this->once(),
261+
'searchConfig' => $mysqlSearchConfig,
262+
'fileConfig' => $fileConfig,
263+
'expectedConfig' => $mysqlExpectedConfig
153264
],
154-
[
265+
'magento version 2.1 elasticsearch config' => [
155266
'is21' => true,
156267
'useSharedWriter' => $this->once(),
268+
'useSharedReader' => $this->once(),
157269
'useEnvWriter' => $this->never(),
270+
'useEnvReader' => $this->never(),
271+
'searchConfig' => $elasticSearchConfig,
272+
'fileConfig' => $fileConfig,
273+
'expectedConfig' => $elasticExpectedConfig
158274
],
275+
'magento version > 2.1 elasticsearch config' => [
276+
'is21' => false,
277+
'useSharedWriter' => $this->never(),
278+
'useSharedReader' => $this->never(),
279+
'useEnvWriter' => $this->once(),
280+
'useEnvReader' => $this->once(),
281+
'searchConfig' => $elasticSearchConfig,
282+
'fileConfig' => $fileConfig,
283+
'expectedConfig' => $elasticExpectedConfig
284+
],
285+
159286
];
160287
}
161288

@@ -189,7 +316,7 @@ public function testExecuteWithException()
189316
->method('update')
190317
->with($config);
191318
$this->envWriterMock->expects($this->once())
192-
->method('update')
319+
->method('create')
193320
->with($config)
194321
->willThrowException(new FileSystemException('Some error'));
195322

0 commit comments

Comments
 (0)