Skip to content

Commit 5603987

Browse files
authored
MCLOUD-7572: RabbitMq version validation error (#39)
1 parent 5e33685 commit 5603987

File tree

2 files changed

+117
-1
lines changed

2 files changed

+117
-1
lines changed

src/Config/Relationship.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ public function get(Config $config): array
8282
{
8383
$relationships = [];
8484
foreach (self::$defaultConfiguration as $serviceName => $serviceConfig) {
85-
if ($config->hasServiceEnabled($this->convertServiceName($serviceName))) {
85+
if ($config->hasServiceEnabled($this->convertServiceName($serviceName))
86+
&& !empty($serviceConfig[0])) {
87+
$serviceConfig[0]['type'] = $this->convertServiceName($serviceName) . ':'
88+
. $config->getServiceVersion($this->convertServiceName($serviceName));
8689
$relationships[$serviceName] = $serviceConfig;
8790
}
8891
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CloudDocker\Test\Unit\Config;
9+
10+
use Magento\CloudDocker\Config\Config;
11+
use Magento\CloudDocker\Config\Relationship;
12+
use Magento\CloudDocker\Service\ServiceInterface;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* @inheritDoc
17+
*/
18+
class RelationshipTest extends TestCase
19+
{
20+
/**
21+
* @var Relationship
22+
*/
23+
private $relationship;
24+
25+
/**
26+
* @var \PHPUnit\Framework\MockObject\MockObject|Config
27+
*/
28+
private $configMock;
29+
30+
public $defaultConfigs = [
31+
'database' => [
32+
[
33+
'host' => 'db',
34+
'path' => 'magento2',
35+
'password' => 'magento2',
36+
'username' => 'magento2',
37+
'port' => '3306'
38+
],
39+
],
40+
'redis' => [
41+
[
42+
'host' => 'redis',
43+
'port' => '6379'
44+
]
45+
],
46+
'elasticsearch' => [
47+
[
48+
'host' => 'elasticsearch',
49+
'port' => '9200',
50+
],
51+
],
52+
'rabbitmq' => [
53+
[
54+
'host' => 'rabbitmq',
55+
'port' => '5672',
56+
'username' => 'guest',
57+
'password' => 'guest',
58+
]
59+
],
60+
];
61+
62+
/**
63+
* @inheritDoc
64+
*/
65+
protected function setUp(): void
66+
{
67+
$this->configMock = $this->createMock(Config::class);
68+
$this->relationship = new Relationship();
69+
}
70+
71+
/**
72+
* @throws \Magento\CloudDocker\App\ConfigurationMismatchException
73+
*/
74+
public function testGet()
75+
{
76+
$mysqlVersion = '10.4';
77+
$redisVersion = '5.2';
78+
$esVersion = '7.7';
79+
$rmqVersion = '3.5';
80+
$configWithType = $this->defaultConfigs;
81+
$configWithType['database'][0]['type'] = "mysql:$mysqlVersion";
82+
$configWithType['redis'][0]['type'] = "redis:$redisVersion";
83+
$configWithType['elasticsearch'][0]['type'] = "elasticsearch:$esVersion";
84+
$configWithType['rabbitmq'][0]['type'] = "rabbitmq:$rmqVersion";
85+
86+
$this->configMock->expects($this->exactly(6))
87+
->method('hasServiceEnabled')
88+
->withConsecutive(
89+
[ServiceInterface::SERVICE_DB],
90+
[ServiceInterface::SERVICE_DB_QUOTE],
91+
[ServiceInterface::SERVICE_DB_SALES],
92+
['redis'],
93+
['elasticsearch'],
94+
['rabbitmq']
95+
)
96+
->willReturnOnConsecutiveCalls(
97+
true, false, false, true, true, true
98+
);
99+
$this->configMock->expects($this->exactly(4))
100+
->method('getServiceVersion')
101+
->withConsecutive(
102+
[ServiceInterface::SERVICE_DB],
103+
['redis'],
104+
['elasticsearch'],
105+
['rabbitmq']
106+
)
107+
->willReturnOnConsecutiveCalls(
108+
$mysqlVersion, $redisVersion, $esVersion, $rmqVersion
109+
);
110+
111+
$this->assertEquals($configWithType, $this->relationship->get($this->configMock));
112+
}
113+
}

0 commit comments

Comments
 (0)