Skip to content

Commit a7bcac3

Browse files
author
Oleksii Korshenko
authored
Merge pull request #206 from magento-okapis/MAGETWO-54560-Split-Queue-Configs
[Okapis] Multiple Topics per Queue
2 parents 8332b1b + 8b35dd8 commit a7bcac3

File tree

10 files changed

+190
-39
lines changed

10 files changed

+190
-39
lines changed

dev/tests/api-functional/framework/bootstrap.php

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,8 @@
2020
$logWriter->setFormatter(new \Zend_Log_Formatter_Simple('%message%' . PHP_EOL));
2121
$logger = new \Zend_Log($logWriter);
2222

23-
/** Copy test modules to app/code/Magento to make them visible for Magento instance */
24-
$pathToCommittedTestModules = __DIR__ . '/../_files/Magento';
25-
$pathToInstalledMagentoInstanceModules = __DIR__ . '/../../../../app/code/Magento';
26-
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($pathToCommittedTestModules));
27-
/** @var SplFileInfo $file */
28-
foreach ($iterator as $file) {
29-
if (!$file->isDir()) {
30-
$source = $file->getPathname();
31-
$relativePath = substr($source, strlen($pathToCommittedTestModules));
32-
$destination = $pathToInstalledMagentoInstanceModules . $relativePath;
33-
$targetDir = dirname($destination);
34-
if (!is_dir($targetDir)) {
35-
mkdir($targetDir, 0755, true);
36-
}
37-
copy($source, $destination);
38-
}
39-
}
40-
unset($iterator, $file);
41-
42-
// Register the modules under '_files/'
43-
$pathPattern = $pathToInstalledMagentoInstanceModules . '/TestModule*/registration.php';
44-
$files = glob($pathPattern, GLOB_NOSORT);
45-
if ($files === false) {
46-
throw new \RuntimeException('glob() returned error while searching in \'' . $pathPattern . '\'');
47-
}
48-
foreach ($files as $file) {
49-
include $file;
50-
}
23+
$testFrameworkDir = __DIR__;
24+
require_once __DIR__ . '/../../integration/framework/deployTestModules.php';
5125

5226
/* Bootstrap the application */
5327
$settings = new \Magento\TestFramework\Bootstrap\Settings($testsBaseDir, get_defined_constants());
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "magento/module-sample-test",
3+
"description": "test sample module",
4+
"require": {
5+
"php": "~5.6.0|7.0.2|7.0.4|~7.0.6",
6+
"magento/framework": "100.1.*",
7+
"magento/module-integration": "100.1.*"
8+
},
9+
"type": "magento2-module",
10+
"version": "1.0",
11+
"extra": {
12+
"map": [
13+
[
14+
"*",
15+
"Magento/TestModuleSample"
16+
]
17+
]
18+
}
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. 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:Module/etc/module.xsd">
9+
<module name="Magento_TestModuleSample" setup_version="0.0.1" active="true">
10+
</module>
11+
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\Component\ComponentRegistrar;
8+
9+
$registrar = new ComponentRegistrar();
10+
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleSample') === null) {
11+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleSample', __DIR__);
12+
}

dev/tests/integration/framework/bootstrap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
define('TESTS_TEMP_DIR', $testsBaseDir . '/tmp');
1616
}
1717

18+
$testFrameworkDir = __DIR__;
19+
require_once 'deployTestModules.php';
20+
1821
try {
1922
setCustomErrorHandler();
2023

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* @var $testFrameworkDir string - Must be defined in parent script.
9+
*/
10+
11+
/** Copy test modules to app/code/Magento to make them visible for Magento instance */
12+
$pathToCommittedTestModules = $testFrameworkDir . '/../_files/Magento';
13+
$pathToInstalledMagentoInstanceModules = $testFrameworkDir . '/../../../../app/code/Magento';
14+
$iterator = new RecursiveIteratorIterator(
15+
new RecursiveDirectoryIterator($pathToCommittedTestModules, RecursiveDirectoryIterator::FOLLOW_SYMLINKS)
16+
);
17+
/** @var SplFileInfo $file */
18+
foreach ($iterator as $file) {
19+
if (!$file->isDir()) {
20+
$source = $file->getPathname();
21+
$relativePath = substr($source, strlen($pathToCommittedTestModules));
22+
$destination = $pathToInstalledMagentoInstanceModules . $relativePath;
23+
$targetDir = dirname($destination);
24+
if (!is_dir($targetDir)) {
25+
mkdir($targetDir, 0755, true);
26+
}
27+
copy($source, $destination);
28+
}
29+
}
30+
unset($iterator, $file);
31+
32+
// Register the modules under '_files/'
33+
$pathPattern = $pathToInstalledMagentoInstanceModules . '/TestModule*/registration.php';
34+
$files = glob($pathPattern, GLOB_NOSORT);
35+
if ($files === false) {
36+
throw new \RuntimeException('glob() returned error while searching in \'' . $pathPattern . '\'');
37+
}
38+
foreach ($files as $file) {
39+
include $file;
40+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\TestModuleSample;
7+
8+
class ModuleInstallationTest extends \PHPUnit_Framework_TestCase
9+
{
10+
public function testSampleModuleInstallation()
11+
{
12+
/** @var \Magento\Framework\Module\ModuleListInterface $moduleList */
13+
$moduleList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
14+
\Magento\Framework\Module\ModuleListInterface::class
15+
);
16+
$this->assertTrue(
17+
$moduleList->has('Magento_TestModuleSample'),
18+
'Test module [Magento_TestModuleSample] is not installed'
19+
);
20+
}
21+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Communication\Config;
7+
8+
use Magento\Framework\Exception\LocalizedException;
9+
use Magento\Framework\Phrase;
10+
11+
/**
12+
* Parser helper for communication-related configs.
13+
*/
14+
class ConfigParser
15+
{
16+
const TYPE_NAME = 'typeName';
17+
const METHOD_NAME = 'methodName';
18+
19+
/**
20+
* Parse service method name.
21+
*
22+
* @param string $serviceMethod
23+
* @return array Contains class name and method name
24+
* @throws LocalizedException
25+
*/
26+
public function parseServiceMethod($serviceMethod)
27+
{
28+
$pattern = '/^([a-zA-Z\\\\]+)::([a-zA-Z]+)$/';
29+
preg_match($pattern, $serviceMethod, $matches);
30+
if (!isset($matches[1]) || !isset($matches[2])) {
31+
throw new LocalizedException(
32+
new Phrase(
33+
'Service method "%serviceMethod" must match the following pattern: "%pattern"',
34+
['serviceMethod' => $serviceMethod, 'pattern' => $pattern]
35+
)
36+
);
37+
}
38+
$className = $matches[1];
39+
$methodName = $matches[2];
40+
return [self::TYPE_NAME => $className, self::METHOD_NAME => $methodName];
41+
}
42+
}

lib/internal/Magento/Framework/Communication/Config/Reader/XmlReader/Converter.php

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
use Magento\Framework\Phrase;
1010
use Magento\Framework\Communication\Config\ReflectionGenerator;
1111
use Magento\Framework\Stdlib\BooleanUtils;
12+
use Magento\Framework\Communication\Config\ConfigParser;
1213
use Magento\Framework\Communication\Config\Reader\XmlReader\Validator;
1314

1415
/**
1516
* Converts Communication config from \DOMDocument to array
1617
*/
1718
class Converter implements \Magento\Framework\Config\ConverterInterface
1819
{
20+
/**
21+
* @deprecated
22+
* @see ConfigParser::SERVICE_METHOD_NAME_PATTERN
23+
*/
1924
const SERVICE_METHOD_NAME_PATTERN = '/^([a-zA-Z\\\\]+)::([a-zA-Z]+)$/';
2025

2126
/**
@@ -33,6 +38,11 @@ class Converter implements \Magento\Framework\Config\ConverterInterface
3338
*/
3439
private $xmlValidator;
3540

41+
/**
42+
* @var ConfigParser
43+
*/
44+
private $configParser;
45+
3646
/**
3747
* Initialize dependencies
3848
*
@@ -50,6 +60,21 @@ public function __construct(
5060
$this->xmlValidator = $xmlValidator;
5161
}
5262

63+
/**
64+
* The getter function to get the new ConfigParser dependency.
65+
*
66+
* @return \Magento\Framework\Communication\Config\ConfigParser
67+
* @deprecated
68+
*/
69+
private function getConfigParser()
70+
{
71+
if ($this->configParser === null) {
72+
$this->configParser = \Magento\Framework\App\ObjectManager::getInstance()
73+
->get(\Magento\Framework\Communication\Config\ConfigParser::class);
74+
}
75+
return $this->configParser;
76+
}
77+
5378
/**
5479
* Convert dom node tree to array
5580
*
@@ -81,8 +106,8 @@ protected function extractTopics($config)
81106
$serviceMethod = $this->getServiceMethodBySchema($topicNode);
82107
$requestResponseSchema = $serviceMethod
83108
? $this->reflectionGenerator->extractMethodMetadata(
84-
$serviceMethod['typeName'],
85-
$serviceMethod['methodName']
109+
$serviceMethod[ConfigParser::TYPE_NAME],
110+
$serviceMethod[ConfigParser::METHOD_NAME]
86111
)
87112
: null;
88113
$requestSchema = $this->extractTopicRequestSchema($topicNode);
@@ -104,8 +129,8 @@ protected function extractTopics($config)
104129
if ($serviceMethod) {
105130
$output[$topicName] = $this->reflectionGenerator->generateTopicConfigForServiceMethod(
106131
$topicName,
107-
$serviceMethod['typeName'],
108-
$serviceMethod['methodName'],
132+
$serviceMethod[ConfigParser::TYPE_NAME],
133+
$serviceMethod[ConfigParser::METHOD_NAME],
109134
$handlers
110135
);
111136
} else if ($requestSchema && $responseSchema) {
@@ -213,7 +238,8 @@ protected function getServiceMethodBySchema($topicNode)
213238
return null;
214239
}
215240
$topicName = $topicAttributes->getNamedItem('name')->nodeValue;
216-
return $this->parseServiceMethod($topicAttributes->getNamedItem('schema')->nodeValue, $topicName);
241+
$serviceMethod = $topicAttributes->getNamedItem('schema')->nodeValue;
242+
return $this->parseServiceMethod($serviceMethod, $topicName);
217243
}
218244

219245
/**
@@ -225,10 +251,13 @@ protected function getServiceMethodBySchema($topicNode)
225251
*/
226252
protected function parseServiceMethod($serviceMethod, $topicName)
227253
{
228-
preg_match(self::SERVICE_METHOD_NAME_PATTERN, $serviceMethod, $matches);
229-
$className = $matches[1];
230-
$methodName = $matches[2];
231-
$this->xmlValidator->validateServiceMethod($serviceMethod, $topicName, $className, $methodName);
232-
return ['typeName' => $className, 'methodName' => $methodName];
254+
$parsedServiceMethod = $this->getConfigParser()->parseServiceMethod($serviceMethod);
255+
$this->xmlValidator->validateServiceMethod(
256+
$serviceMethod,
257+
$topicName,
258+
$parsedServiceMethod[ConfigParser::TYPE_NAME],
259+
$parsedServiceMethod[ConfigParser::METHOD_NAME]
260+
);
261+
return $parsedServiceMethod;
233262
}
234263
}

lib/internal/Magento/Framework/Communication/ConfigInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface ConfigInterface
4141
* Get configuration of the specified topic.
4242
*
4343
* @param string $topicName
44-
* @return string[]
44+
* @return array
4545
* @throws LocalizedException
4646
*/
4747
public function getTopic($topicName);

0 commit comments

Comments
 (0)