Skip to content

Commit 9e69d20

Browse files
committed
MQE-2016: Add warning for test materials that violate naming convention
- Extract logging out to its own class
1 parent ae9ec16 commit 9e69d20

File tree

7 files changed

+165
-250
lines changed

7 files changed

+165
-250
lines changed

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/DataObjectHandler.php

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
1515
use Magento\FunctionalTestingFramework\DataGenerator\Util\DataExtensionUtil;
1616
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
17+
use Magento\FunctionalTestingFramework\Util\Validation\NameValidationUtil;
1718

1819
class DataObjectHandler implements ObjectHandlerInterface
1920
{
@@ -59,18 +60,18 @@ class DataObjectHandler implements ObjectHandlerInterface
5960
private $extendUtil;
6061

6162
/**
62-
* Keeps track of data.key's that are not camelCase.
63+
* Validates and keeps track of entity name violations. Entity names should be PascalCase.
6364
*
64-
* @var array
65+
* @var NameValidationUtil
6566
*/
66-
private $entityKeyViolations = [];
67+
private $entityNameValidator;
6768

6869
/**
69-
* Keeps track of data entity names that are not PascalCase.
70+
* Validates and keeps track of entity key violations. Entity keys should be camelCase.
7071
*
71-
* @var array
72+
* @var NameValidationUtil
7273
*/
73-
private $nameViolations = [];
74+
private $entityKeyValidator;
7475

7576
/**
7677
* Constructor
@@ -82,6 +83,8 @@ private function __construct()
8283
if (!$parserOutput) {
8384
return;
8485
}
86+
$this->entityNameValidator = new NameValidationUtil(NameValidationUtil::TYPE_DATA_ENTITY_NAME);
87+
$this->entityKeyValidator = new NameValidationUtil(NameValidationUtil::TYPE_DATA_ENTITY_KEY);
8588
$this->entityDataObjects = $this->processParserOutput($parserOutput);
8689
$this->extendUtil = new DataExtensionUtil();
8790
}
@@ -148,18 +151,7 @@ private function processParserOutput($parserOutput)
148151
}
149152

150153
$filename = $rawEntity[self::_FILENAME] ?? null;
151-
152-
// Check that data entity name is PascalCase
153-
if (!ctype_upper($name[0])) {
154-
$this->nameViolations[] = $name;
155-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
156-
"The data entity {$name} should be PascalCase with an uppercase first letter."
157-
. " See file {$filename}.",
158-
[],
159-
false
160-
);
161-
}
162-
154+
$this->entityNameValidator->validatePascalCase($name, $filename);
163155
$type = $rawEntity[self::_TYPE] ?? null;
164156
$data = [];
165157
$deprecated = null;
@@ -215,7 +207,8 @@ private function processParserOutput($parserOutput)
215207

216208
$entityDataObjects[$entityDataObject->getName()] = $entityDataObject;
217209
}
218-
$this->logViolationSummary();
210+
$this->entityNameValidator->logCountPascalCase();
211+
$this->entityKeyValidator->logCountCamelCase();
219212
return $entityDataObjects;
220213
}
221214

@@ -249,18 +242,7 @@ private function processDataElements($entityData)
249242
foreach ($entityData[self::_DATA] as $dataElement) {
250243
$originalDataElementKey = $dataElement[self::_KEY];
251244
$filename = $entityData[self::_FILENAME] ?? null;
252-
253-
// Check that data.keys are camelCase
254-
if (!ctype_lower($originalDataElementKey[0])) {
255-
$this->entityKeyViolations[] = $originalDataElementKey;
256-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
257-
"The data entity key {$originalDataElementKey} should be camelCase with a lowercase"
258-
. " first letter. See file {$filename}.",
259-
[],
260-
false
261-
);
262-
}
263-
245+
$this->entityKeyValidator->validateCamelCase($originalDataElementKey, $filename);
264246
$dataElementKey = strtolower($originalDataElementKey);
265247
$dataElementValue = $dataElement[self::_VALUE] ?? "";
266248
$dataValues[$dataElementKey] = $dataElementValue;
@@ -338,32 +320,4 @@ private function extendDataObject($dataObject)
338320
}
339321
return $dataObject;
340322
}
341-
342-
/**
343-
* Output to the log a summary of data entity name and data entity key violations.
344-
*
345-
* @throws TestFrameworkException
346-
* @return void
347-
*/
348-
private function logViolationSummary()
349-
{
350-
$nameViolationCount = count($this->nameViolations);
351-
if ($nameViolationCount > 0) {
352-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
353-
"{$nameViolationCount} data entity name violations detected. Data entity names must be"
354-
. " PascalCase with an uppercase first letter.",
355-
[],
356-
true
357-
);
358-
}
359-
$keyViolationCount = count($this->entityKeyViolations);
360-
if ($keyViolationCount > 0) {
361-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
362-
"{$keyViolationCount} data entity key violations detected. Data entity keys must be"
363-
. " camelCase with a lowercase first letter.",
364-
[],
365-
true
366-
);
367-
}
368-
}
369323
}

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
use Magento\FunctionalTestingFramework\DataGenerator\Objects\OperationElement;
1010
use Magento\FunctionalTestingFramework\DataGenerator\Parsers\OperationDefinitionParser;
1111
use Magento\FunctionalTestingFramework\DataGenerator\Util\OperationElementExtractor;
12-
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1312
use Magento\FunctionalTestingFramework\ObjectManager\ObjectHandlerInterface;
1413
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
1514
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
15+
use Magento\FunctionalTestingFramework\Util\Validation\NameValidationUtil;
1616

1717
class OperationDefinitionObjectHandler implements ObjectHandlerInterface
1818
{
@@ -138,18 +138,9 @@ private function initialize()
138138
$parser = $objectManager->create(OperationDefinitionParser::class);
139139
$parserOutput = $parser->readOperationMetadata()[OperationDefinitionObjectHandler::ENTITY_OPERATION_ROOT_TAG];
140140

141-
$nameViolations = [];
141+
$operationNameValidator = new NameValidationUtil(NameValidationUtil::TYPE_METADATA_OPERATION_NAME);
142142
foreach ($parserOutput as $dataDefName => $opDefArray) {
143-
// Check that operation names are PascalCase
144-
if (!ctype_upper($dataDefName[0])) {
145-
$nameViolations[] = $dataDefName;
146-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
147-
"The metadata operation {$dataDefName} should be PascalCase with an uppercase"
148-
. " first letter.",
149-
[],
150-
false
151-
);
152-
}
143+
$operationNameValidator->validatePascalCase($dataDefName);
153144

154145
$operation = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_TYPE];
155146
$dataType = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_DATA_TYPE];
@@ -244,27 +235,7 @@ private function initialize()
244235
$deprecated
245236
);
246237
}
247-
$this->logViolationSummary($nameViolations);
248-
}
249-
250-
/**
251-
* Output to the log a summary of metadata operation name violations.
252-
*
253-
* @param string[] $nameViolations An array of metadata operation names that are not PascalCase.
254-
* @throws TestFrameworkException
255-
* @return void
256-
*/
257-
private function logViolationSummary($nameViolations)
258-
{
259-
$nameViolationCount = count($nameViolations);
260-
if ($nameViolationCount > 0) {
261-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
262-
"{$nameViolationCount} metadata operation name violations detected. Metadata operation names"
263-
. " must be PascalCase with an uppercase first letter.",
264-
[],
265-
true
266-
);
267-
}
238+
$operationNameValidator->logCountPascalCase();
268239
}
269240

270241
/**

src/Magento/FunctionalTestingFramework/Page/Handlers/PageObjectHandler.php

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
namespace Magento\FunctionalTestingFramework\Page\Handlers;
88

9-
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
109
use Magento\FunctionalTestingFramework\ObjectManager\ObjectHandlerInterface;
1110
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
1211
use Magento\FunctionalTestingFramework\Page\Objects\PageObject;
1312
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
13+
use Magento\FunctionalTestingFramework\Util\Validation\NameValidationUtil;
1414
use Magento\FunctionalTestingFramework\XmlParser\PageParser;
1515
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
1616

@@ -55,25 +55,14 @@ private function __construct()
5555
return;
5656
}
5757

58-
$nameViolations = [];
58+
$pageNameValidator = new NameValidationUtil(NameValidationUtil::TYPE_PAGE_NAME);
5959
foreach ($parserOutput as $pageName => $pageData) {
6060
if (preg_match('/[^a-zA-Z0-9_]/', $pageName)) {
6161
throw new XmlException(sprintf(self::NAME_BLACKLIST_ERROR_MSG, $pageName));
6262
}
6363

6464
$filename = $pageData[self::FILENAME] ?? null;
65-
66-
// Check that page names are PascalCase
67-
if (!ctype_upper($pageName[0])) {
68-
$nameViolations[] = $pageName;
69-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
70-
"The page name {$pageName} should be PascalCase with an uppercase first letter."
71-
. " See file {$filename}.",
72-
[],
73-
false
74-
);
75-
}
76-
65+
$pageNameValidator->validatePascalCase($pageName, $filename);
7766
$area = $pageData[self::AREA] ?? null;
7867
$url = $pageData[self::URL] ?? null;
7968

@@ -96,7 +85,7 @@ private function __construct()
9685
$this->pageObjects[$pageName] =
9786
new PageObject($pageName, $url, $module, $sectionNames, $parameterized, $area, $filename, $deprecated);
9887
}
99-
$this->logViolationSummary($nameViolations);
88+
$pageNameValidator->logCountPascalCase();
10089
}
10190

10291
/**
@@ -138,24 +127,4 @@ public function getAllObjects()
138127
{
139128
return $this->pageObjects;
140129
}
141-
142-
/**
143-
* Output to the log a summary of page name violations.
144-
*
145-
* @param string[] $nameViolations An array of page names that are not PascalCase.
146-
* @throws TestFrameworkException
147-
* @return void
148-
*/
149-
private function logViolationSummary($nameViolations)
150-
{
151-
$nameViolationCount = count($nameViolations);
152-
if ($nameViolationCount > 0) {
153-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
154-
"{$nameViolationCount} page name violations detected. Page names must be PascalCase with"
155-
. " an uppercase first letter.",
156-
[],
157-
true
158-
);
159-
}
160-
}
161130
}

src/Magento/FunctionalTestingFramework/Page/Handlers/SectionObjectHandler.php

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\FunctionalTestingFramework\Page\Objects\ElementObject;
1313
use Magento\FunctionalTestingFramework\Page\Objects\SectionObject;
1414
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
15+
use Magento\FunctionalTestingFramework\Util\Validation\NameValidationUtil;
1516
use Magento\FunctionalTestingFramework\XmlParser\SectionParser;
1617
use Magento\FunctionalTestingFramework\Exceptions\XmlException;
1718

@@ -61,8 +62,8 @@ private function __construct()
6162
return;
6263
}
6364

64-
$sectionNameViolations = [];
65-
$elementNameViolations = [];
65+
$sectionNameValidator = new NameValidationUtil(NameValidationUtil::TYPE_SECTION_NAME);
66+
$elementNameValidator = new NameValidationUtil(NameValidationUtil::TYPE_ELEMENT_NAME);
6667
foreach ($parserOutput as $sectionName => $sectionData) {
6768
$elements = [];
6869

@@ -71,35 +72,15 @@ private function __construct()
7172
}
7273

7374
$filename = $sectionData[self::FILENAME] ?? null;
74-
75-
// Check that section names are PascalCase
76-
if (!ctype_upper($sectionName[0])) {
77-
$sectionNameViolations[] = $sectionName;
78-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
79-
"The section name {$sectionName} should be PascalCase with an uppercase first letter."
80-
. " See file {$filename}.",
81-
[],
82-
false
83-
);
84-
}
75+
$sectionNameValidator->validatePascalCase($sectionName, $filename);
8576

8677
try {
8778
foreach ($sectionData[SectionObjectHandler::ELEMENT] as $elementName => $elementData) {
8879
if (preg_match('/[^a-zA-Z0-9_]/', $elementName)) {
8980
throw new XmlException(sprintf(self::ELEMENT_NAME_ERROR_MSG, $elementName, $sectionName));
9081
}
9182

92-
// Check that element names are camelCase
93-
if (!ctype_lower($elementName[0])) {
94-
$elementNameViolations[] = $elementName;
95-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
96-
"The section element name {$elementName} should be camelCase with a lowercase"
97-
. " first letter. See file {$filename}.",
98-
[],
99-
false
100-
);
101-
}
102-
83+
$elementNameValidator->validateCamelCase($elementName, $filename);
10384
$elementType = $elementData[SectionObjectHandler::TYPE] ?? null;
10485
$elementSelector = $elementData[SectionObjectHandler::SELECTOR] ?? null;
10586
$elementLocatorFunc = $elementData[SectionObjectHandler::LOCATOR_FUNCTION] ?? null;
@@ -142,7 +123,8 @@ private function __construct()
142123
$sectionDeprecated
143124
);
144125
}
145-
$this->logViolationSummary($sectionNameViolations, $elementNameViolations);
126+
$sectionNameValidator->logCountPascalCase();
127+
$elementNameValidator->logCountCamelCase();
146128
}
147129

148130
/**
@@ -184,34 +166,4 @@ public function getAllObjects()
184166
{
185167
return $this->sectionObjects;
186168
}
187-
188-
/**
189-
* Output to the log a summary of section name and element name violations.
190-
*
191-
* @param string[] $sectionNameViolations A list of section names that are not PascalCase.
192-
* @param string[] $elementNameViolations A list of element names that are not camelCase.
193-
* @throws TestFrameworkException
194-
* @return void
195-
*/
196-
private function logViolationSummary($sectionNameViolations, $elementNameViolations)
197-
{
198-
$nameViolationCount = count($sectionNameViolations);
199-
if ($nameViolationCount > 0) {
200-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
201-
"{$nameViolationCount} section name violations detected. Section names must be PascalCase"
202-
. " with an uppercase first letter.",
203-
[],
204-
true
205-
);
206-
}
207-
$keyViolationCount = count($elementNameViolations);
208-
if ($keyViolationCount > 0) {
209-
LoggingUtil::getInstance()->getLogger(self::class)->notification(
210-
"{$keyViolationCount} section element name violations detected. Element names must be"
211-
. " camelCase with a lowercase first letter.",
212-
[],
213-
true
214-
);
215-
}
216-
}
217169
}

0 commit comments

Comments
 (0)