Skip to content

Commit e880b2b

Browse files
MCLOUD-5542: Add mapping for Elastic 7 version validator in ece-tools (magento#716)
1 parent b70a54e commit e880b2b

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

src/Config/Validator/Deploy/ElasticSearchVersion.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\MagentoCloud\Config\Validator\Deploy;
99

10+
use Composer\Semver\Comparator;
1011
use Composer\Semver\Semver;
1112
use Magento\MagentoCloud\Config\SearchEngine;
1213
use Magento\MagentoCloud\Config\Validator;
@@ -57,19 +58,24 @@ class ElasticSearchVersion implements ValidatorInterface
5758
*/
5859
private static $versionsMap = [
5960
[
60-
'packageVersion' => '~6.0',
61-
'esVersion' => '~6.0',
62-
'esVersionRaw' => '6.x',
61+
'packageVersion' => '~2.0',
62+
'esVersion' => '>= 1.0 < 3.0',
63+
'esVersionRaw' => '1.x or 2.x',
6364
],
6465
[
6566
'packageVersion' => '~5.0',
6667
'esVersion' => '~5.0',
6768
'esVersionRaw' => '5.x',
6869
],
6970
[
70-
'packageVersion' => '~2.0',
71-
'esVersion' => '>= 1.0 < 3.0',
72-
'esVersionRaw' => '1.x or 2.x',
71+
'packageVersion' => '~6.0',
72+
'esVersion' => '~6.0',
73+
'esVersionRaw' => '6.x',
74+
],
75+
[
76+
'packageVersion' => '~7.0',
77+
'esVersion' => '~7.0',
78+
'esVersionRaw' => '7.x',
7379
],
7480
];
7581

@@ -126,7 +132,7 @@ public function validate(): Validator\ResultInterface
126132
return $this->generateError($esServiceVersion, $esPackageVersion, $versionInfo);
127133
}
128134
}
129-
} catch (\Exception $e) {
135+
} catch (UndefinedPackageException $e) {
130136
$this->logger->warning('Can\'t validate version of elasticsearch: ' . $e->getMessage());
131137
}
132138

@@ -164,10 +170,15 @@ private function generateError(
164170
$suggestion[] = ' Update the composer.json file for your Magento Cloud project to ' .
165171
'require elasticsearch/elasticsearch module version ~2.0.';
166172
} else {
173+
$mode = Comparator::greaterThan($esServiceVersion, $esPackageVersion)
174+
? 'downgrading'
175+
: 'upgrading';
176+
167177
$suggestion = [
168178
sprintf(
169-
'You can fix this issue by upgrading the Elasticsearch service on your ' .
179+
'You can fix this issue by %s the Elasticsearch service on your ' .
170180
'Magento Cloud infrastructure to version %s.',
181+
$mode,
171182
$versionInfo['esVersionRaw']
172183
)
173184
];

src/Test/Unit/Config/Validator/Deploy/ElasticSearchVersionTest.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\MagentoCloud\Config\Validator\ResultFactory;
1616
use Magento\MagentoCloud\Package\MagentoVersion;
1717
use Magento\MagentoCloud\Package\Manager;
18+
use Magento\MagentoCloud\Package\UndefinedPackageException;
1819
use Magento\MagentoCloud\Service\ElasticSearch;
1920
use PHPUnit\Framework\MockObject\MockObject;
2021
use PHPUnit\Framework\TestCase;
@@ -63,7 +64,7 @@ class ElasticSearchVersionTest extends TestCase
6364
/**
6465
* @inheritdoc
6566
*/
66-
public function setUp()
67+
public function setUp(): void
6768
{
6869
$this->resultFactoryMock = $this->createMock(ResultFactory::class);
6970
$this->managerMock = $this->createMock(Manager::class);
@@ -82,7 +83,7 @@ public function setUp()
8283
);
8384
}
8485

85-
public function testValidateElasticSearchServiceNotExists()
86+
public function testValidateElasticSearchServiceNotExists(): void
8687
{
8788
$this->elasticSearchMock->expects($this->once())
8889
->method('getVersion')
@@ -99,7 +100,7 @@ public function testValidateElasticSearchServiceNotExists()
99100
$this->assertInstanceOf(Success::class, $this->validator->validate());
100101
}
101102

102-
public function testValidatePackageNotExists()
103+
public function testValidatePackageNotExists(): void
103104
{
104105
$this->searchEngineMock->expects($this->once())
105106
->method('isESFamily')
@@ -110,7 +111,7 @@ public function testValidatePackageNotExists()
110111
$this->managerMock->expects($this->once())
111112
->method('get')
112113
->with('elasticsearch/elasticsearch')
113-
->willThrowException(new \Exception('package doesn\'t exist'));
114+
->willThrowException(new UndefinedPackageException('package doesn\'t exist'));
114115
$this->loggerMock->expects($this->once())
115116
->method('warning')
116117
->with('Can\'t validate version of elasticsearch: package doesn\'t exist');
@@ -120,7 +121,7 @@ public function testValidatePackageNotExists()
120121
$this->assertInstanceOf(Success::class, $this->validator->validate());
121122
}
122123

123-
public function testValidateElasticSearchServiceExistsAndNotConfigured()
124+
public function testValidateElasticSearchServiceExistsAndNotConfigured(): void
124125
{
125126
$this->searchEngineMock->expects($this->once())
126127
->method('isESFamily')
@@ -154,7 +155,7 @@ public function testValidate(
154155
string $magentoVersion = '2.2',
155156
string $errorMessage = '',
156157
string $errorSuggestion = ''
157-
) {
158+
): void {
158159
$this->magentoVersionMock->expects($this->any())
159160
->method('getVersion')
160161
->willReturn($magentoVersion);
@@ -186,6 +187,8 @@ public function testValidate(
186187

187188
/**
188189
* @return array
190+
*
191+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
189192
*/
190193
public function validateDataProvider(): array
191194
{
@@ -202,6 +205,8 @@ public function validateDataProvider(): array
202205
['1.7', '2.9', Success::class],
203206
['5.1', '5.0', Success::class],
204207
['5.2', '5.1', Success::class],
208+
['7.0', '7.1', Success::class],
209+
['7.4', '7.2', Success::class],
205210
['6.1', '2.0', Error::class],
206211
[
207212
'6.2',
@@ -210,7 +215,7 @@ public function validateDataProvider(): array
210215
'2.3.0',
211216
'Elasticsearch service version 6.2 on infrastructure layer is not compatible with current version of ' .
212217
'elasticsearch/elasticsearch module (5.0), used by your Magento application.',
213-
'You can fix this issue by upgrading the Elasticsearch service on your ' .
218+
'You can fix this issue by downgrading the Elasticsearch service on your ' .
214219
'Magento Cloud infrastructure to version 5.x.'
215220
],
216221
[
@@ -231,7 +236,7 @@ public function validateDataProvider(): array
231236
'2.1.4',
232237
'Elasticsearch service version 5.0 on infrastructure layer is not compatible with current version of ' .
233238
'elasticsearch/elasticsearch module (2.0), used by your Magento application.',
234-
'You can fix this issue by upgrading the Elasticsearch service on your ' .
239+
'You can fix this issue by downgrading the Elasticsearch service on your ' .
235240
'Magento Cloud infrastructure to version 1.x or 2.x.'
236241
],
237242
[
@@ -280,6 +285,16 @@ public function validateDataProvider(): array
280285
'You can fix this issue by upgrading the Elasticsearch service on your ' .
281286
'Magento Cloud infrastructure to version 5.x.'
282287
],
288+
[
289+
'7.4',
290+
'6.2',
291+
Error::class,
292+
'2.4.0',
293+
'Elasticsearch service version 7.4 on infrastructure layer is not compatible with current version of ' .
294+
'elasticsearch/elasticsearch module (6.2), used by your Magento application.',
295+
'You can fix this issue by downgrading the Elasticsearch service on your ' .
296+
'Magento Cloud infrastructure to version 6.x.'
297+
],
283298
];
284299
}
285300
}

0 commit comments

Comments
 (0)