Skip to content

Commit 6281e31

Browse files
authored
MQE-917: Eliminate usage of XSD relative paths
- New mftf command to generate URN (needed for MTF parity) - New UpgrateTestsCommand - Added call to above command in BuildProject if flag -u is set - UpgradeTestSchemaPaths script added to upgrade folder.
1 parent cd958a1 commit 6281e31

15 files changed

+444
-25
lines changed

bin/mftf

+17-14
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,30 @@ if (PHP_SAPI !== 'cli') {
1111
exit(1);
1212
}
1313

14-
$autoload_path = realpath(__DIR__ . '/../../../autoload.php');
15-
$test_bootstrap_path = realpath(__DIR__ . '/../dev/tests/functional/_bootstrap.php');
14+
$autoloadPath = realpath(__DIR__ . '/../../../autoload.php');
15+
$testBootstrapPath = realpath(__DIR__ . '/../dev/tests/functional/_bootstrap.php');
1616

17-
if (file_exists($autoload_path)) {
18-
require_once $autoload_path;
19-
} else {
20-
require_once $test_bootstrap_path;
17+
try {
18+
if (file_exists($autoloadPath)) {
19+
require_once $autoloadPath;
20+
} else {
21+
require_once $testBootstrapPath;
22+
}
23+
} catch (\Exception $e) {
24+
echo 'Autoload error: ' . $e->getMessage();
25+
exit(1);
2126
}
2227

2328

2429
try {
2530
$application = new Symfony\Component\Console\Application();
2631
$application->setName('Magento Functional Testing Framework CLI');
27-
$application->setVersion('1.0.0');
28-
$application->add(new Magento\FunctionalTestingFramework\Console\SetupEnvCommand());
29-
$application->add(new Magento\FunctionalTestingFramework\Console\CleanProjectCommand());
30-
$application->add(new Magento\FunctionalTestingFramework\Console\BuildProjectCommand());
31-
$application->add(new Magento\FunctionalTestingFramework\Console\GenerateSuiteCommand());
32-
$application->add(new Magento\FunctionalTestingFramework\Console\GenerateTestsCommand());
33-
$application->add(new Magento\FunctionalTestingFramework\Console\RunTestGroupCommand());
34-
$application->add(new Magento\FunctionalTestingFramework\Console\RunTestCommand());
32+
$application->setVersion('2.3.0');
33+
/** @var \Magento\FunctionalTestingFramework\Console\CommandListInterface $commandList */
34+
$commandList = new \Magento\FunctionalTestingFramework\Console\CommandList;
35+
foreach ($commandList->getCommands() as $command) {
36+
$application->add($command);
37+
}
3538
$application->run();
3639
} catch (\Exception $e) {
3740
while ($e) {

src/Magento/FunctionalTestingFramework/Console/BuildProjectCommand.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class BuildProjectCommand extends Command
3838
protected function configure()
3939
{
4040
$this->setName('build:project')
41-
->setDescription('Generate configuration files for the project. Build the Codeception project.');
41+
->setDescription('Generate configuration files for the project. Build the Codeception project.')
42+
->addOption("upgrade", 'u', InputOption::VALUE_NONE, 'upgrade existing MFTF tests according to last major release requiements');
4243
$this->envProcessor = new EnvProcessor(TESTS_BP . DIRECTORY_SEPARATOR . '.env');
4344
$env = $this->envProcessor->getEnv();
4445
foreach ($env as $key => $value) {
@@ -58,6 +59,10 @@ protected function configure()
5859
*/
5960
protected function execute(InputInterface $input, OutputInterface $output)
6061
{
62+
$resetCommand = new CleanProjectCommand();
63+
$resetOptions = new ArrayInput([]);
64+
$resetCommand->run($resetOptions, $output);
65+
6166
$this->generateConfigFiles($output);
6267

6368
$setupEnvCommand = new SetupEnvCommand();
@@ -87,6 +92,12 @@ function ($type, $buffer) use ($output) {
8792
}
8893
}
8994
);
95+
96+
if ($input->getOption('upgrade')) {
97+
$upgradeCommand = new UpgradeTestsCommand();
98+
$upgradeOptions = new ArrayInput(['path' => TESTS_MODULE_PATH]);
99+
$upgradeCommand->run($upgradeOptions, $output);
100+
}
90101
}
91102

92103
/**

src/Magento/FunctionalTestingFramework/Console/CleanProjectCommand.php

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\Console\Output\OutputInterface;
1515
use Symfony\Component\Filesystem\Filesystem;
1616
use Symfony\Component\Finder\Finder;
17-
use Symfony\Component\Finder\SplFileInfo;
1817

1918
class CleanProjectCommand extends Command
2019
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\FunctionalTestingFramework\Console;
10+
11+
/**
12+
* Class CommandList has a list of commands.
13+
* @codingStandardsIgnoreFile
14+
*/
15+
class CommandList implements CommandListInterface
16+
{
17+
/**
18+
* List of Commands
19+
* @var \Symfony\Component\Console\Command\Command[]
20+
*/
21+
private $commands;
22+
23+
/**
24+
* Constructor
25+
*
26+
* @param array $commands
27+
*/
28+
public function __construct(array $commands = [])
29+
{
30+
$this->commands = [
31+
'build:project' => new BuildProjectCommand(),
32+
'reset' => new CleanProjectCommand(),
33+
'generate:urn-catalog' => new GenerateDevUrnCommand(),
34+
'generate:suite' => new GenerateSuiteCommand(),
35+
'generate:tests' => new GenerateTestsCommand(),
36+
'run:test' => new RunTestCommand(),
37+
'run:group' => new RunTestGroupCommand(),
38+
'setup:env' => new SetupEnvCommand(),
39+
'upgrade:tests' => new UpgradeTestsCommand(),
40+
] + $commands;
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
public function getCommands()
47+
{
48+
return $this->commands;
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\FunctionalTestingFramework\Console;
7+
8+
/**
9+
* Contains a list of Console commands
10+
* @api
11+
*/
12+
interface CommandListInterface
13+
{
14+
/**
15+
* Gets list of command instances
16+
*
17+
* @return \Symfony\Component\Console\Command\Command[]
18+
*/
19+
public function getCommands();
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
// @codingStandardsIgnoreFile
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types = 1);
8+
9+
namespace Magento\FunctionalTestingFramework\Console;
10+
11+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
12+
use Symfony\Component\Console\Command\Command;
13+
use Symfony\Component\Console\Input\InputArgument;
14+
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
17+
class GenerateDevUrnCommand extends Command
18+
{
19+
/**
20+
* Configures the current command.
21+
*
22+
* @return void
23+
*/
24+
protected function configure()
25+
{
26+
$this->setName('generate:urn-catalog')
27+
->setDescription('This command generates an URN catalog to enable PHPStorm to recognize and highlight URNs.')
28+
->addArgument('path', InputArgument::REQUIRED, 'path to PHPStorm misc.xml file (typically located in [ProjectRoot]/.idea/misc.xml)');
29+
}
30+
31+
/**
32+
* Executes the current command.
33+
*
34+
* @param InputInterface $input
35+
* @param OutputInterface $output
36+
* @return void
37+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
38+
*/
39+
protected function execute(InputInterface $input, OutputInterface $output)
40+
{
41+
$miscXmlFilePath = $input->getArgument('path') . DIRECTORY_SEPARATOR . "misc.xml";
42+
$miscXmlFile = realpath($miscXmlFilePath);
43+
44+
if ($miscXmlFile === false) {
45+
$exceptionMessage = "misc.xml not found in given path '{$miscXmlFilePath}'";
46+
LoggingUtil::getInstance()->getLogger(GenerateDevUrnCommand::class)
47+
->error($exceptionMessage);
48+
throw new TestFrameworkException($exceptionMessage);
49+
}
50+
$dom = new \DOMDocument('1.0');
51+
$dom->preserveWhiteSpace = false;
52+
$dom->formatOutput = true;
53+
$dom->loadXML(file_get_contents($miscXmlFile));
54+
55+
//Locate ProjectResources node, create one if none are found.
56+
$nodeForWork = null;
57+
foreach($dom->getElementsByTagName('component') as $child) {
58+
if ($child->getAttribute('name') === 'ProjectResources') {
59+
$nodeForWork = $child;
60+
}
61+
}
62+
if ($nodeForWork === null) {
63+
$project = $dom->getElementsByTagName('project')->item(0);
64+
$nodeForWork = $dom->createElement('component');
65+
$nodeForWork->setAttribute('name', 'ProjectResources');
66+
$project->appendChild($nodeForWork);
67+
}
68+
69+
//Extract url=>location mappings that already exist, add MFTF URNs and reappend
70+
$resources = [];
71+
$resourceNodes = $nodeForWork->getElementsByTagName('resource');
72+
$resourceCount = $resourceNodes->length;
73+
for ($i = 0; $i < $resourceCount; $i++) {
74+
$child = $resourceNodes[0];
75+
$resources[$child->getAttribute('url')] = $child->getAttribute('location');
76+
$child->parentNode->removeChild($child);
77+
}
78+
79+
$resources = array_merge($resources, $this->generateResourcesArray());
80+
81+
foreach ($resources as $url => $location) {
82+
$resourceNode = $dom->createElement('resource');
83+
$resourceNode->setAttribute('url', $url);
84+
$resourceNode->setAttribute('location', $location);
85+
$nodeForWork->appendChild($resourceNode);
86+
}
87+
88+
//Save output
89+
$dom->save($miscXmlFile);
90+
$output->writeln("MFTF URN mapping successfully added to {$miscXmlFile}.");
91+
}
92+
93+
/**
94+
* Generates urn => location array for all MFTF schema.
95+
* @return array
96+
*/
97+
private function generateResourcesArray()
98+
{
99+
$resourcesArray = [
100+
'urn:magento:mftf:DataGenerator/etc/dataOperation.xsd' =>
101+
realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd'),
102+
'urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd' =>
103+
realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataProfileSchema.xsd'),
104+
'urn:magento:mftf:Page/etc/PageObject.xsd' =>
105+
realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/Page/etc/PageObject.xsd'),
106+
'urn:magento:mftf:Page/etc/SectionObject.xsd' =>
107+
realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd'),
108+
'urn:magento:mftf:Test/etc/actionGroupSchema.xsd' =>
109+
realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd'),
110+
'urn:magento:mftf:Test/etc/testSchema.xsd' =>
111+
realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd'),
112+
'urn:magento:mftf:Suite/etc/suiteSchema.xsd' =>
113+
realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/Suite/etc/suiteSchema.xsd')
114+
];
115+
return $resourcesArray;
116+
}
117+
118+
}

src/Magento/FunctionalTestingFramework/Console/GenerateSuiteCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ protected function configure()
3737
*
3838
* @param InputInterface $input
3939
* @param OutputInterface $output
40-
* @return void
41-
* @throws \Symfony\Component\Console\Exception\LogicException
40+
* @return int|null|void
41+
* @throws \Exception
4242
*/
4343
protected function execute(InputInterface $input, OutputInterface $output)
4444
{

src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ protected function configure()
4646
* @param InputInterface $input
4747
* @param OutputInterface $output
4848
* @return void
49-
* @throws \Symfony\Component\Console\Exception\LogicException|TestFrameworkException
49+
* @throws TestFrameworkException
50+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
51+
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
5052
*/
5153
protected function execute(InputInterface $input, OutputInterface $output)
5254
{
@@ -97,6 +99,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
9799
* @param bool $debug
98100
* @param bool $verbose
99101
* @return array
102+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
103+
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
100104
*/
101105
private function createTestConfiguration($json, array $tests, bool $force, bool $debug, bool $verbose)
102106
{
@@ -134,10 +138,10 @@ private function createTestConfiguration($json, array $tests, bool $force, bool
134138
*
135139
* @param string $json
136140
* @param array $testConfiguration
137-
* @throws TestFrameworkException
138141
* @return array
139142
*/
140-
private function parseTestsConfigJson($json, array $testConfiguration) {
143+
private function parseTestsConfigJson($json, array $testConfiguration)
144+
{
141145
if ($json === null) {
142146
return $testConfiguration;
143147
}

src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ protected function configure()
3636
*
3737
* @param InputInterface $input
3838
* @param OutputInterface $output
39-
* @return void
40-
* @throws \Symfony\Component\Console\Exception\LogicException
39+
* @return int|null|void
40+
* @throws \Exception
4141
*
4242
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
4343
*/

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ protected function configure()
4242
*
4343
* @param InputInterface $input
4444
* @param OutputInterface $output
45-
* @return void
46-
* @throws \Symfony\Component\Console\Exception\LogicException
45+
* @return int|null|void
46+
* @throws \Exception
4747
*
4848
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
4949
*/
@@ -82,6 +82,7 @@ function ($type, $buffer) use ($output) {
8282
*
8383
* @param array $groups
8484
* @return string
85+
* @throws \Magento\FunctionalTestingFramework\Exceptions\XmlException
8586
*/
8687
private function getGroupAndSuiteConfiguration(array $groups)
8788
{

0 commit comments

Comments
 (0)