Skip to content

Commit cdf6b84

Browse files
committed
MQE-1963: Update XSD Schema to verify that file has only single entity
1 parent fe3c8f5 commit cdf6b84

File tree

10 files changed

+162
-141
lines changed

10 files changed

+162
-141
lines changed

src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ protected function getGroupAndSuiteConfiguration(array $groupOrSuiteNames)
191191
}
192192

193193
/**
194-
* Set Symfony Style for output
194+
* Set Symfony IO Style
195195
*
196196
* @param InputInterface $input
197197
* @param OutputInterface $output
198198
* @return void
199199
*/
200-
protected function setOutputStyle(InputInterface $input, OutputInterface $output)
200+
protected function setIOStyle(InputInterface $input, OutputInterface $output)
201201
{
202-
// For output style
202+
// For IO style
203203
if (null === $this->ioStyle) {
204204
$this->ioStyle = new SymfonyStyle($input, $output);
205205
}

src/Magento/FunctionalTestingFramework/StaticCheck/ActionGroupArgumentsCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function execute(InputInterface $input)
5353
{
5454
$allModules = ScriptUtil::getAllModulePaths();
5555

56-
$actionGroupXmlFiles = ScriptUtil::buildFileList(
56+
$actionGroupXmlFiles = ScriptUtil::getModuleXmlFilesByScope(
5757
$allModules,
5858
DIRECTORY_SEPARATOR . 'ActionGroup' . DIRECTORY_SEPARATOR
5959
);

src/Magento/FunctionalTestingFramework/StaticCheck/TestDependencyCheck.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ public function execute(InputInterface $input)
108108
DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR,
109109
];
110110
// These files can contain references to other modules.
111-
$testXmlFiles = ScriptUtil::buildFileList($allModules, $filePaths[0]);
112-
$actionGroupXmlFiles = ScriptUtil::buildFileList($allModules, $filePaths[1]);
113-
$dataXmlFiles= ScriptUtil::buildFileList($allModules, $filePaths[2]);
111+
$testXmlFiles = ScriptUtil::getModuleXmlFilesByScope($allModules, $filePaths[0]);
112+
$actionGroupXmlFiles = ScriptUtil::getModuleXmlFilesByScope($allModules, $filePaths[1]);
113+
$dataXmlFiles= ScriptUtil::getModuleXmlFilesByScope($allModules, $filePaths[2]);
114114

115115
$this->errors = [];
116116
$this->errors += $this->findErrorsInFileSet($testXmlFiles);

src/Magento/FunctionalTestingFramework/Suite/Util/SuiteObjectExtractor.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Magento\FunctionalTestingFramework\Test\Util\TestObjectExtractor;
1616
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
1717
use Magento\FunctionalTestingFramework\Util\Validation\NameValidationUtil;
18-
use Magento\FunctionalTestingFramework\Util\Filesystem\RecursiveGlobUtil;
18+
use Symfony\Component\Finder\Finder;
1919

2020
class SuiteObjectExtractor extends BaseObjectExtractor
2121
{
@@ -240,17 +240,23 @@ private function extractTestObjectsFromSuiteRef($suiteReferences)
240240
*/
241241
private function resolveFilePathTestNames($filename, $moduleName = null)
242242
{
243-
$filepath = $filename;
243+
$filepath = null;
244244
if (!file_exists($filename) && null !== $moduleName) {
245245
$dir = FilePathFormatter::format(TESTS_MODULE_PATH) . $moduleName . DIRECTORY_SEPARATOR . 'Test';
246-
$filepaths = RecursiveGlobUtil::glob($filename, $dir);
247-
if (isset($filepaths[0]) && file_exists($filepaths[0])) {
248-
$filepath = $filepaths[0];
249-
} else {
250-
throw new Exception("Could not find file ${filename}");
246+
if (file_exists($dir)) {
247+
$finder = new Finder();
248+
$finder->files()->followLinks()->name($filename)->in($dir);
249+
foreach ($finder as $file) {
250+
$filepath = $file->getRealPath();
251+
break;
252+
}
251253
}
252254
}
253255

256+
if (null === $filepath) {
257+
throw new Exception("Could not find file ${filename}");
258+
}
259+
254260
$testObjects = [];
255261
$xml = simplexml_load_file($filepath);
256262
for ($i = 0; $i < $xml->count(); $i++) {

src/Magento/FunctionalTestingFramework/Upgrade/RemoveModuleFileInSuiteFiles.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Symfony\Component\Console\Input\InputInterface;
1212
use Symfony\Component\Console\Output\OutputInterface;
1313
use Symfony\Component\Console\Style\SymfonyStyle;
14+
use Symfony\Component\Finder\Finder;
1415

1516
/**
1617
* Class RemoveModuleFileInSuiteFiles
@@ -63,17 +64,30 @@ public function execute(InputInterface $input, OutputInterface $output)
6364
$testPaths = ScriptUtil::getAllModulePaths();
6465
}
6566

66-
$xmlFiles = ScriptUtil::buildFileList(
67-
$testPaths,
68-
DIRECTORY_SEPARATOR . 'Suite' . DIRECTORY_SEPARATOR
69-
);
67+
// Get module suite xml files
68+
$xmlFiles = ScriptUtil::getModuleXmlFilesByScope($testPaths, 'Suite');
69+
$this->processXmlFiles($xmlFiles);
70+
71+
// Get root suite xml files
72+
$xmlFiles = ScriptUtil::getRootSuiteXmlFiles();
73+
$this->processXmlFiles($xmlFiles);
74+
75+
return ("Removed module file reference in {$this->testsUpdated} suite file(s).");
76+
}
7077

78+
/**
79+
* Process on list of xml files
80+
*
81+
* @param Finder $xmlFiles
82+
* @return void
83+
*/
84+
private function processXmlFiles($xmlFiles)
85+
{
7186
foreach ($xmlFiles as $file) {
7287
$contents = $file->getContents();
7388
$filePath = $file->getRealPath();
7489
file_put_contents($filePath, $this->removeModuleFileAttributeInSuite($contents, $filePath));
7590
}
76-
return ("Removed module file reference in {$this->testsUpdated} suite file(s).");
7791
}
7892

7993
/**
@@ -91,8 +105,8 @@ private function removeModuleFileAttributeInSuite($contents, $file)
91105
function ($matches) use ($file) {
92106
if (!$this->printNotice) {
93107
$this->ioStyle->note(
94-
'`file` attribute is removed from <module> in Suite XML schema.' . PHP_EOL
95-
. 'The references in the following xml files are removed. Consider using <test> instead.'
108+
'`file` is not a valid attribute for <module> in Suite XML schema.' . PHP_EOL
109+
. 'The `file`references in the following xml files are removed. Consider using <test> instead.'
96110
);
97111
$this->printNotice = true;
98112
}
@@ -101,11 +115,11 @@ function ($matches) use ($file) {
101115
. '"' . trim($matches[0]) . '"' . PHP_EOL
102116
. 'is removed from file: ' . $file . PHP_EOL
103117
);
118+
$this->testsUpdated += 1;
104119
return '';
105120
},
106121
$contents
107122
);
108-
$this->testsUpdated += 1;
109123
return $contents;
110124
}
111125

src/Magento/FunctionalTestingFramework/Upgrade/SplitMultipleEntitiesFiles.php

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\FunctionalTestingFramework\Util\Script\ScriptUtil;
1111
use Symfony\Component\Console\Input\InputInterface;
1212
use Symfony\Component\Console\Output\OutputInterface;
13+
use Symfony\Component\Finder\Finder;
1314

1415
/**
1516
* Class SplitMultipleEntitiesFiles
@@ -37,6 +38,13 @@ class SplitMultipleEntitiesFiles implements UpgradeInterface
3738
*/
3839
private $output;
3940

41+
/**
42+
* Total test updated
43+
*
44+
* @var integer
45+
*/
46+
private $testsUpdated = 0;
47+
4048
/**
4149
* Entity categories for the upgrade script
4250
*
@@ -62,51 +70,66 @@ class SplitMultipleEntitiesFiles implements UpgradeInterface
6270
public function execute(InputInterface $input, OutputInterface $output)
6371
{
6472
$this->output = $output;
65-
$testsUpdated = 0;
73+
$this->testsUpdated = 0;
6674
$testPaths[] = $input->getArgument('path');
6775
if (empty($testPaths[0])) {
6876
$testPaths = ScriptUtil::getAllModulePaths();
6977
}
7078

79+
// Process module xml files
7180
foreach ($this->entityCategories as $type => $urn) {
72-
$xmlFiles = ScriptUtil::buildFileList(
73-
$testPaths,
74-
DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR
75-
);
76-
77-
foreach ($xmlFiles as $file) {
78-
$contents = $file->getContents();
79-
$entityContents = $this->getEntityContents($contents, $type);
80-
if (count($entityContents) > 1) {
81-
$filename = $file->getRealPath();
81+
$xmlFiles = ScriptUtil::getModuleXmlFilesByScope($testPaths, $type);
82+
$this->processXmlFiles($xmlFiles, $type, $urn);
83+
}
84+
85+
// Process root suite xml files
86+
$xmlFiles = ScriptUtil::getRootSuiteXmlFiles();
87+
$this->processXmlFiles($xmlFiles, 'Suite', $this->entityCategories['Suite']);
88+
89+
return ("Split multiple entities in {$this->testsUpdated} file(s).");
90+
}
91+
92+
/**
93+
* Split on list of xml files
94+
*
95+
* @param Finder $xmlFiles
96+
* @param string $type
97+
* @param string $urn
98+
* @return void
99+
*/
100+
private function processXmlFiles($xmlFiles, $type, $urn)
101+
{
102+
foreach ($xmlFiles as $file) {
103+
$contents = $file->getContents();
104+
$entityContents = $this->getEntityContents($contents, $type);
105+
if (count($entityContents) > 1) {
106+
$filename = $file->getRealPath();
107+
if ($this->output->isVerbose()) {
108+
$this->output->writeln('Processing file:' . $filename);
109+
}
110+
foreach ($entityContents as $entityName => $entityContent) {
111+
$dir = dirname($file);
112+
$dir .= DIRECTORY_SEPARATOR . ucfirst(basename($file, '.xml'));
113+
$splitFileName = $this->formatName($entityName, $type);
114+
$this->filePutContents(
115+
$dir . DIRECTORY_SEPARATOR . $splitFileName . '.xml',
116+
$type,
117+
$urn,
118+
$entityContent
119+
);
82120
if ($this->output->isVerbose()) {
83-
$this->output->writeln('Processing file:' . $filename);
84-
}
85-
foreach ($entityContents as $entityName => $entityContent) {
86-
$dir = dirname($file);
87-
$dir .= DIRECTORY_SEPARATOR . ucfirst(basename($file, '.xml'));
88-
$splitFileName = $this->formatName($entityName, $type);
89-
$this->filePutContents(
90-
$dir . DIRECTORY_SEPARATOR . $splitFileName . '.xml',
91-
$type,
92-
$urn,
93-
$entityContent
121+
$this->output->writeln(
122+
'Created file:' . $dir . DIRECTORY_SEPARATOR . $splitFileName . '.xml'
94123
);
95-
if ($this->output->isVerbose()) {
96-
$this->output->writeln(
97-
'Created file:' . $dir . DIRECTORY_SEPARATOR . $splitFileName . '.xml'
98-
);
99-
}
100-
$testsUpdated++;
101-
}
102-
unlink($file);
103-
if ($this->output->isVerbose()) {
104-
$this->output->writeln('Unlinked file:' . $filename . PHP_EOL);
105124
}
125+
$this->testsUpdated++;
126+
}
127+
unlink($file);
128+
if ($this->output->isVerbose()) {
129+
$this->output->writeln('Unlinked file:' . $filename . PHP_EOL);
106130
}
107131
}
108132
}
109-
return ("Split multiple entities in {$testsUpdated} file(s).");
110133
}
111134

112135
/**

src/Magento/FunctionalTestingFramework/Util/Filesystem/RecursiveGlobUtil.php

Lines changed: 0 additions & 72 deletions
This file was deleted.

src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
1313
use Magento\FunctionalTestingFramework\Util\Path\UrlFormatter;
1414
use Symfony\Component\HttpFoundation\Response;
15+
use \Magento\FunctionalTestingFramework\Util\ModuleResolver\AlphabeticSequenceSorter;
16+
use \Magento\FunctionalTestingFramework\Util\ModuleResolver\SequenceSorterInterface;
1517

1618
/**
1719
* Class ModuleResolver, resolve module path based on enabled modules of target Magento instance.
@@ -180,9 +182,12 @@ public static function getInstance()
180182
private function __construct()
181183
{
182184
$objectManager = \Magento\FunctionalTestingFramework\ObjectManagerFactory::getObjectManager();
183-
$this->sequenceSorter = $objectManager->get(
184-
\Magento\FunctionalTestingFramework\Util\ModuleResolver\SequenceSorterInterface::class
185-
);
185+
186+
if (MftfApplicationConfig::getConfig()->getPhase() == MftfApplicationConfig::UNIT_TEST_PHASE) {
187+
$this->sequenceSorter = $objectManager->get(AlphabeticSequenceSorter::class);
188+
} else {
189+
$this->sequenceSorter = $objectManager->get(SequenceSorterInterface::class);
190+
}
186191
}
187192

188193
/**
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\FunctionalTestingFramework\Util\ModuleResolver;
8+
9+
/**
10+
* Alphabetic sequence sorter.
11+
*/
12+
class AlphabeticSequenceSorter implements SequenceSorterInterface
13+
{
14+
/**
15+
* Sort files alphabetically.
16+
*
17+
* @param array $paths
18+
* @return array
19+
*/
20+
public function sort(array $paths)
21+
{
22+
asort($paths);
23+
return $paths;
24+
}
25+
}

0 commit comments

Comments
 (0)