Skip to content

MQE-1096: Standardize MFTF Deprecation Warnings #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/tests/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// set mftf appplication context
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::create(
true,
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::GENERATION_PHASE,
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::UNIT_TEST_PHASE,
true,
false
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function testMissingAnnotations()
// Asserts
TestLoggingUtil::getInstance()->validateMockLogStatement(
'warning',
'Test testFileName is missing required annotations.',
'DEPRECATION: Test testFileName is missing required annotations.',
[
'testName' => 'testFileName',
'missingAnnotations' => "title, description, severity"
Expand Down
3 changes: 2 additions & 1 deletion dev/tests/unit/Util/TestLoggingUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use AspectMock\Test as AspectMock;
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
use Magento\FunctionalTestingFramework\Util\Logger\MftfLogger;
use Monolog\Handler\TestHandler;
use Monolog\Logger;
use PHPUnit\Framework\Assert;
Expand Down Expand Up @@ -54,7 +55,7 @@ public static function getInstance()
public function setMockLoggingUtil()
{
$this->testLogHandler = new TestHandler();
$testLogger = new Logger('testLogger');
$testLogger = new MftfLogger('testLogger');
$testLogger->pushHandler($this->testLogHandler);
$mockLoggingUtil = AspectMock::double(
LoggingUtil::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class MftfApplicationConfig
{
const GENERATION_PHASE = "generation";
const EXECUTION_PHASE = "execution";
const MFTF_PHASES = [self::GENERATION_PHASE, self::EXECUTION_PHASE];
const UNIT_TEST_PHASE = "testing";
const MFTF_PHASES = [self::GENERATION_PHASE, self::EXECUTION_PHASE, self::UNIT_TEST_PHASE];

/**
* Determines whether the user has specified a force option for generation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ public function extendEntity($entityObject)
PHP_EOL
);
}
if (MftfApplicationConfig::getConfig()->verboseEnabled()) {
echo("Extending Data: " . $parentEntity->getName() . " => " . $entityObject->getName() . PHP_EOL);
if (MftfApplicationConfig::getConfig()->verboseEnabled() &&
MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE) {
print("Extending Data: " . $parentEntity->getName() . " => " . $entityObject->getName() . PHP_EOL);
}

//get parent entity type if child does not have a type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function trimAssertionAttributes()
if (!empty($oldAttributes)) {
$appConfig = MftfApplicationConfig::getConfig();
if ($appConfig->getPhase() == MftfApplicationConfig::GENERATION_PHASE && $appConfig->verboseEnabled()) {
LoggingUtil::getInstance()->getLogger(ActionObject::class)->warning(
LoggingUtil::getInstance()->getLogger(ActionObject::class)->deprecation(
"use of one line Assertion actions will be deprecated in MFTF 3.0.0, please use nested syntax",
["action" => $this->type, "stepKey" => $this->stepKey]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private function validateMissingAnnotations($annotationObjects, $filename)

if (!empty($missingAnnotations)) {
$message = "Test {$filename} is missing required annotations.";
LoggingUtil::getInstance()->getLogger(ActionObject::class)->warning(
LoggingUtil::getInstance()->getLogger(ActionObject::class)->deprecation(
$message,
["testName" => $filename, "missingAnnotations" => implode(", ", $missingAnnotations)]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private function __construct()
* existing instance is simply returned.
*
* @param string $clazz
* @return Logger
* @return MftfLogger
* @throws \Exception
*/
public function getLogger($clazz)
Expand All @@ -62,7 +62,7 @@ public function getLogger($clazz)
}

if (!array_key_exists($clazz, $this->loggers)) {
$logger = new Logger($clazz);
$logger = new MftfLogger($clazz);
$logger->pushHandler(new StreamHandler($this->getLoggingPath()));
$this->loggers[$clazz] = $logger;
}
Expand Down
31 changes: 31 additions & 0 deletions src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\FunctionalTestingFramework\Util\Logger;

use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

class MftfLogger extends Logger
{
/**
* Prints a deprecation warning, as well as adding a log at the WARNING level.
*
* @param string $message The log message.
* @param array $context The log context.
* @return void
*/
public function deprecation($message, array $context = [])
{
$message = "DEPRECATION: " . $message;
// Suppress print during unit testing
if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE) {
print ($message . json_encode($context) . "\n");
}
parent::warning($message, $context);
}
}