Skip to content

Commit 11ccb29

Browse files
committed
Adding Integration test cases for communication.xml merging process
1 parent 2cbb726 commit 11ccb29

File tree

4 files changed

+56
-28
lines changed

4 files changed

+56
-28
lines changed

dev/tests/integration/testsuite/Magento/Framework/Communication/ConfigTest.php

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ class ConfigTest extends \PHPUnit\Framework\TestCase
1717
*/
1818
public function testGetTopics()
1919
{
20-
$topics = $this->getConfigInstance(__DIR__ . '/_files/valid_communication.xml')->getTopics();
20+
$topics = $this->getConfigInstance(
21+
[__DIR__ . '/_files/valid_communication.xml', __DIR__ . '/_files/valid_communication_extra.xml']
22+
)->getTopics();
2123
$expectedParsedTopics = include __DIR__ . '/_files/valid_communication_expected.php';
2224
$this->assertEquals($expectedParsedTopics, $topics);
2325
}
@@ -31,7 +33,7 @@ public function testGetTopicsNumeric()
3133
$this->expectException(\LogicException::class);
3234
$this->expectExceptionMessage('Service method specified in the definition of topic "customerDeletedNumbers" is not av');
3335

34-
$this->getConfigInstance(__DIR__ . '/_files/valid_communication_numeric.xml')->getTopics();
36+
$this->getConfigInstance([__DIR__ . '/_files/valid_communication_numeric.xml'])->getTopics();
3537
}
3638

3739
// @codingStandardsIgnoreStart
@@ -58,15 +60,17 @@ public function testGetTopicsNumericInvalid()
5860
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
5961
$this->expectExceptionMessage('The XML in file "0" is invalid:');
6062

61-
$this->getConfigInstance(__DIR__ . '/_files/invalid_communication_numeric.xml')->getTopics();
63+
$this->getConfigInstance([__DIR__ . '/_files/invalid_communication_numeric.xml'])->getTopics();
6264
}
6365

6466
/**
6567
* Get topic configuration by its name
6668
*/
6769
public function testGetTopic()
6870
{
69-
$topics = $this->getConfigInstance(__DIR__ . '/_files/valid_communication.xml')->getTopic('customerCreated');
71+
$topics = $this->getConfigInstance(
72+
[__DIR__ . '/_files/valid_communication.xml', __DIR__ . '/_files/valid_communication_extra.xml']
73+
)->getTopic('customerCreated');
7074
$expectedParsedTopics = include __DIR__ . '/_files/valid_communication_expected.php';
7175
$this->assertEquals($expectedParsedTopics['customerCreated'], $topics);
7276
}
@@ -80,7 +84,7 @@ public function testGetTopicInvalidName()
8084
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
8185
$this->expectExceptionMessage('Topic "invalidTopic" is not configured.');
8286

83-
$this->getConfigInstance(__DIR__ . '/_files/valid_communication.xml')->getTopic('invalidTopic');
87+
$this->getConfigInstance([__DIR__ . '/_files/valid_communication.xml'])->getTopic('invalidTopic');
8488
}
8589

8690
/**
@@ -90,7 +94,7 @@ public function testGetTopicsExceptionMissingRequest()
9094
$this->expectException(\LogicException::class);
9195
$this->expectExceptionMessage('Either "request" or "schema" attribute must be specified for topic "customerUpdated"');
9296

93-
$this->getConfigInstance(__DIR__ . '/_files/communication_missing_request.xml')->getTopics();
97+
$this->getConfigInstance([__DIR__ . '/_files/communication_missing_request.xml'])->getTopics();
9498
}
9599

96100
/**
@@ -100,7 +104,7 @@ public function testGetTopicsExceptionNotExistingServiceMethod()
100104
$this->expectException(\LogicException::class);
101105
$this->expectExceptionMessage('Service method specified in the definition of topic "customerRetrieved" is not');
102106

103-
$this->getConfigInstance(__DIR__ . '/_files/communication_not_existing_service_method.xml')->getTopics();
107+
$this->getConfigInstance([__DIR__ . '/_files/communication_not_existing_service_method.xml'])->getTopics();
104108
}
105109

106110
/**
@@ -110,7 +114,7 @@ public function testGetTopicsExceptionNotExistingService()
110114
$this->expectException(\LogicException::class);
111115
$this->expectExceptionMessage('Service method specified in the definition of topic "customerRetrieved" is not');
112116

113-
$this->getConfigInstance(__DIR__ . '/_files/communication_not_existing_service.xml')->getTopics();
117+
$this->getConfigInstance([__DIR__ . '/_files/communication_not_existing_service.xml'])->getTopics();
114118
}
115119

116120
/**
@@ -120,7 +124,7 @@ public function testGetTopicsExceptionNoAttributes()
120124
$this->expectException(\LogicException::class);
121125
$this->expectExceptionMessage('Either "request" or "schema" attribute must be specified for topic "customerRetrieved"');
122126

123-
$this->getConfigInstance(__DIR__ . '/_files/communication_no_attributes.xml')->getTopics();
127+
$this->getConfigInstance([__DIR__ . '/_files/communication_no_attributes.xml'])->getTopics();
124128
}
125129

126130
/**
@@ -130,7 +134,7 @@ public function testGetTopicsExceptionInvalidResponseSchema()
130134
$this->expectException(\LogicException::class);
131135
$this->expectExceptionMessage('Response schema definition for topic "customerUpdated" should reference existing');
132136

133-
$this->getConfigInstance(__DIR__ . '/_files/communication_response_not_existing_service.xml')->getTopics();
137+
$this->getConfigInstance([__DIR__ . '/_files/communication_response_not_existing_service.xml'])->getTopics();
134138
}
135139

136140
/**
@@ -140,7 +144,7 @@ public function testGetTopicsExceptionInvalidRequestSchema()
140144
$this->expectException(\LogicException::class);
141145
$this->expectExceptionMessage('Request schema definition for topic "customerUpdated" should reference existing');
142146

143-
$this->getConfigInstance(__DIR__ . '/_files/communication_request_not_existing_service.xml')->getTopics();
147+
$this->getConfigInstance([__DIR__ . '/_files/communication_request_not_existing_service.xml'])->getTopics();
144148
}
145149

146150
/**
@@ -150,7 +154,7 @@ public function testGetTopicsExceptionMultipleHandlersSynchronousMode()
150154
$this->expectException(\LogicException::class);
151155
$this->expectExceptionMessage('Topic "customerDeleted" is configured for synchronous requests, that is why it must');
152156

153-
$this->getConfigInstance(__DIR__ . '/_files/communication_multiple_handlers_synchronous_mode.xml')->getTopics();
157+
$this->getConfigInstance([__DIR__ . '/_files/communication_multiple_handlers_synchronous_mode.xml'])->getTopics();
154158
}
155159

156160
/**
@@ -160,7 +164,7 @@ public function testGetTopicsExceptionInvalidHandler()
160164
$this->expectException(\LogicException::class);
161165
$this->expectExceptionMessage('Service method specified in the definition of handler "customHandler" for topic "custo');
162166

163-
$this->getConfigInstance(__DIR__ . '/_files/communication_not_existing_handler_method.xml')->getTopics();
167+
$this->getConfigInstance([__DIR__ . '/_files/communication_not_existing_handler_method.xml'])->getTopics();
164168
}
165169

166170
/**
@@ -171,7 +175,7 @@ public function testGetTopicsExceptionInvalidTopicNameInEnv()
171175
$this->expectExceptionMessage('Topic name "customerAdded" and attribute "name" = "customerCreated" must be equal');
172176

173177
$this->getConfigInstance(
174-
__DIR__ . '/_files/valid_communication.xml',
178+
[__DIR__ . '/_files/valid_communication.xml'],
175179
__DIR__ . '/_files/communication_invalid_topic_name.php'
176180
)->getTopics();
177181
}
@@ -184,7 +188,7 @@ public function testGetTopicsExceptionTopicWithoutDataInEnv()
184188
$this->expectExceptionMessage('Topic "customerCreated" must contain data');
185189

186190
$this->getConfigInstance(
187-
__DIR__ . '/_files/valid_communication.xml',
191+
[__DIR__ . '/_files/valid_communication.xml'],
188192
__DIR__ . '/_files/communication_topic_without_data.php'
189193
)->getTopics();
190194
}
@@ -197,7 +201,7 @@ public function testGetTopicsExceptionTopicWithMissedKeysInEnv()
197201
$this->expectExceptionMessage('Topic "customerCreated" has missed keys: [response]');
198202

199203
$this->getConfigInstance(
200-
__DIR__ . '/_files/valid_communication.xml',
204+
[__DIR__ . '/_files/valid_communication.xml'],
201205
__DIR__ . '/_files/communication_topic_with_missed_keys.php'
202206
)->getTopics();
203207
}
@@ -210,7 +214,7 @@ public function testGetTopicsExceptionTopicWithExcessiveKeysInEnv()
210214
$this->expectExceptionMessage('Topic "customerCreated" has excessive keys: [some_incorrect_key]');
211215

212216
$this->getConfigInstance(
213-
__DIR__ . '/_files/valid_communication.xml',
217+
[__DIR__ . '/_files/valid_communication.xml'],
214218
__DIR__ . '/_files/communication_topic_with_excessive_keys.php'
215219
)->getTopics();
216220
}
@@ -223,7 +227,7 @@ public function testGetTopicsExceptionTopicWithNonMatchedNameInEnv()
223227
$this->expectExceptionMessage('Topic name "customerDeleted" and attribute "name" = "customerRemoved" must be equal');
224228

225229
$this->getConfigInstance(
226-
__DIR__ . '/_files/valid_communication.xml',
230+
[__DIR__ . '/_files/valid_communication.xml'],
227231
__DIR__ . '/_files/communication_with_non_matched_name.php'
228232
)->getTopics();
229233
}
@@ -236,7 +240,7 @@ public function testGetTopicsExceptionMultipleHandlersSynchronousModeInEnv()
236240
$this->expectExceptionMessage('Topic "customerDeleted" is configured for synchronous requests, that is why it must');
237241

238242
$this->getConfigInstance(
239-
__DIR__ . '/_files/valid_communication.xml',
243+
[__DIR__ . '/_files/valid_communication.xml'],
240244
__DIR__ . '/_files/communication_multiple_handlers_synchronous_mode.php'
241245
)->getTopics();
242246
}
@@ -249,7 +253,7 @@ public function testGetTopicsExceptionInvalidRequestSchemaInEnv()
249253
$this->expectExceptionMessage('Request schema definition for topic "customerCreated" should reference existing service');
250254

251255
$this->getConfigInstance(
252-
__DIR__ . '/_files/valid_communication.xml',
256+
[__DIR__ . '/_files/valid_communication.xml'],
253257
__DIR__ . '/_files/communication_request_not_existing_service.php'
254258
)->getTopics();
255259
}
@@ -262,7 +266,7 @@ public function testGetTopicsExceptionInvalidResponseSchemaInEnv()
262266
$this->expectExceptionMessage('Response schema definition for topic "customerCreated" should reference existing type o');
263267

264268
$this->getConfigInstance(
265-
__DIR__ . '/_files/valid_communication.xml',
269+
[__DIR__ . '/_files/valid_communication.xml'],
266270
__DIR__ . '/_files/communication_response_not_existing_service.php'
267271
)->getTopics();
268272
}
@@ -275,7 +279,7 @@ public function testGetTopicsExceptionInvalidMethodInHandlerInEnv()
275279
$this->expectExceptionMessage('Service method specified in the definition of handler "customerCreatedFirst" for topic');
276280

277281
$this->getConfigInstance(
278-
__DIR__ . '/_files/valid_communication.xml',
282+
[__DIR__ . '/_files/valid_communication.xml'],
279283
__DIR__ . '/_files/communication_not_existing_handler_method.php'
280284
)->getTopics();
281285
}
@@ -288,7 +292,7 @@ public function testGetTopicsExceptionWithDisabledHandlerInEnv()
288292
$this->expectExceptionMessage('Disabled handler "default" for topic "customerCreated" cannot be added to the config fi');
289293

290294
$this->getConfigInstance(
291-
__DIR__ . '/_files/valid_communication.xml',
295+
[__DIR__ . '/_files/valid_communication.xml'],
292296
__DIR__ . '/_files/communication_with_disabled_handler.php'
293297
)->getTopics();
294298
}
@@ -301,7 +305,7 @@ public function testGetTopicsExceptionIncorrectRequestSchemaTypeInEnv()
301305
$this->expectExceptionMessage('Request schema type for topic "customerCreated" must be "object_interface" or "service_');
302306

303307
$this->getConfigInstance(
304-
__DIR__ . '/_files/valid_communication.xml',
308+
[__DIR__ . '/_files/valid_communication.xml'],
305309
__DIR__ . '/_files/communication_incorrect_request_schema_type.php'
306310
)->getTopics();
307311
}
@@ -314,24 +318,28 @@ public function testGetTopicsExceptionIsNotBooleanTypeOfIsSynchronousInEnv()
314318
$this->expectExceptionMessage('The attribute "is_synchronous" for topic "customerCreated" should have the value of the');
315319

316320
$this->getConfigInstance(
317-
__DIR__ . '/_files/valid_communication.xml',
321+
[__DIR__ . '/_files/valid_communication.xml'],
318322
__DIR__ . '/_files/communication_is_synchronous_is_not_boolean.php'
319323
)->getTopics();
320324
}
321325

322326
/**
323327
* Create config instance initialized with configuration from $configFilePath
324328
*
325-
* @param string $configFilePath
329+
* @param array $configFilePaths
326330
* @param string|null $envConfigFilePath
327331
* @return \Magento\Framework\Communication\ConfigInterface
328332
*/
329-
protected function getConfigInstance($configFilePath, $envConfigFilePath = null)
333+
protected function getConfigInstance($configFilePaths, $envConfigFilePath = null)
330334
{
331335
$fileResolver = $this->getMockForAbstractClass(\Magento\Framework\Config\FileResolverInterface::class);
336+
$fileResolverResult = [];
337+
foreach ($configFilePaths as $configFilePath) {
338+
$fileResolverResult[] = file_get_contents($configFilePath);
339+
}
332340
$fileResolver->expects($this->any())
333341
->method('get')
334-
->willReturn([file_get_contents($configFilePath)]);
342+
->willReturn($fileResolverResult);
335343
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
336344
$xmlReader = $objectManager->create(
337345
\Magento\Framework\Communication\Config\Reader\XmlReader::class,

dev/tests/integration/testsuite/Magento/Framework/Communication/_files/valid_communication_expected.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
'type' => \Magento\Customer\Api\CustomerRepositoryInterface::class,
3434
'method' => 'delete',
3535
],
36+
'customerCreatedExtra' => [
37+
'type' => \Magento\Customer\Api\CustomerRepositoryInterface::class,
38+
'method' => 'save',
39+
],
3640
'saveNameNotDisabled' => [
3741
'type' => \Magento\Customer\Api\CustomerRepositoryInterface::class,
3842
'method' => 'save',
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Communication/etc/communication.xsd">
9+
<topic name="customerAdded" request="string[]">
10+
<handler name="customerCreatedExtra" type="Magento\Customer\Api\CustomerRepositoryInterface" method="save"/>
11+
</topic>
12+
</config>

dev/tests/integration/testsuite/Magento/Framework/Communication/_files/valid_communication_input.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
'type' => \Magento\Customer\Api\CustomerRepositoryInterface::class,
3636
'method' => 'delete',
3737
],
38+
'customerCreatedExtra' => [
39+
'type' => \Magento\Customer\Api\CustomerRepositoryInterface::class,
40+
'method' => 'save',
41+
],
3842
'saveNameNotDisabled' => [
3943
'type' => \Magento\Customer\Api\CustomerRepositoryInterface::class,
4044
'method' => 'save',

0 commit comments

Comments
 (0)