Skip to content

Commit 74d77de

Browse files
committed
MAGECLOUD-1246: Cover different RabbitMQ relationship names
1 parent 697fad2 commit 74d77de

File tree

2 files changed

+39
-8
lines changed
  • src
    • Process/Deploy/InstallUpdate/ConfigUpdate
    • Test/Unit/Process/Deploy/InstallUpdate/ConfigUpdate

2 files changed

+39
-8
lines changed

src/Process/Deploy/InstallUpdate/ConfigUpdate/Amqp.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ class Amqp implements ProcessInterface
3333
*/
3434
private $configReader;
3535

36+
/**
37+
* Possible names for amqp relationship
38+
*
39+
* @var array
40+
*/
41+
private $possibleRelationshipNames = ['rabbitmq', 'mq', 'amqp'];
42+
3643
/**
3744
* @param Environment $environment
3845
* @param ConfigReader $configReader
@@ -56,7 +63,7 @@ public function __construct(
5663
*/
5764
public function execute()
5865
{
59-
$mqConfig = $this->environment->getRelationship('mq');
66+
$mqConfig = $this->getAmqpConfig();
6067
$config = $this->configReader->read();
6168

6269
if (count($mqConfig)) {
@@ -95,4 +102,22 @@ private function removeAmqpConfig(array $config)
95102

96103
return $config;
97104
}
105+
106+
/**
107+
* Finds if configuration exists for one of possible amqp relationship names and return first match,
108+
* amqp relationship can have different name on different environment.
109+
*
110+
* @return array
111+
*/
112+
private function getAmqpConfig(): array
113+
{
114+
foreach ($this->possibleRelationshipNames as $relationshipName) {
115+
$mqConfig = $this->environment->getRelationship($relationshipName);
116+
if (!empty($mqConfig)) {
117+
return $mqConfig;
118+
}
119+
}
120+
121+
return [];
122+
}
98123
}

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ protected function setUp()
6767
public function testExecuteWithoutAmqp()
6868
{
6969
$config = ['some config'];
70-
$this->environmentMock->expects($this->once())
70+
$this->environmentMock->expects($this->any())
7171
->method('getRelationship')
72-
->with('mq')
72+
->with($this->anything())
7373
->willReturn([]);
7474
$this->configReaderMock->expects($this->once())
7575
->method('read')
@@ -110,10 +110,16 @@ public function testExecuteAddUpdate(array $config)
110110
],
111111
];
112112

113-
$this->environmentMock->expects($this->once())
113+
$this->environmentMock->expects($this->exactly(2))
114114
->method('getRelationship')
115-
->with('mq')
116-
->willReturn($amqpConfig);
115+
->withConsecutive(
116+
['rabbitmq'],
117+
['mq']
118+
)
119+
->willReturnOnConsecutiveCalls(
120+
[],
121+
$amqpConfig
122+
);
117123
$this->configReaderMock->expects($this->once())
118124
->method('read')
119125
->willReturn($config);
@@ -158,9 +164,9 @@ public function executeAddUpdateDataProvider(): array
158164
*/
159165
public function testExecuteRemoveAmqp(array $config, array $expectedConfig)
160166
{
161-
$this->environmentMock->expects($this->once())
167+
$this->environmentMock->expects($this->any())
162168
->method('getRelationship')
163-
->with('mq')
169+
->with($this->anything())
164170
->willReturn([]);
165171
$this->configReaderMock->expects($this->once())
166172
->method('read')

0 commit comments

Comments
 (0)