Skip to content

Commit 741e81d

Browse files
committed
MQE-1541: Add option to generate:tests for XSD validation on 'merged files'
Updates for default debugging
1 parent f1f2381 commit 741e81d

File tree

13 files changed

+62
-84
lines changed

13 files changed

+62
-84
lines changed

etc/config/.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ BROWSER=chrome
4242
MODULE_WHITELIST=Magento_Framework,Magento_ConfigurableProductWishlist,Magento_ConfigurableProductCatalogSearch
4343
#CUSTOM_MODULE_PATHS=
4444

45-
#*** Bool properties which allows the user to toggle debug output during test execution
45+
#*** Bool property which allows the user to toggle debug output during test execution
4646
#MFTF_DEBUG=
47-
#MFTF_FAST_DEBUG=
4847

4948
#*** Default timeout for wait actions
5049
#WAIT_TIMEOUT=10

src/Magento/FunctionalTestingFramework/Config/MftfApplicationConfig.php

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class MftfApplicationConfig
1414
const UNIT_TEST_PHASE = "testing";
1515
const MFTF_PHASES = [self::GENERATION_PHASE, self::EXECUTION_PHASE, self::UNIT_TEST_PHASE];
1616

17+
const DEFAULT_DEBUG_MODE = "default";
18+
const PER_FILE_DEBUG_MODE = "perFile";
19+
const DISABLE_DEBUG_MODE = "ignore";
20+
const MFTF_DEBUG_MODES = [self::DEFAULT_DEBUG_MODE, self::PER_FILE_DEBUG_MODE, self::DISABLE_DEBUG_MODE];
21+
1722
/**
1823
* Determines whether the user has specified a force option for generation
1924
*
@@ -36,18 +41,11 @@ class MftfApplicationConfig
3641
private $verboseEnabled;
3742

3843
/**
39-
* Determines whether the user would like to execute mftf in a 'per file' debug mode
44+
* String which identifies the current debug mode of mftf execution
4045
*
41-
* @var boolean
42-
*/
43-
private $debugEnabled;
44-
45-
/**
46-
* Determines whether the user would like to execute mftf in a 'merged file' debug mode
47-
*
48-
* @var boolean
46+
* @var string
4947
*/
50-
private $fastDebugEnabled;
48+
private $debug;
5149

5250
/**
5351
* MftfApplicationConfig Singelton Instance
@@ -60,18 +58,16 @@ class MftfApplicationConfig
6058
* MftfApplicationConfig constructor.
6159
*
6260
* @param boolean $forceGenerate
63-
* @param string $phase
61+
* @param string $phase
6462
* @param boolean $verboseEnabled
65-
* @param boolean $debugEnabled
66-
* @param null $fastDebugEnabled
63+
* @param boolean $debug
6764
* @throws TestFrameworkException
6865
*/
6966
private function __construct(
7067
$forceGenerate = false,
7168
$phase = self::EXECUTION_PHASE,
7269
$verboseEnabled = null,
73-
$debugEnabled = null,
74-
$fastDebugEnabled = null
70+
$debug = null
7571
) {
7672
$this->forceGenerate = $forceGenerate;
7773

@@ -81,8 +77,7 @@ private function __construct(
8177

8278
$this->phase = $phase;
8379
$this->verboseEnabled = $verboseEnabled;
84-
$this->debugEnabled = $debugEnabled;
85-
$this->fastDebugEnabled = $fastDebugEnabled;
80+
$this->debug = $debug;
8681
}
8782

8883
/**
@@ -92,15 +87,14 @@ private function __construct(
9287
* @param boolean $forceGenerate
9388
* @param string $phase
9489
* @param boolean $verboseEnabled
95-
* @param boolean $debugEnabled
96-
* * @param boolean $fastDebugEnabled
90+
* @param string $debug
9791
* @return void
9892
*/
99-
public static function create($forceGenerate, $phase, $verboseEnabled, $debugEnabled, $fastDebugEnabled)
93+
public static function create($forceGenerate, $phase, $verboseEnabled, $debug)
10094
{
10195
if (self::$MFTF_APPLICATION_CONTEXT == null) {
10296
self::$MFTF_APPLICATION_CONTEXT =
103-
new MftfApplicationConfig($forceGenerate, $phase, $verboseEnabled, $debugEnabled, $fastDebugEnabled);
97+
new MftfApplicationConfig($forceGenerate, $phase, $verboseEnabled, $debug);
10498
}
10599
}
106100

@@ -139,29 +133,17 @@ public function forceGenerateEnabled()
139133
*/
140134
public function verboseEnabled()
141135
{
142-
return $this->verboseEnabled ?? (strcasecmp(getenv('MFTF_DEBUG'),'true') == 0);
136+
return $this->verboseEnabled ?? getenv('MFTF_DEBUG');
143137
}
144138

145139
/**
146-
* Returns a boolean indicating whether the user has indicated a debug run, which will run lengthy validation
147-
* with some extra error messaging to be run
140+
* Returns a string which indicates the debug mode of mftf execution.
148141
*
149-
* @return boolean
150-
*/
151-
public function debugEnabled()
152-
{
153-
return $this->debugEnabled ?? (strcasecmp(getenv('MFTF_DEBUG'),'true') == 0);
154-
}
155-
156-
/**
157-
* Returns a boolean indicating whether the user has indicated a fast debug run, which will run lengthy validation
158-
* on merged file instead of 'per file' with some extra error messaging to be run
159-
*
160-
* @return boolean
142+
* @return string
161143
*/
162-
public function fastDebugEnabled()
144+
public function getDebugMode()
163145
{
164-
return $this->fastDebugEnabled ?? (strcasecmp(getenv('MFTF_FAST_DEBUG'),'true') == 0);
146+
return $this->debug ?? getenv('MFTF_DEBUG');
165147
}
166148

167149
/**

src/Magento/FunctionalTestingFramework/Config/Reader/Filesystem.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ protected function readFiles($fileList)
157157
} else {
158158
$configMerger->merge($content);
159159
}
160-
if (MftfApplicationConfig::getConfig()->debugEnabled()) {
160+
if (MftfApplicationConfig::getConfig()->getDebugMode() == MftfApplicationConfig::PER_FILE_DEBUG_MODE) {
161161
$this->validateSchema($configMerger, $fileList->getFilename());
162162
}
163163
} catch (\Magento\FunctionalTestingFramework\Config\Dom\ValidationException $e) {
@@ -232,12 +232,13 @@ protected function validateSchema($configMerger, $filename = null)
232232
$errors = [];
233233
if ($configMerger && !$configMerger->validate($this->schemaFile, $errors)) {
234234
foreach ($errors as $error){
235-
LoggingUtil::getInstance()->getLogger(Filesystem::class)->buildFailure(
236-
"XSD schema error ",
237-
[ "file"=> $filename ? $filename: ":mergedFile:", "error" => $error]
235+
$error = str_replace("\n", "", $error);
236+
LoggingUtil::getInstance()->getLogger(Filesystem::class)->criticalFailure(
237+
"Schema validation error. ",
238+
($filename ? [ "file"=> $filename, "error" => $error]: ["error" => $error])
238239
);
239240
}
240-
throw new \Exception("Error: XSD schema issues found in file(s) " . $filename . "\n");
241+
throw new \Exception("Error: schema validation errors found in xml file(s) " . $filename . "\n");
241242
}
242243
}
243244
}

src/Magento/FunctionalTestingFramework/Config/Reader/MftfFilesystem.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function readFiles($fileList)
2424
$exceptionCollector = new ExceptionCollector();
2525
/** @var \Magento\FunctionalTestingFramework\Test\Config\Dom $configMerger */
2626
$configMerger = null;
27+
$debugMode = MftfApplicationConfig::getConfig()->getDebugMode();
2728
foreach ($fileList as $key => $content) {
2829
//check if file is empty and continue to next if it is
2930
if (!parent::verifyFileEmpty($content, $fileList->getFilename())) {
@@ -40,7 +41,9 @@ public function readFiles($fileList)
4041
} else {
4142
$configMerger->merge($content, $fileList->getFilename(), $exceptionCollector);
4243
}
43-
if (MftfApplicationConfig::getConfig()->debugEnabled()) {
44+
// per file debug mode - run per file validation for generate:tests -d
45+
if (!in_array($debugMode, MftfApplicationConfig::MFTF_DEBUG_MODES) ||
46+
$debugMode == MftfApplicationConfig::PER_FILE_DEBUG_MODE) {
4447
$this->validateSchema($configMerger, $fileList->getFilename());
4548
}
4649
} catch (\Magento\FunctionalTestingFramework\Config\Dom\ValidationException $e) {
@@ -51,8 +54,9 @@ public function readFiles($fileList)
5154
if ($fileList->valid()) {
5255
$this->validateSchema($configMerger, $fileList->getFilename());
5356
}
54-
if (MftfApplicationConfig::getConfig()->fastDebugEnabled() &&
55-
!MftfApplicationConfig::getConfig()->debugEnabled()) {
57+
58+
// default debug mode - run validation on merged file for generate:tests
59+
if ($debugMode == MftfApplicationConfig::DEFAULT_DEBUG_MODE) {
5660
$this->validateSchema($configMerger);
5761
}
5862

src/Magento/FunctionalTestingFramework/Console/GenerateDocsCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6767
$force,
6868
MftfApplicationConfig::GENERATION_PHASE,
6969
false,
70-
false,
71-
false
70+
MftfApplicationConfig::DISABLE_DEBUG_MODE
7271
);
7372

7473
$allActionGroups = ActionGroupObjectHandler::getInstance()->getAllObjects();

src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class GenerateTestsCommand extends BaseGenerateCommand
2929
protected function configure()
3030
{
3131
$this->setName('generate:tests')
32-
->setDescription('This command generates all test files and suites based on xml declarations')
32+
->setDescription('This command runs validation and generates all test files and suites based on xml declarations')
3333
->addArgument(
3434
'name',
3535
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
@@ -54,13 +54,9 @@ protected function configure()
5454
)->addOption(
5555
'debug',
5656
'd',
57-
InputOption::VALUE_NONE,
58-
'run extra validation per file when generating tests'
59-
)->addOption(
60-
'fastdebug',
61-
'a',
62-
InputOption::VALUE_NONE,
63-
'run extra validation on merged files when generating tests'
57+
InputOption::VALUE_OPTIONAL,
58+
'run per file validation while running tests. Use option \'ignore\' to skip debugging',
59+
'default'
6460
);
6561

6662
parent::configure();
@@ -83,8 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8379
$json = $input->getOption('tests');
8480
$force = $input->getOption('force');
8581
$time = $input->getOption('time') * 60 * 1000; // convert from minutes to milliseconds
86-
$debug = $input->getOption('debug');
87-
$fastDebug = $input->getOption('fastdebug');
82+
$debug = $input->getOption('debug')?? MftfApplicationConfig::PER_FILE_DEBUG_MODE; //set to per file debug as default
8883
$remove = $input->getOption('remove');
8984
$verbose = $output->isVerbose();
9085

@@ -100,10 +95,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
10095

10196
// Remove previous GENERATED_DIR if --remove option is used
10297
if ($remove) {
103-
$this->removeGeneratedDirectory($output, $verbose || $debug || $fastDebug);
98+
$this->removeGeneratedDirectory($output, $verbose ||
99+
($debug !== MftfApplicationConfig::DISABLE_DEBUG_MODE));
104100
}
105101

106-
$testConfiguration = $this->createTestConfiguration($json, $tests, $force, $debug, $fastDebug, $verbose);
102+
$testConfiguration = $this->createTestConfiguration($json, $tests, $force, $debug, $verbose);
107103

108104
// create our manifest file here
109105
$testManifest = TestManifestFactory::makeManifest($config, $testConfiguration['suites']);
@@ -129,22 +125,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
129125
* @param string $json
130126
* @param array $tests
131127
* @param boolean $force
132-
* @param boolean $debug
133-
* @param boolean $fastDebug
128+
* @param string $debug
134129
* @param boolean $verbose
135130
* @return array
136131
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
137132
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
138133
*/
139-
private function createTestConfiguration($json, array $tests, bool $force, bool $debug, bool $fastDebug, bool $verbose)
134+
private function createTestConfiguration($json, array $tests, bool $force, string $debug, bool $verbose)
140135
{
141136
// set our application configuration so we can references the user options in our framework
142137
MftfApplicationConfig::create(
143138
$force,
144139
MftfApplicationConfig::GENERATION_PHASE,
145140
$verbose,
146-
$debug,
147-
$fastDebug
141+
$debug
148142
);
149143

150144
$testConfiguration = [];

src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\FunctionalTestingFramework\Console;
99

10+
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
1011
use Symfony\Component\Console\Input\ArrayInput;
1112
use Symfony\Component\Console\Input\InputArgument;
1213
use Symfony\Component\Console\Input\InputInterface;
@@ -73,7 +74,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7374
'suites' => null
7475
]),
7576
'--force' => $force,
76-
'--remove' => $remove
77+
'--remove' => $remove,
78+
'--debug' => MftfApplicationConfig::DISABLE_DEBUG_MODE
7779
];
7880
$command->run(new ArrayInput($args), $output);
7981
}

src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7272
false,
7373
MftfApplicationConfig::GENERATION_PHASE,
7474
false,
75-
false,
76-
false
75+
MftfApplicationConfig::DISABLE_DEBUG_MODE
7776
);
7877

7978
$testConfiguration = $this->getFailedTestList();

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7777
$force,
7878
MftfApplicationConfig::GENERATION_PHASE,
7979
false,
80-
false,
81-
false
80+
MftfApplicationConfig::DISABLE_DEBUG_MODE
8281
);
8382

8483
if (!$skipGeneration) {

src/Magento/FunctionalTestingFramework/StaticCheck/TestDependencyCheck.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ public function execute(InputInterface $input)
7575
true,
7676
MftfApplicationConfig::UNIT_TEST_PHASE,
7777
false,
78-
false,
79-
false
78+
MftfApplicationConfig::DISABLE_DEBUG_MODE
8079
);
8180

8281
ModuleResolver::getInstance()->getModulesPath();

src/Magento/FunctionalTestingFramework/Test/etc/Actions/commonAttributes.xsd

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@
3131
</xs:annotation>
3232
</xs:attribute>
3333

34-
<xs:attribute type="xs:boolean" name="skipReadiness">
35-
<xs:annotation>
36-
<xs:documentation>
37-
Flag for skipping readiness check
38-
</xs:documentation>
39-
</xs:annotation>
40-
</xs:attribute>
4134
</xs:attributeGroup>
4235

4336
<xs:attribute type="xs:string" name="userInput" id="userInput">
@@ -87,4 +80,5 @@
8780
</xs:documentation>
8881
</xs:annotation>
8982
</xs:attribute>
83+
9084
</xs:schema>

src/Magento/FunctionalTestingFramework/Test/etc/mergedTestSchema.xsd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,13 @@
129129
</xs:documentation>
130130
</xs:annotation>
131131
</xs:attribute>
132+
<xs:attribute type="xs:boolean" name="skipReadiness" use="prohibited">
133+
<xs:annotation>
134+
<xs:documentation>
135+
Flag for skipping readiness check.
136+
</xs:documentation>
137+
</xs:annotation>
138+
</xs:attribute>
132139
<xs:attributeGroup ref="commonActionAttributes"/>
133-
<xs:attribute type="xs:boolean" name="skipReadiness" use="prohibited"/>
134140
</xs:complexType>
135141
</xs:schema>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public function deprecation($message, array $context = [])
3636
* @param array $context The log context.
3737
* @return void
3838
*/
39-
public function buildFailure($message, array $context = [])
39+
public function criticalFailure($message, array $context = [])
4040
{
41-
$message = "BUILD FAILURE: " . $message;
41+
$message = "CRITICAL FAILURE: " . $message;
4242
// Suppress print during unit testing
4343
if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE) {
4444
print ($message . json_encode($context) . "\n");

0 commit comments

Comments
 (0)