Skip to content

Commit 27f1c6f

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

File tree

8 files changed

+62
-23
lines changed

8 files changed

+62
-23
lines changed

docs/commands/mftf.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ vendor/bin/mftf build:project
2828
vendor/bin/mftf build:project --upgrade
2929
```
3030

31-
Upgrades the existing MFTF tests after the MFTF major upgrade.
31+
Upgrades the all installed MFTF tests after the MFTF major upgrade.
3232

3333
### Generate all tests
3434

@@ -115,7 +115,7 @@ vendor/bin/mftf build:project [--upgrade] [config_param_options]
115115

116116
| Option | Description |
117117
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
118-
| `-u`, `--upgrade` | Upgrades existing MFTF tests according to requirements of the last major release. Specifying this flag upgrades only those tests in the default location. Example: `build:project --upgrade`. |
118+
| `-u`, `--upgrade` | Upgrades all installed MFTF tests according to requirements of the last major release. Specifying this flag upgrades only those tests in the default location. Example: `build:project --upgrade`. |
119119

120120
You can include options to set configuration parameter values for your environment since the project build process also [sets up the environment][setup].
121121

@@ -505,19 +505,26 @@ vendor/bin/mftf static-checks testDependencies actionGroupArguments
505505

506506
### `upgrade:tests`
507507

508-
Applies all the MFTF major version upgrade scripts to test components in the given path (`test.xml`, `data.xml`, etc).
508+
When path argument is specified, this command will apply all the MFTF major version upgrade scripts to test components in the given path (`test.xml`, `data.xml`, etc);
509+
otherwise it will apply all the MFTF major version upgrade scripts to all installed test components.
509510

510511
#### Usage
511512

512513
```bash
513-
vendor/bin/mftf upgrade:tests <path>
514+
vendor/bin/mftf upgrade:tests [<path>]
514515
```
515516

516517
`<path>` is the path that contains MFTF test components that need to be upgraded.
517518
The command searches recursively for any `*.xml` files to upgrade.
518519

519520
#### Examples
520521

522+
To upgrade all installed MFTF tests
523+
524+
```bash
525+
vendor/bin/mftf upgrade:tests
526+
```
527+
521528
To upgrade all test components inside modules in the `dev/tests/acceptance/tests/` directory:
522529

523530
```bash

etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
</virtualType>
8181
<virtualType name="Magento\FunctionalTestingFramework\Config\Reader\Page" type="Magento\FunctionalTestingFramework\Config\Reader\MftfFilesystem">
8282
<arguments>
83-
<argument name="fileResolver" xsi:type="object">Magento\FunctionalTestingFramework\Config\FileResolver\Module</argument>
83+
<argument name="fileResolver" xsi:type="object">Magento\FunctionalTestingFramework\Config\FileResolver\Mask</argument>
8484
<argument name="converter" xsi:type="object">Magento\FunctionalTestingFramework\Config\Converter</argument>
8585
<argument name="schemaLocator" xsi:type="object">Magento\FunctionalTestingFramework\Config\SchemaLocator\Page</argument>
8686
<argument name="domDocumentClass" xsi:type="string">Magento\FunctionalTestingFramework\Page\Config\Dom</argument>

src/Magento/FunctionalTestingFramework/Config/FileResolver/Root.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\FunctionalTestingFramework\Util\Iterator\File;
1212
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
1313

14-
class Root extends Module
14+
class Root extends Mask
1515
{
1616
const ROOT_SUITE_DIR = "tests/_suite";
1717

@@ -26,16 +26,29 @@ class Root extends Module
2626
*/
2727
public function get($filename, $scope)
2828
{
29-
// first pick up the root level test suite dir
30-
$paths = glob(
31-
FilePathFormatter::format(TESTS_BP) . self::ROOT_SUITE_DIR
32-
. DIRECTORY_SEPARATOR . $filename
33-
);
29+
// First pick up the root level test suite dir
30+
$paths = [];
31+
$dir = FilePathFormatter::format(TESTS_BP) . self::ROOT_SUITE_DIR;
32+
if (is_readable($dir)) {
33+
$directoryIterator = new \RecursiveIteratorIterator(
34+
new \RecursiveDirectoryIterator(
35+
$dir,
36+
\FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS
37+
)
38+
);
39+
$regexpIterator = new \RegexIterator($directoryIterator, $filename);
40+
/** @var \SplFileInfo $file */
41+
foreach ($regexpIterator as $file) {
42+
if ($file->isFile() && $file->isReadable()) {
43+
$paths[] = $file->getRealPath();
44+
}
45+
}
46+
}
3447

35-
// then merge this path into the module based paths
36-
// Since we are sharing this code with Module based resolution we will unncessarily glob against modules in the
48+
// Then merge this path into the module based paths
49+
// Since we are sharing this code with Module based resolution we will unnecessarily glob against modules in the
3750
// dev/tests dir tree, however as we plan to migrate to app/code this will be a temporary unneeded check.
38-
$paths = array_merge($paths, $this->getPaths($filename, $scope));
51+
$paths = array_merge($paths, $this->getFileCollection($filename, $scope));
3952

4053
// create and return the iterator for these file paths
4154
$iterator = new File($paths);

src/Magento/FunctionalTestingFramework/Console/UpgradeTestsCommand.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ protected function configure()
3333
{
3434
$this->setName('upgrade:tests')
3535
->setDescription(
36-
'This command will upgrade all installed mftf tests according to new MFTF Major version requirements.'
37-
);
36+
'This command will upgrade MFTF tests according to new MFTF Major version requirements. '
37+
. 'It will upgrade MFTF tests in specific path when "path" argument is specified, otherwise it will '
38+
. 'upgrade all MFTF tests installed.'
39+
)
40+
->addArgument('path', InputArgument::OPTIONAL, 'path to MFTF tests to upgrade');
3841
$this->upgradeScriptsList = new UpgradeScriptList();
3942
}
4043

src/Magento/FunctionalTestingFramework/Upgrade/SplitMultipleEntitiesFiles.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ class SplitMultipleEntitiesFiles implements UpgradeInterface
5656
public function execute(InputInterface $input, OutputInterface $output)
5757
{
5858
$testsUpdated = 0;
59-
$allModulePaths = ScriptUtil::getAllModulePaths();
59+
$testPaths[] = $input->getArgument('path');
60+
if (empty($testPaths[0])) {
61+
$testPaths = ScriptUtil::getAllModulePaths();
62+
}
63+
6064
foreach ($this->entityCategories as $type => $urn) {
6165
$xmlFiles = ScriptUtil::buildFileList(
62-
$allModulePaths,
66+
$testPaths,
6367
DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR
6468
);
6569

src/Magento/FunctionalTestingFramework/Upgrade/UpdateTestSchemaPaths.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ public function execute(InputInterface $input, OutputInterface $output)
5858
}
5959

6060
$testsUpdated = 0;
61-
$allModulePaths = ScriptUtil::getAllModulePaths();
62-
foreach ($allModulePaths as $testsPath) {
61+
$testPaths[] = $input->getArgument('path');
62+
if (empty($testPaths[0])) {
63+
$testPaths = ScriptUtil::getAllModulePaths();
64+
}
65+
66+
foreach ($testPaths as $testsPath) {
6367
$finder = new Finder();
6468
$finder->files()->in($testsPath)->name("*.xml");
6569

src/Magento/FunctionalTestingFramework/Util/ModulePathExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private function extractKeyByPath($path)
9090
}
9191

9292
foreach ($this->testModulePaths as $key => $value) {
93-
if ($value == $shortenedPath) {
93+
if (substr($path, 0, strlen($value)) == $value) {
9494
return $key;
9595
}
9696
}

src/Magento/FunctionalTestingFramework/Util/Script/ScriptUtil.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,27 @@ public static function printErrorsToFile($errors, $filename, $message)
6565

6666
/**
6767
* Builds list of all XML files in given modulePaths + path given
68+
* Return empty array if Finder is not run
69+
*
6870
* @param array $modulePaths
6971
* @param string $path
70-
* @return Finder
72+
* @return Finder|array
7173
*/
7274
public static function buildFileList($modulePaths, $path)
7375
{
76+
$finderRun = false;
7477
$finder = new Finder();
7578
foreach ($modulePaths as $modulePath) {
7679
if (!realpath($modulePath . $path)) {
7780
continue;
7881
}
7982
$finder->files()->in($modulePath . $path)->name("*.xml");
83+
$finderRun = true;
84+
}
85+
if ($finderRun) {
86+
return $finder->files();
87+
} else {
88+
return [];
8089
}
81-
return $finder->files();
8290
}
8391
}

0 commit comments

Comments
 (0)