Skip to content

Commit 98a678d

Browse files
committed
MQE-1974: Report used deprecated metadata in Test
1 parent 98d9a3b commit 98a678d

File tree

10 files changed

+68
-47
lines changed

10 files changed

+68
-47
lines changed

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

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ class DataObjectHandler implements ObjectHandlerInterface
7575

7676
/**
7777
* Constructor
78+
* @param bool $validateName Set to false to disable name validations
79+
* @throws XmlException
7880
*/
79-
private function __construct()
81+
private function __construct($validateName = true)
8082
{
8183
$parser = ObjectManagerFactory::getObjectManager()->create(DataProfileSchemaParser::class);
8284
$parserOutput = $parser->readDataProfiles();
@@ -85,20 +87,21 @@ private function __construct()
8587
}
8688
$this->entityNameValidator = new NameValidationUtil();
8789
$this->entityKeyValidator = new NameValidationUtil();
88-
$this->entityDataObjects = $this->processParserOutput($parserOutput);
90+
$this->entityDataObjects = $this->processParserOutput($parserOutput, $validateName);
8991
$this->extendUtil = new DataExtensionUtil();
9092
}
9193

9294
/**
9395
* Return the singleton instance of this class. Initialize it if needed.
9496
*
97+
* @param bool $validateName
9598
* @return DataObjectHandler
9699
* @throws \Exception
97100
*/
98-
public static function getInstance()
101+
public static function getInstance($validateName = true)
99102
{
100103
if (!self::$INSTANCE) {
101-
self::$INSTANCE = new DataObjectHandler();
104+
self::$INSTANCE = new DataObjectHandler($validateName);
102105
}
103106
return self::$INSTANCE;
104107
}
@@ -135,11 +138,12 @@ public function getAllObjects()
135138
* Convert the parser output into a collection of EntityDataObjects
136139
*
137140
* @param string[] $parserOutput Primitive array output from the Magento parser.
141+
* @param bool $validateName
138142
* @return EntityDataObject[]
139143
* @throws XmlException
140144
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
141145
*/
142-
private function processParserOutput($parserOutput)
146+
private function processParserOutput($parserOutput, $validateName = true)
143147
{
144148
$entityDataObjects = [];
145149
$rawEntities = $parserOutput[self::_ENTITY];
@@ -150,11 +154,13 @@ private function processParserOutput($parserOutput)
150154
}
151155

152156
$filename = $rawEntity[self::_FILENAME] ?? null;
153-
$this->entityNameValidator->validatePascalCase(
154-
$name,
155-
NameValidationUtil::DATA_ENTITY_NAME,
156-
$filename
157-
);
157+
if ($validateName) {
158+
$this->entityNameValidator->validatePascalCase(
159+
$name,
160+
NameValidationUtil::DATA_ENTITY_NAME,
161+
$filename
162+
);
163+
}
158164
$type = $rawEntity[self::_TYPE] ?? null;
159165
$data = [];
160166
$deprecated = null;
@@ -164,7 +170,7 @@ private function processParserOutput($parserOutput)
164170
$parentEntity = null;
165171

166172
if (array_key_exists(self::_DATA, $rawEntity)) {
167-
$data = $this->processDataElements($rawEntity);
173+
$data = $this->processDataElements($rawEntity, $validateName);
168174
$uniquenessData = $this->processUniquenessData($rawEntity);
169175
}
170176

@@ -191,8 +197,8 @@ private function processParserOutput($parserOutput)
191197
if (array_key_exists(self::OBJ_DEPRECATED, $rawEntity)) {
192198
$deprecated = $rawEntity[self::OBJ_DEPRECATED];
193199
LoggingUtil::getInstance()->getLogger(self::class)->deprecation(
194-
$deprecated,
195-
["dataName" => $filename, "deprecatedEntity" => $deprecated]
200+
"The data entity '{$name}' is deprecated.",
201+
["fileName" => $filename, "deprecatedMessage" => $deprecated]
196202
);
197203
}
198204

@@ -210,8 +216,10 @@ private function processParserOutput($parserOutput)
210216

211217
$entityDataObjects[$entityDataObject->getName()] = $entityDataObject;
212218
}
213-
$this->entityNameValidator->summarize(NameValidationUtil::DATA_ENTITY_NAME);
214-
$this->entityKeyValidator->summarize(NameValidationUtil::DATA_ENTITY_KEY);
219+
if ($validateName) {
220+
$this->entityNameValidator->summarize(NameValidationUtil::DATA_ENTITY_NAME);
221+
$this->entityKeyValidator->summarize(NameValidationUtil::DATA_ENTITY_KEY);
222+
}
215223
return $entityDataObjects;
216224
}
217225

@@ -237,19 +245,22 @@ private function processArray($arrayItems, $data, $key)
237245
* Parses <data> elements in an entity, and returns them as an array of "lowerKey"=>value.
238246
*
239247
* @param string[] $entityData
248+
* @param bool $validateName
240249
* @return string[]
241250
*/
242-
private function processDataElements($entityData)
251+
private function processDataElements($entityData, $validateName = true)
243252
{
244253
$dataValues = [];
245254
foreach ($entityData[self::_DATA] as $dataElement) {
246255
$originalDataElementKey = $dataElement[self::_KEY];
247256
$filename = $entityData[self::_FILENAME] ?? null;
248-
$this->entityKeyValidator->validateCamelCase(
249-
$originalDataElementKey,
250-
NameValidationUtil::DATA_ENTITY_KEY,
251-
$filename
252-
);
257+
if ($validateName) {
258+
$this->entityKeyValidator->validateCamelCase(
259+
$originalDataElementKey,
260+
NameValidationUtil::DATA_ENTITY_KEY,
261+
$filename
262+
);
263+
}
253264
$dataElementKey = strtolower($originalDataElementKey);
254265
$dataElementValue = $dataElement[self::_VALUE] ?? "";
255266
$dataValues[$dataElementKey] = $dataElementValue;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ private function initialize()
215215

216216
if ($deprecated !== null) {
217217
LoggingUtil::getInstance()->getLogger(self::class)->deprecation(
218-
$deprecated,
219-
["operationName" => $dataDefName, "deprecatedOperation" => $deprecated]
218+
$message = "The operation {$dataDefName} is deprecated.",
219+
["operationType" => $operation, "deprecatedMessage" => $deprecated]
220220
);
221221
}
222222

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function createEntity(
8787
$retrievedDependentObjects[] = $this->retrieveEntity($objectKey, $scope);
8888
}
8989

90-
$retrievedEntity = DataObjectHandler::getInstance()->getObject($entity);
90+
$retrievedEntity = DataObjectHandler::getInstance(false)->getObject($entity);
9191

9292
if ($retrievedEntity === null) {
9393
throw new TestReferenceException(
@@ -163,7 +163,7 @@ public function getEntity($key, $scope, $entity, $dependentObjectKeys = [], $sto
163163
$retrievedDependentObjects[] = $this->retrieveEntity($objectKey, $scope);
164164
}
165165

166-
$retrievedEntity = DataObjectHandler::getInstance()->getObject($entity);
166+
$retrievedEntity = DataObjectHandler::getInstance(false)->getObject($entity);
167167
$persistedObject = new DataPersistenceHandler(
168168
$retrievedEntity,
169169
$retrievedDependentObjects

src/Magento/FunctionalTestingFramework/DataGenerator/Objects/OperationDefinitionObject.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\FunctionalTestingFramework\DataGenerator\Objects;
88

9+
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
10+
911
/**
1012
* Class OperationDefinitionObject
1113
* @SuppressWarnings(PHPMD)
@@ -341,4 +343,20 @@ public function addQueryParams()
341343
$this->apiUrl = $this->apiUrl . $paramName . "=" . $paramValue;
342344
}
343345
}
346+
347+
/**
348+
* Function to log a referenced deprecated operation at runtime.
349+
*
350+
* @return void
351+
*/
352+
public function logDeprecated()
353+
{
354+
if ($this->deprecated != null) {
355+
LoggingUtil::getInstance()->getLogger(self::class)->deprecation(
356+
$message = "The operation {$this->name} is deprecated.",
357+
["operationType" => $this->operation, "deprecatedMessage" => $this->deprecated],
358+
true
359+
);
360+
}
361+
}
344362
}

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public function __construct($operation, $entityObject, $storeCode = null)
9292
$this->operation,
9393
$this->entityObject->getType()
9494
);
95+
$this->operationDefinition->logDeprecated();
9596
$this->isJson = false;
9697
}
9798

@@ -125,7 +126,6 @@ public function executeRequest($dependentEntities)
125126
$method = $this->operationDefinition->getApiMethod();
126127
AllureHelper::addAttachmentToCurrentStep($apiUrl, 'API Endpoint');
127128
AllureHelper::addAttachmentToCurrentStep(json_encode($headers, JSON_PRETTY_PRINT), 'Request Headers');
128-
129129
$operationDataResolver = new OperationDataArrayResolver($dependentEntities);
130130
$this->requestData = $operationDataResolver->resolveOperationDataArray(
131131
$this->entityObject,

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/DataPersistenceHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function updateEntity($updateDataName, $updateDependentObjects = [])
110110
foreach ($updateDependentObjects as $dependentObject) {
111111
$this->dependentObjects[] = $dependentObject->getCreatedObject();
112112
}
113-
$updateEntityObject = DataObjectHandler::getInstance()->getObject($updateDataName);
113+
$updateEntityObject = DataObjectHandler::getInstance(false)->getObject($updateDataName);
114114
$curlHandler = new CurlHandler('update', $updateEntityObject, $this->storeCode);
115115
$result = $curlHandler->executeRequest(array_merge($this->dependentObjects, [$this->createdObject]));
116116
$this->setCreatedObject(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ private function __construct()
7979

8080
if ($deprecated !== null) {
8181
LoggingUtil::getInstance()->getLogger(self::class)->deprecation(
82-
$deprecated,
83-
["pageName" => $filename, "deprecatedPage" => $deprecated]
82+
"The page '{$pageName}' is deprecated.",
83+
["fileName" => $filename, "deprecatedMessage" => $deprecated]
8484
);
8585
}
8686

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ private function __construct()
8989
$elementDeprecated = $elementData[self::OBJ_DEPRECATED] ?? null;
9090
if ($elementDeprecated !== null) {
9191
LoggingUtil::getInstance()->getLogger(ElementObject::class)->deprecation(
92-
$elementDeprecated,
93-
["elementName" => $elementName, "deprecatedElement" => $elementDeprecated]
92+
"The element '{$elementName}' is deprecated.",
93+
["fileName" => $filename, "deprecatedMessage" => $elementDeprecated]
9494
);
9595
}
9696
$elements[$elementName] = new ElementObject(

src/Magento/FunctionalTestingFramework/Test/Util/ActionGroupObjectExtractor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public function extractActionGroup($actionGroupData)
6565
if (array_key_exists(self::OBJ_DEPRECATED, $actionGroupData)) {
6666
$deprecated = $actionGroupData[self::OBJ_DEPRECATED];
6767
LoggingUtil::getInstance()->getLogger(ActionGroupObject::class)->deprecation(
68-
$deprecated,
69-
["actionGroupName" => $actionGroupData[self::FILENAME], "deprecatedActionGroup" => $deprecated]
68+
"The action group '{$actionGroupData[self::NAME]}' is deprecated.",
69+
["fileName" => $actionGroupData[self::FILENAME], "deprecatedMessage" => $deprecated]
7070
);
7171
}
7272
$actionGroupReference = $actionGroupData[self::EXTENDS_ACTION_GROUP] ?? null;

src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public function __construct($name, array $handlers = [], array $processors = [])
3636

3737
/**
3838
* Prints a deprecation warning, as well as adds a log at the WARNING level.
39-
* Suppresses logging during execution phase.
4039
*
4140
* @param string $message The log message.
4241
* @param array $context The log context.
@@ -46,14 +45,11 @@ public function __construct($name, array $handlers = [], array $processors = [])
4645
public function deprecation($message, array $context = [], $verbose = false)
4746
{
4847
$message = "DEPRECATION: " . $message;
49-
// print during test generation
50-
if ($this->phase === MftfApplicationConfig::GENERATION_PHASE && $verbose) {
48+
// Suppress print during unit testing
49+
if ($this->phase !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) {
5150
print ($message . json_encode($context) . "\n");
5251
}
53-
// suppress logging during test execution
54-
if ($this->phase !== MftfApplicationConfig::EXECUTION_PHASE) {
55-
parent::warning($message, $context);
56-
}
52+
parent::warning($message, $context);
5753
}
5854

5955
/**
@@ -76,7 +72,6 @@ public function criticalFailure($message, array $context = [], $verbose = false)
7672

7773
/**
7874
* Adds a log record at the NOTICE level.
79-
* Suppresses logging during execution phase.
8075
*
8176
* @param string $message
8277
* @param array $context
@@ -86,13 +81,10 @@ public function criticalFailure($message, array $context = [], $verbose = false)
8681
public function notification($message, array $context = [], $verbose = false)
8782
{
8883
$message = "NOTICE: " . $message;
89-
// print during test generation
90-
if ($this->phase === MftfApplicationConfig::GENERATION_PHASE && $verbose) {
84+
// Suppress print during unit testing
85+
if ($this->phase !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) {
9186
print ($message . json_encode($context) . "\n");
9287
}
93-
// suppress logging during test execution
94-
if ($this->phase !== MftfApplicationConfig::EXECUTION_PHASE) {
95-
parent::notice($message, $context);
96-
}
88+
parent::notice($message, $context);
9789
}
9890
}

0 commit comments

Comments
 (0)