Skip to content

Commit 53f6bae

Browse files
committed
MQE-1541: Add option to generate:tests for XSD validation on 'merged files'
1 parent 9359af2 commit 53f6bae

File tree

10 files changed

+74
-14
lines changed

10 files changed

+74
-14
lines changed

dev/tests/_bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
true,
3333
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::UNIT_TEST_PHASE,
3434
true,
35+
false,
3536
false
3637
);
3738

src/Magento/FunctionalTestingFramework/Config/MftfApplicationConfig.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,19 @@ class MftfApplicationConfig
3636
private $verboseEnabled;
3737

3838
/**
39-
* Determines whether the user would like to execute mftf in a verbose run.
39+
* Determines whether the user would like to execute mftf in a 'per file' debug mode
4040
*
4141
* @var boolean
4242
*/
4343
private $debugEnabled;
4444

45+
/**
46+
* Determines whether the user would like to execute mftf in a 'merged file' debug mode
47+
*
48+
* @var boolean
49+
*/
50+
private $fastDebugEnabled;
51+
4552
/**
4653
* MftfApplicationConfig Singelton Instance
4754
*
@@ -53,16 +60,18 @@ class MftfApplicationConfig
5360
* MftfApplicationConfig constructor.
5461
*
5562
* @param boolean $forceGenerate
56-
* @param string $phase
63+
* @param string $phase
5764
* @param boolean $verboseEnabled
5865
* @param boolean $debugEnabled
66+
* @param null $fastDebugEnabled
5967
* @throws TestFrameworkException
6068
*/
6169
private function __construct(
6270
$forceGenerate = false,
6371
$phase = self::EXECUTION_PHASE,
6472
$verboseEnabled = null,
65-
$debugEnabled = null
73+
$debugEnabled = null,
74+
$fastDebugEnabled = null
6675
) {
6776
$this->forceGenerate = $forceGenerate;
6877

@@ -73,6 +82,7 @@ private function __construct(
7382
$this->phase = $phase;
7483
$this->verboseEnabled = $verboseEnabled;
7584
$this->debugEnabled = $debugEnabled;
85+
$this->fastDebugEnabled = $fastDebugEnabled;
7686
}
7787

7888
/**
@@ -83,13 +93,14 @@ private function __construct(
8393
* @param string $phase
8494
* @param boolean $verboseEnabled
8595
* @param boolean $debugEnabled
96+
* * @param boolean $fastDebugEnabled
8697
* @return void
8798
*/
88-
public static function create($forceGenerate, $phase, $verboseEnabled, $debugEnabled)
99+
public static function create($forceGenerate, $phase, $verboseEnabled, $debugEnabled, $fastDebugEnabled)
89100
{
90101
if (self::$MFTF_APPLICATION_CONTEXT == null) {
91102
self::$MFTF_APPLICATION_CONTEXT =
92-
new MftfApplicationConfig($forceGenerate, $phase, $verboseEnabled, $debugEnabled);
103+
new MftfApplicationConfig($forceGenerate, $phase, $verboseEnabled, $debugEnabled, $fastDebugEnabled);
93104
}
94105
}
95106

@@ -128,7 +139,7 @@ public function forceGenerateEnabled()
128139
*/
129140
public function verboseEnabled()
130141
{
131-
return $this->verboseEnabled ?? getenv('MFTF_DEBUG');
142+
return $this->verboseEnabled ?? (strcasecmp(getenv('MFTF_DEBUG'),'true') == 0);
132143
}
133144

134145
/**
@@ -139,7 +150,18 @@ public function verboseEnabled()
139150
*/
140151
public function debugEnabled()
141152
{
142-
return $this->debugEnabled ?? getenv('MFTF_DEBUG');
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 lengthy validation
158+
* on merged file instead of 'per file' with some extra error messaging to be run
159+
*
160+
* @return boolean
161+
*/
162+
public function fastDebugEnabled()
163+
{
164+
return $this->fastDebugEnabled ?? (strcasecmp(getenv('MFTF_FAST_DEBUG'),'true') == 0);
143165
}
144166

145167
/**

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ protected function validateSchema($configMerger, $filename = null)
232232
$errors = [];
233233
if ($configMerger && !$configMerger->validate($this->schemaFile, $errors)) {
234234
$message = $filename ? $filename . PHP_EOL . "Invalid Document \n" : PHP_EOL . "Invalid Document \n";
235+
foreach ($errors as $error ){
236+
LoggingUtil::getInstance()->getLogger(Filesystem::class)->buildFailure(
237+
"XSD schema validation error",
238+
[ "file"=> $filename ? $filename: ":mergedFile:", "error" => $error]
239+
);
240+
}
235241
throw new \Exception($message . implode("\n", $errors));
236242
}
237243
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public function readFiles($fileList)
5151
if ($fileList->valid()) {
5252
$this->validateSchema($configMerger, $fileList->getFilename());
5353
}
54+
if (MftfApplicationConfig::getConfig()->fastDebugEnabled()) {
55+
$this->validateSchema($configMerger);
56+
}
5457

5558
$output = [];
5659
if ($configMerger) {

src/Magento/FunctionalTestingFramework/Console/GenerateDocsCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6767
$force,
6868
MftfApplicationConfig::GENERATION_PHASE,
6969
false,
70+
false,
7071
false
7172
);
7273

src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ protected function configure()
5555
'debug',
5656
'd',
5757
InputOption::VALUE_NONE,
58-
'run extra validation when generating tests'
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'
5964
);
6065

6166
parent::configure();
@@ -79,8 +84,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
7984
$force = $input->getOption('force');
8085
$time = $input->getOption('time') * 60 * 1000; // convert from minutes to milliseconds
8186
$debug = $input->getOption('debug');
87+
$fastDebug = $input->getOption('fastdebug');
8288
$remove = $input->getOption('remove');
83-
8489
$verbose = $output->isVerbose();
8590

8691
if ($json !== null && !json_decode($json)) {
@@ -95,10 +100,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
95100

96101
// Remove previous GENERATED_DIR if --remove option is used
97102
if ($remove) {
98-
$this->removeGeneratedDirectory($output, $verbose || $debug);
103+
$this->removeGeneratedDirectory($output, $verbose || $debug || $fastDebug);
99104
}
100105

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

103108
// create our manifest file here
104109
$testManifest = TestManifestFactory::makeManifest($config, $testConfiguration['suites']);
@@ -125,19 +130,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
125130
* @param array $tests
126131
* @param boolean $force
127132
* @param boolean $debug
133+
* @param boolean $fastDebug
128134
* @param boolean $verbose
129135
* @return array
130136
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
131137
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
132138
*/
133-
private function createTestConfiguration($json, array $tests, bool $force, bool $debug, bool $verbose)
139+
private function createTestConfiguration($json, array $tests, bool $force, bool $debug, bool $fastDebug, bool $verbose)
134140
{
135141
// set our application configuration so we can references the user options in our framework
136142
MftfApplicationConfig::create(
137143
$force,
138144
MftfApplicationConfig::GENERATION_PHASE,
139145
$verbose,
140-
$debug
146+
$debug,
147+
$fastDebug
141148
);
142149

143150
$testConfiguration = [];

src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7272
false,
7373
MftfApplicationConfig::GENERATION_PHASE,
7474
false,
75+
false,
7576
false
7677
);
7778

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7777
$force,
7878
MftfApplicationConfig::GENERATION_PHASE,
7979
false,
80+
false,
8081
false
8182
);
8283

src/Magento/FunctionalTestingFramework/StaticCheck/TestDependencyCheck.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function execute(InputInterface $input)
7575
true,
7676
MftfApplicationConfig::UNIT_TEST_PHASE,
7777
false,
78+
false,
7879
false
7980
);
8081

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class MftfLogger extends Logger
1414
{
1515
/**
16-
* Prints a deprecation warning, as well as adding a log at the WARNING level.
16+
* Prints a deprecation warning, as well as adds a log at the WARNING level.
1717
*
1818
* @param string $message The log message.
1919
* @param array $context The log context.
@@ -28,4 +28,21 @@ public function deprecation($message, array $context = [])
2828
}
2929
parent::warning($message, $context);
3030
}
31+
32+
/**
33+
* Prints a critical failure, as well as adds a log at the CRITICAL level.
34+
*
35+
* @param string $message The log message.
36+
* @param array $context The log context.
37+
* @return void
38+
*/
39+
public function buildFailure($message, array $context = [])
40+
{
41+
$message = "BUILD FAILURE: " . $message;
42+
// Suppress print during unit testing
43+
if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE) {
44+
print ($message . json_encode($context) . "\n");
45+
}
46+
parent::critical($message, $context);
47+
}
3148
}

0 commit comments

Comments
 (0)