Skip to content

Commit 596efbe

Browse files
committed
MQE-1017: Better Error Messaging When Non-Whitespace Characters Are
Outside XML Elements - Adding debug flag to generate tests - Adding individual file validation for schema when debug is on
1 parent aff7f67 commit 596efbe

File tree

5 files changed

+56
-9
lines changed

5 files changed

+56
-9
lines changed

dev/tests/_bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::create(
3232
true,
3333
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::GENERATION_PHASE,
34+
true,
3435
true
3536
);
3637

src/Magento/FunctionalTestingFramework/Config/MftfApplicationConfig.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ class MftfApplicationConfig
3434
*/
3535
private $verboseEnabled;
3636

37+
/**
38+
* Determines whether the user would like to execute mftf in a verbose run.
39+
*
40+
* @var bool
41+
*/
42+
private $debugEnabled;
43+
3744
/**
3845
* MftfApplicationConfig Singelton Instance
3946
*
@@ -47,10 +54,15 @@ class MftfApplicationConfig
4754
* @param bool $forceGenerate
4855
* @param string $phase
4956
* @param bool $verboseEnabled
57+
* @param bool $debugEnabled
5058
* @throws TestFrameworkException
5159
*/
52-
private function __construct($forceGenerate = false, $phase = self::EXECUTION_PHASE, $verboseEnabled = null)
53-
{
60+
private function __construct(
61+
$forceGenerate = false,
62+
$phase = self::EXECUTION_PHASE,
63+
$verboseEnabled = null,
64+
$debugEnabled = null
65+
) {
5466
$this->forceGenerate = $forceGenerate;
5567

5668
if (!in_array($phase, self::MFTF_PHASES)) {
@@ -59,6 +71,7 @@ private function __construct($forceGenerate = false, $phase = self::EXECUTION_PH
5971

6072
$this->phase = $phase;
6173
$this->verboseEnabled = $verboseEnabled;
74+
$this->debugEnabled = $debugEnabled;
6275
}
6376

6477
/**
@@ -68,12 +81,14 @@ private function __construct($forceGenerate = false, $phase = self::EXECUTION_PH
6881
* @param bool $forceGenerate
6982
* @param string $phase
7083
* @param bool $verboseEnabled
84+
* @param bool $debugEnabled
7185
* @return void
7286
*/
73-
public static function create($forceGenerate, $phase, $verboseEnabled)
87+
public static function create($forceGenerate, $phase, $verboseEnabled, $debugEnabled)
7488
{
7589
if (self::$MFTF_APPLICATION_CONTEXT == null) {
76-
self::$MFTF_APPLICATION_CONTEXT = new MftfApplicationConfig($forceGenerate, $phase, $verboseEnabled);
90+
self::$MFTF_APPLICATION_CONTEXT =
91+
new MftfApplicationConfig($forceGenerate, $phase, $verboseEnabled, $debugEnabled);
7792
}
7893
}
7994

@@ -115,6 +130,17 @@ public function verboseEnabled()
115130
return $this->verboseEnabled ?? getenv('MFTF_DEBUG');
116131
}
117132

133+
/**
134+
* Returns a boolean indicating whether the user has indicated a debug run, which will lengthy validation
135+
* with some extra error messaging to be run
136+
*
137+
* @return bool
138+
*/
139+
public function debugEnabled()
140+
{
141+
return $this->debugEnabled ?? getenv('MFTF_DEBUG');
142+
}
143+
118144
/**
119145
* Returns a string which indicates the phase of mftf execution.
120146
*

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ protected function readFiles($fileList)
150150
} else {
151151
$configMerger->merge($content);
152152
}
153+
if ($this->validationState->isValidationRequired()) {
154+
$errors = [];
155+
if ($configMerger && !$configMerger->validate($this->schemaFile, $errors)) {
156+
$message = $fileList->getFilename() . PHP_EOL . "Invalid Document \n";
157+
throw new \Exception($message . implode("\n", $errors));
158+
}
159+
}
153160
} catch (\Magento\FunctionalTestingFramework\Config\Dom\ValidationException $e) {
154161
throw new \Exception("Invalid XML in file " . $fileList->getFilename() . ":\n" . $e->getMessage());
155162
}

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

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

77
namespace Magento\FunctionalTestingFramework\Config\Reader;
88

9+
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
910
use Magento\FunctionalTestingFramework\Exceptions\Collector\ExceptionCollector;
1011
use Magento\FunctionalTestingFramework\Util\Iterator\File;
1112

@@ -36,14 +37,22 @@ public function readFiles($fileList)
3637
} else {
3738
$configMerger->merge($content, $fileList->getFilename(), $exceptionCollector);
3839
}
40+
if (MftfApplicationConfig::getConfig()->debugEnabled()) {
41+
if ($this->validationState->isValidationRequired()) {
42+
if ($configMerger && !$configMerger->validate($this->schemaFile, $errors)) {
43+
$message = "Invalid Document: " . PHP_EOL . $fileList->getFilename() . PHP_EOL;
44+
throw new \Exception($message . implode("\n", $errors));
45+
}
46+
}
47+
}
3948
} catch (\Magento\FunctionalTestingFramework\Config\Dom\ValidationException $e) {
4049
throw new \Exception("Invalid XML in file " . $key . ":\n" . $e->getMessage());
4150
}
4251
}
4352
$exceptionCollector->throwException();
4453
if ($this->validationState->isValidationRequired()) {
4554
if ($configMerger && !$configMerger->validate($this->schemaFile, $errors)) {
46-
$message = "Invalid Document \n";
55+
$message = "Invalid Document: " . PHP_EOL;
4756
throw new \Exception($message . implode("\n", $errors));
4857
}
4958
}

src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ protected function configure()
3636
->addOption("config", 'c', InputOption::VALUE_REQUIRED, 'default, singleRun, or parallel', 'default')
3737
->addOption("force", 'f',InputOption::VALUE_NONE, 'force generation of tests regardless of Magento Instance Configuration')
3838
->addOption('lines', 'l', InputOption::VALUE_REQUIRED, 'Used in combination with a parallel configuration, determines desired group size', 500)
39-
->addOption('tests', 't', InputOption::VALUE_REQUIRED, 'A parameter accepting a JSON string used to determine the test configuration');
39+
->addOption('tests', 't', InputOption::VALUE_REQUIRED, 'A parameter accepting a JSON string used to determine the test configuration')
40+
->addOption('debug', 'd', InputOption::VALUE_NONE, 'run extra validation when generating tests');
4041
}
4142

4243
/**
@@ -54,14 +55,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
5455
$json = $input->getOption('tests');
5556
$force = $input->getOption('force');
5657
$lines = $input->getOption('lines');
58+
$debug = $input->getOption('debug');
5759
$verbose = $output->isVerbose();
5860

5961
if ($json !== null && !json_decode($json)) {
6062
// stop execution if we have failed to properly parse any json passed in by the user
6163
throw new TestFrameworkException("JSON could not be parsed: " . json_last_error_msg());
6264
}
6365

64-
$testConfiguration = $this->createTestConfiguration($json, $tests, $force, $verbose);
66+
$testConfiguration = $this->createTestConfiguration($json, $tests, $force, $debug, $verbose);
6567

6668
// create our manifest file here
6769
$testManifest = TestManifestFactory::makeManifest($config, $testConfiguration['suites']);
@@ -84,16 +86,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
8486
* @param string $json
8587
* @param array $tests
8688
* @param bool $force
89+
* @param bool $debug
8790
* @param bool $verbose
8891
* @return array
8992
*/
90-
private function createTestConfiguration($json, array $tests, bool $force, bool $verbose)
93+
private function createTestConfiguration($json, array $tests, bool $force, bool $debug, bool $verbose)
9194
{
9295
// set our application configuration so we can references the user options in our framework
9396
MftfApplicationConfig::create(
9497
$force,
9598
MftfApplicationConfig::GENERATION_PHASE,
96-
$verbose
99+
$verbose,
100+
$debug
97101
);
98102

99103
$testConfiguration = [];

0 commit comments

Comments
 (0)