Skip to content

Commit 489ca5e

Browse files
committed
MQE-1541: Add option to generate:tests for XSD validation on 'merged files'
1 parent 3f39f44 commit 489ca5e

File tree

11 files changed

+41
-31
lines changed

11 files changed

+41
-31
lines changed

dev/tests/_bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
true,
3333
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::UNIT_TEST_PHASE,
3434
true,
35-
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::DISABLE_DEBUG_MODE
35+
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::MODE_PRODUCTION
3636
);
3737

3838
// Load needed framework env params

dev/tests/verification/Tests/SchemaValidationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SchemaValidationTest extends MftfTestCase
1919
*/
2020
public function testInvalidTestSchema()
2121
{
22-
AspectMock::double(MftfApplicationConfig::class, ['getDebugMode' => MftfApplicationConfig::DEVELOPER_MODE]);
22+
AspectMock::double(MftfApplicationConfig::class, ['getMode' => MftfApplicationConfig::MODE_DEVELOPER]);
2323
$testFile = ['testFile.xml' => "<tests><test name='testName'><annotations>a</annotations></test></tests>"];
2424
$expectedError = TESTS_MODULE_PATH .
2525
DIRECTORY_SEPARATOR .

src/Magento/FunctionalTestingFramework/Config/MftfApplicationConfig.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ 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 DEVELOPER_MODE = "developer";
19-
const DISABLE_DEBUG_MODE = "ignore";
20-
const MFTF_DEBUG_MODES = [self::DEFAULT_DEBUG_MODE, self::DEVELOPER_MODE, self::DISABLE_DEBUG_MODE];
17+
/**
18+
* Mftf debug modes
19+
*/
20+
const MODE_DEFAULT = "default";
21+
const MODE_DEVELOPER = "developer";
22+
const MODE_PRODUCTION = "off";
23+
const MFTF_DEBUG_MODES = [self::MODE_DEFAULT, self::MODE_DEVELOPER, self::MODE_PRODUCTION];
2124

2225
/**
2326
* Determines whether the user has specified a force option for generation
@@ -45,7 +48,7 @@ class MftfApplicationConfig
4548
*
4649
* @var string
4750
*/
48-
private $debug;
51+
private $mode;
4952

5053
/**
5154
* MftfApplicationConfig Singelton Instance
@@ -60,14 +63,14 @@ class MftfApplicationConfig
6063
* @param boolean $forceGenerate
6164
* @param string $phase
6265
* @param boolean $verboseEnabled
63-
* @param boolean $debug
66+
* @param string $mode
6467
* @throws TestFrameworkException
6568
*/
6669
private function __construct(
6770
$forceGenerate = false,
6871
$phase = self::EXECUTION_PHASE,
6972
$verboseEnabled = null,
70-
$debug = null
73+
$mode = self::MODE_PRODUCTION
7174
) {
7275
$this->forceGenerate = $forceGenerate;
7376

@@ -77,7 +80,15 @@ private function __construct(
7780

7881
$this->phase = $phase;
7982
$this->verboseEnabled = $verboseEnabled;
80-
$this->debug = $debug;
83+
switch ($mode) {
84+
case self::MODE_DEVELOPER:
85+
case self::MODE_DEFAULT:
86+
case self::MODE_PRODUCTION:
87+
$this->mode = $mode;
88+
break;
89+
default:
90+
$this->mode = self::MODE_DEVELOPER;
91+
}
8192
}
8293

8394
/**
@@ -87,14 +98,14 @@ private function __construct(
8798
* @param boolean $forceGenerate
8899
* @param string $phase
89100
* @param boolean $verboseEnabled
90-
* @param string $debug
101+
* @param string $mode
91102
* @return void
92103
*/
93-
public static function create($forceGenerate, $phase, $verboseEnabled, $debug)
104+
public static function create($forceGenerate, $phase, $verboseEnabled, $mode)
94105
{
95106
if (self::$MFTF_APPLICATION_CONTEXT == null) {
96107
self::$MFTF_APPLICATION_CONTEXT =
97-
new MftfApplicationConfig($forceGenerate, $phase, $verboseEnabled, $debug);
108+
new MftfApplicationConfig($forceGenerate, $phase, $verboseEnabled, $mode);
98109
}
99110
}
100111

@@ -141,9 +152,9 @@ public function verboseEnabled()
141152
*
142153
* @return string
143154
*/
144-
public function getDebugMode()
155+
public function getMode()
145156
{
146-
return $this->debug ?? getenv('MFTF_DEBUG');
157+
return $this->mode ?? getenv('MFTF_DEBUG');
147158
}
148159

149160
/**

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

Lines changed: 2 additions & 2 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()->getDebugMode() === MftfApplicationConfig::DEVELOPER_MODE) {
160+
if (MftfApplicationConfig::getConfig()->getMode() === MftfApplicationConfig::MODE_DEVELOPER) {
161161
$this->validateSchema($configMerger, $fileList->getFilename());
162162
}
163163
} catch (\Magento\FunctionalTestingFramework\Config\Dom\ValidationException $e) {
@@ -235,7 +235,7 @@ protected function validateSchema($configMerger, $filename = null)
235235
$error = str_replace(PHP_EOL, "", $error);
236236
LoggingUtil::getInstance()->getLogger(Filesystem::class)->criticalFailure(
237237
"Schema validation error ",
238-
($filename ? [ "file"=> $filename, "error" => $error]: ["error" => $error])
238+
($filename ? [ "file"=> $filename, "error" => $error]: ["schema" => $this->schemaFile, "error" => $error])
239239
);
240240
}
241241
throw new \Exception("Schema validation errors found in xml file(s)" . $filename);

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +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();
27+
$mode = MftfApplicationConfig::getConfig()->getMode();
2828
foreach ($fileList as $key => $content) {
2929
//check if file is empty and continue to next if it is
3030
if (!parent::verifyFileEmpty($content, $fileList->getFilename())) {
@@ -42,8 +42,7 @@ public function readFiles($fileList)
4242
$configMerger->merge($content, $fileList->getFilename(), $exceptionCollector);
4343
}
4444
// run per file validation with generate:tests -d
45-
if (!in_array($debugMode, MftfApplicationConfig::MFTF_DEBUG_MODES) ||
46-
$debugMode === MftfApplicationConfig::DEVELOPER_MODE) {
45+
if ($mode == MftfApplicationConfig::MODE_DEVELOPER) {
4746
$this->validateSchema($configMerger, $fileList->getFilename());
4847
}
4948
} catch (\Magento\FunctionalTestingFramework\Config\Dom\ValidationException $e) {
@@ -53,7 +52,7 @@ public function readFiles($fileList)
5352
$exceptionCollector->throwException();
5453

5554
//run validation on merged file with generate:tests
56-
if ($debugMode === MftfApplicationConfig::DEFAULT_DEBUG_MODE) {
55+
if ($mode == MftfApplicationConfig::MODE_DEFAULT) {
5756
$this->validateSchema($configMerger);
5857
}
5958

src/Magento/FunctionalTestingFramework/Console/GenerateDocsCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6767
$force,
6868
MftfApplicationConfig::GENERATION_PHASE,
6969
false,
70-
MftfApplicationConfig::DISABLE_DEBUG_MODE
70+
MftfApplicationConfig::MODE_PRODUCTION
7171
);
7272

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

src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected function configure()
5555
'debug',
5656
'd',
5757
InputOption::VALUE_OPTIONAL,
58-
'Run extra validation when generating tests. Use option \'ignore\' to skip debugging --
58+
'Run extra validation when generating tests. Use option \'off\' to turn off debugging --
5959
added for backward compatibility, will be removed in the next MAJOR release',
6060
'default'
6161
);
@@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8080
$json = $input->getOption('tests');
8181
$force = $input->getOption('force');
8282
$time = $input->getOption('time') * 60 * 1000; // convert from minutes to milliseconds
83-
$debug = $input->getOption('debug')?? MftfApplicationConfig::DEVELOPER_MODE;
83+
$mode = $input->getOption('debug');
8484
$remove = $input->getOption('remove');
8585
$verbose = $output->isVerbose();
8686

@@ -97,10 +97,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
9797
// Remove previous GENERATED_DIR if --remove option is used
9898
if ($remove) {
9999
$this->removeGeneratedDirectory($output, $verbose ||
100-
($debug !== MftfApplicationConfig::DISABLE_DEBUG_MODE));
100+
($mode !== MftfApplicationConfig::MODE_PRODUCTION));
101101
}
102102

103-
$testConfiguration = $this->createTestConfiguration($json, $tests, $force, $debug, $verbose);
103+
$testConfiguration = $this->createTestConfiguration($json, $tests, $force, $mode, $verbose);
104104

105105
// create our manifest file here
106106
$testManifest = TestManifestFactory::makeManifest($config, $testConfiguration['suites']);
@@ -132,7 +132,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
132132
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
133133
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
134134
*/
135-
private function createTestConfiguration($json, array $tests, bool $force, string $debug, bool $verbose)
135+
private function createTestConfiguration($json, array $tests, bool $force, $debug, bool $verbose)
136136
{
137137
// set our application configuration so we can references the user options in our framework
138138
MftfApplicationConfig::create(

src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7575
]),
7676
'--force' => $force,
7777
'--remove' => $remove,
78-
'--debug' => MftfApplicationConfig::DISABLE_DEBUG_MODE
78+
'--debug' => MftfApplicationConfig::MODE_PRODUCTION
7979
];
8080
$command->run(new ArrayInput($args), $output);
8181
}

src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7272
false,
7373
MftfApplicationConfig::GENERATION_PHASE,
7474
false,
75-
MftfApplicationConfig::DISABLE_DEBUG_MODE
75+
MftfApplicationConfig::MODE_PRODUCTION
7676
);
7777

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

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7777
$force,
7878
MftfApplicationConfig::GENERATION_PHASE,
7979
false,
80-
MftfApplicationConfig::DISABLE_DEBUG_MODE
80+
MftfApplicationConfig::MODE_PRODUCTION
8181
);
8282

8383
if (!$skipGeneration) {

0 commit comments

Comments
 (0)