Skip to content

Commit 95062cf

Browse files
authored
MQE-1096: Standardize MFTF Deprecation Warnings
- added MftfLogger and deprecation() function.
1 parent 4c5a133 commit 95062cf

File tree

9 files changed

+44
-10
lines changed

9 files changed

+44
-10
lines changed

dev/tests/_bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
// set mftf appplication context
3131
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::create(
3232
true,
33-
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::GENERATION_PHASE,
33+
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::UNIT_TEST_PHASE,
3434
true,
3535
false
3636
);

dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/AnnotationExtractorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function testMissingAnnotations()
114114
// Asserts
115115
TestLoggingUtil::getInstance()->validateMockLogStatement(
116116
'warning',
117-
'Test testFileName is missing required annotations.',
117+
'DEPRECATION: Test testFileName is missing required annotations.',
118118
[
119119
'testName' => 'testFileName',
120120
'missingAnnotations' => "title, description, severity"

dev/tests/unit/Util/TestLoggingUtil.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use AspectMock\Test as AspectMock;
1010
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
11+
use Magento\FunctionalTestingFramework\Util\Logger\MftfLogger;
1112
use Monolog\Handler\TestHandler;
1213
use Monolog\Logger;
1314
use PHPUnit\Framework\Assert;
@@ -54,7 +55,7 @@ public static function getInstance()
5455
public function setMockLoggingUtil()
5556
{
5657
$this->testLogHandler = new TestHandler();
57-
$testLogger = new Logger('testLogger');
58+
$testLogger = new MftfLogger('testLogger');
5859
$testLogger->pushHandler($this->testLogHandler);
5960
$mockLoggingUtil = AspectMock::double(
6061
LoggingUtil::class,

src/Magento/FunctionalTestingFramework/Config/MftfApplicationConfig.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class MftfApplicationConfig
1111
{
1212
const GENERATION_PHASE = "generation";
1313
const EXECUTION_PHASE = "execution";
14-
const MFTF_PHASES = [self::GENERATION_PHASE, self::EXECUTION_PHASE];
14+
const UNIT_TEST_PHASE = "testing";
15+
const MFTF_PHASES = [self::GENERATION_PHASE, self::EXECUTION_PHASE, self::UNIT_TEST_PHASE];
1516

1617
/**
1718
* Determines whether the user has specified a force option for generation

src/Magento/FunctionalTestingFramework/DataGenerator/Util/DataExtensionUtil.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ public function extendEntity($entityObject)
5252
PHP_EOL
5353
);
5454
}
55-
if (MftfApplicationConfig::getConfig()->verboseEnabled()) {
56-
echo("Extending Data: " . $parentEntity->getName() . " => " . $entityObject->getName() . PHP_EOL);
55+
if (MftfApplicationConfig::getConfig()->verboseEnabled() &&
56+
MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE) {
57+
print("Extending Data: " . $parentEntity->getName() . " => " . $entityObject->getName() . PHP_EOL);
5758
}
5859

5960
//get parent entity type if child does not have a type

src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function trimAssertionAttributes()
280280
if (!empty($oldAttributes)) {
281281
$appConfig = MftfApplicationConfig::getConfig();
282282
if ($appConfig->getPhase() == MftfApplicationConfig::GENERATION_PHASE && $appConfig->verboseEnabled()) {
283-
LoggingUtil::getInstance()->getLogger(ActionObject::class)->warning(
283+
LoggingUtil::getInstance()->getLogger(ActionObject::class)->deprecation(
284284
"use of one line Assertion actions will be deprecated in MFTF 3.0.0, please use nested syntax",
285285
["action" => $this->type, "stepKey" => $this->stepKey]
286286
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private function validateMissingAnnotations($annotationObjects, $filename)
114114

115115
if (!empty($missingAnnotations)) {
116116
$message = "Test {$filename} is missing required annotations.";
117-
LoggingUtil::getInstance()->getLogger(ActionObject::class)->warning(
117+
LoggingUtil::getInstance()->getLogger(ActionObject::class)->deprecation(
118118
$message,
119119
["testName" => $filename, "missingAnnotations" => implode(", ", $missingAnnotations)]
120120
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private function __construct()
5252
* existing instance is simply returned.
5353
*
5454
* @param string $clazz
55-
* @return Logger
55+
* @return MftfLogger
5656
* @throws \Exception
5757
*/
5858
public function getLogger($clazz)
@@ -62,7 +62,7 @@ public function getLogger($clazz)
6262
}
6363

6464
if (!array_key_exists($clazz, $this->loggers)) {
65-
$logger = new Logger($clazz);
65+
$logger = new MftfLogger($clazz);
6666
$logger->pushHandler(new StreamHandler($this->getLoggingPath()));
6767
$this->loggers[$clazz] = $logger;
6868
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\FunctionalTestingFramework\Util\Logger;
8+
9+
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
10+
use Monolog\Handler\StreamHandler;
11+
use Monolog\Logger;
12+
13+
class MftfLogger extends Logger
14+
{
15+
/**
16+
* Prints a deprecation warning, as well as adding a log at the WARNING level.
17+
*
18+
* @param string $message The log message.
19+
* @param array $context The log context.
20+
* @return void
21+
*/
22+
public function deprecation($message, array $context = [])
23+
{
24+
$message = "DEPRECATION: " . $message;
25+
// Suppress print during unit testing
26+
if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE) {
27+
print ($message . json_encode($context) . "\n");
28+
}
29+
parent::warning($message, $context);
30+
}
31+
}

0 commit comments

Comments
 (0)