Skip to content

Commit cb5c632

Browse files
committed
MQE-1470: add interface to handle file path and url format
1 parent d8f3980 commit cb5c632

31 files changed

+260
-121
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Util/Path/FilePathFormatterTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class FilePathFormatterTest extends MagentoTestCase
1919
* @param boolean $withTrailingSeparator
2020
* @param mixed string|boolean $expectedPath
2121
* @return void
22+
* @throws TestFrameworkException
2223
*/
2324
public function testFormat($path, $withTrailingSeparator, $expectedPath)
2425
{
@@ -38,6 +39,7 @@ public function testFormat($path, $withTrailingSeparator, $expectedPath)
3839
* @param string $path
3940
* @param boolean $withTrailingSeparator
4041
* @return void
42+
* @throws TestFrameworkException
4143
*/
4244
public function testFormatWithException($path, $withTrailingSeparator)
4345
{

dev/tests/unit/Magento/FunctionalTestFramework/Util/Path/UrlFormatterTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class UrlFormatterTest extends MagentoTestCase
1919
* @param boolean $withTrailingSeparator
2020
* @param mixed string|boolean $expectedPath
2121
* @return void
22+
* @throws TestFrameworkException
2223
*/
2324
public function testFormat($path, $withTrailingSeparator, $expectedPath)
2425
{
@@ -32,6 +33,7 @@ public function testFormat($path, $withTrailingSeparator, $expectedPath)
3233
* @param string $path
3334
* @param boolean $withTrailingSeparator
3435
* @return void
36+
* @throws TestFrameworkException
3537
*/
3638
public function testFormatWithException($path, $withTrailingSeparator)
3739
{
@@ -53,6 +55,9 @@ public function formatDataProvider()
5355
$url4 = $url3 . '/';
5456
$url5 = 'www.google.com';
5557
$url6 = 'http://www.google.com/';
58+
$url7 = 'http://127.0.0.1:8200';
59+
$url8 = 'wwøw.goåoøgle.coøm';
60+
$url9 = 'http://www.google.com';
5661
return [
5762
[$url1, null, $url1],
5863
[$url1, false, $url1],
@@ -67,6 +72,8 @@ public function formatDataProvider()
6772
[$url4, false, $url3],
6873
[$url4, true, $url4],
6974
[$url5, true, $url6],
75+
[$url7, false, $url7],
76+
[$url8, false, $url9],
7077
];
7178
}
7279

dev/tests/verification/Tests/SuiteGenerationTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
namespace tests\verification\Tests;
88

9+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
910
use Magento\FunctionalTestingFramework\Suite\SuiteGenerator;
1011
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
1112
use Magento\FunctionalTestingFramework\Util\Manifest\DefaultTestManifest;
1213
use Magento\FunctionalTestingFramework\Util\Manifest\ParallelTestManifest;
1314
use Magento\FunctionalTestingFramework\Util\Manifest\TestManifestFactory;
15+
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
1416
use PHPUnit\Util\Filesystem;
1517
use Symfony\Component\Yaml\Yaml;
1618
use tests\unit\Util\TestLoggingUtil;
@@ -413,11 +415,11 @@ public static function tearDownAfterClass()
413415
* Getter for manifest file path
414416
*
415417
* @return string
418+
* @throws TestFrameworkException
416419
*/
417420
private static function getManifestFilePath()
418421
{
419-
return TESTS_BP .
420-
DIRECTORY_SEPARATOR .
422+
return FilePathFormatter::format(TESTS_BP) .
421423
"verification" .
422424
DIRECTORY_SEPARATOR .
423425
"_generated" .

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
namespace Magento\FunctionalTestingFramework\Config\FileResolver;
88

9+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
910
use Magento\FunctionalTestingFramework\Util\Iterator\File;
1011
use Magento\FunctionalTestingFramework\Config\FileResolverInterface;
12+
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
1113

1214
/**
1315
* Provides the list of global configuration files.
@@ -54,6 +56,7 @@ private function getFilePaths($filename, $scope)
5456
* @param string $filename
5557
* @param string $scope
5658
* @return array
59+
* @throws TestFrameworkException
5760
*/
5861
private function getPathPatterns($filename, $scope)
5962
{
@@ -69,8 +72,9 @@ private function getPathPatterns($filename, $scope)
6972
$defaultPath . DIRECTORY_SEPARATOR . $scope . DIRECTORY_SEPARATOR . $filename,
7073
$defaultPath . DIRECTORY_SEPARATOR . $scope . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR
7174
. $filename,
72-
FW_BP . DIRECTORY_SEPARATOR . $scope . DIRECTORY_SEPARATOR . $filename,
73-
FW_BP . DIRECTORY_SEPARATOR . $scope . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . $filename
75+
FilePathFormatter::format(FW_BP) . $scope . DIRECTORY_SEPARATOR . $filename,
76+
FilePathFormatter::format(FW_BP) . $scope . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR
77+
. $filename
7478
];
7579
}
7680
return str_replace(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $patterns);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
namespace Magento\FunctionalTestingFramework\Config\FileResolver;
88

99
use Magento\FunctionalTestingFramework\Config\FileResolverInterface;
10+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1011
use Magento\FunctionalTestingFramework\Util\Iterator\File;
12+
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
1113

1214
class Root extends Module
1315
{
@@ -20,12 +22,13 @@ class Root extends Module
2022
* @param string $filename
2123
* @param string $scope
2224
* @return array|\Iterator,\Countable
25+
* @throws TestFrameworkException
2326
*/
2427
public function get($filename, $scope)
2528
{
2629
// first pick up the root level test suite dir
2730
$paths = glob(
28-
TESTS_BP . DIRECTORY_SEPARATOR . self::ROOT_SUITE_DIR
31+
FilePathFormatter::format(TESTS_BP) . self::ROOT_SUITE_DIR
2932
. DIRECTORY_SEPARATOR . $filename
3033
);
3134

src/Magento/FunctionalTestingFramework/Config/SchemaLocator.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\FunctionalTestingFramework\Config;
88

9+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
10+
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
11+
912
/**
1013
* Configuration schema locator.
1114
*/
@@ -30,12 +33,14 @@ class SchemaLocator implements \Magento\FunctionalTestingFramework\Config\Schema
3033
*
3134
* @param string $schemaPath
3235
* @param string|null $perFileSchema
36+
* @throws TestFrameworkException
3337
*/
3438
public function __construct($schemaPath, $perFileSchema = null)
3539
{
36-
if (constant('FW_BP') && file_exists(FW_BP . DIRECTORY_SEPARATOR . $schemaPath)) {
37-
$this->schemaPath = FW_BP . DIRECTORY_SEPARATOR . $schemaPath;
38-
$this->perFileSchema = $perFileSchema === null ? null : FW_BP . DIRECTORY_SEPARATOR . $perFileSchema;
40+
if (constant('FW_BP') && file_exists(FilePathFormatter::format(FW_BP) . $schemaPath)) {
41+
$this->schemaPath = FilePathFormatter::format(FW_BP) . $schemaPath;
42+
$this->perFileSchema = $perFileSchema === null ? null : FilePathFormatter::format(FW_BP)
43+
. $perFileSchema;
3944
} else {
4045
$path = dirname(dirname(dirname(__DIR__)));
4146
$path = str_replace('\\', DIRECTORY_SEPARATOR, $path);

src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
namespace Magento\FunctionalTestingFramework\Console;
1010

11+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1112
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
13+
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
1214
use Symfony\Component\Console\Command\Command;
1315
use Symfony\Component\Console\Input\InputOption;
1416
use Symfony\Component\Console\Output\OutputInterface;
@@ -57,10 +59,11 @@ protected function configure()
5759
* @param OutputInterface $output
5860
* @param bool $verbose
5961
* @return void
62+
* @throws TestFrameworkException
6063
*/
6164
protected function removeGeneratedDirectory(OutputInterface $output, bool $verbose)
6265
{
63-
$generatedDirectory = TESTS_MODULE_PATH . DIRECTORY_SEPARATOR . TestGenerator::GENERATED_DIR;
66+
$generatedDirectory = FilePathFormatter::format(TESTS_MODULE_PATH) . TestGenerator::GENERATED_DIR;
6467

6568
if (file_exists($generatedDirectory)) {
6669
DirSetupUtil::rmdirRecursive($generatedDirectory);

src/Magento/FunctionalTestingFramework/Console/BuildProjectCommand.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Process\Process;
1919
use Magento\FunctionalTestingFramework\Util\Env\EnvProcessor;
2020
use Symfony\Component\Yaml\Yaml;
21+
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
2122

2223
/**
2324
* Class BuildProjectCommand
@@ -28,7 +29,6 @@
2829
class BuildProjectCommand extends Command
2930
{
3031
const DEFAULT_YAML_INLINE_DEPTH = 10;
31-
const CREDENTIALS_FILE_PATH = TESTS_BP . DIRECTORY_SEPARATOR . '.credentials.example';
3232

3333
/**
3434
* Env processor manages .env files.
@@ -41,6 +41,7 @@ class BuildProjectCommand extends Command
4141
* Configures the current command.
4242
*
4343
* @return void
44+
* @throws TestFrameworkException
4445
*/
4546
protected function configure()
4647
{
@@ -52,7 +53,7 @@ protected function configure()
5253
InputOption::VALUE_NONE,
5354
'upgrade existing MFTF tests according to last major release requirements'
5455
);
55-
$this->envProcessor = new EnvProcessor(TESTS_BP . DIRECTORY_SEPARATOR . '.env');
56+
$this->envProcessor = new EnvProcessor(FilePathFormatter::format(TESTS_BP) . '.env');
5657
$env = $this->envProcessor->getEnv();
5758
foreach ($env as $key => $value) {
5859
$this->addOption($key, null, InputOption::VALUE_REQUIRED, '', $value);
@@ -65,8 +66,7 @@ protected function configure()
6566
* @param InputInterface $input
6667
* @param OutputInterface $output
6768
* @return void
68-
* @throws \Symfony\Component\Console\Exception\LogicException
69-
*
69+
* @throws \Exception
7070
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
7171
*/
7272
protected function execute(InputInterface $input, OutputInterface $output)
@@ -109,7 +109,7 @@ function ($type, $buffer) use ($output) {
109109

110110
if ($input->getOption('upgrade')) {
111111
$upgradeCommand = new UpgradeTestsCommand();
112-
$upgradeOptions = new ArrayInput(['path' => TESTS_MODULE_PATH]);
112+
$upgradeOptions = new ArrayInput(['path' => FilePathFormatter::format(TESTS_MODULE_PATH)]);
113113
$upgradeCommand->run($upgradeOptions, $output);
114114
}
115115
}
@@ -119,52 +119,56 @@ function ($type, $buffer) use ($output) {
119119
*
120120
* @param OutputInterface $output
121121
* @return void
122+
* @throws TestFrameworkException
122123
*/
123124
private function generateConfigFiles(OutputInterface $output)
124125
{
125126
$fileSystem = new Filesystem();
126127
//Find travel path from codeception.yml to FW_BP
127128
$relativePath = $fileSystem->makePathRelative(FW_BP, TESTS_BP);
128129

129-
if (!$fileSystem->exists(TESTS_BP . DIRECTORY_SEPARATOR . 'codeception.yml')) {
130+
if (!$fileSystem->exists(FilePathFormatter::format(TESTS_BP) . 'codeception.yml')) {
130131
// read in the codeception.yml file
131-
$configDistYml = Yaml::parse(file_get_contents(realpath(FW_BP . "/etc/config/codeception.dist.yml")));
132+
$configDistYml = Yaml::parse(file_get_contents(
133+
realpath(FilePathFormatter::format(FW_BP) . "etc/config/codeception.dist.yml")
134+
));
132135
$configDistYml['paths']['support'] = $relativePath . 'src/Magento/FunctionalTestingFramework';
133136
$configDistYml['paths']['envs'] = $relativePath . 'etc/_envs';
134137
$configYmlText = Yaml::dump($configDistYml, self::DEFAULT_YAML_INLINE_DEPTH);
135138

136139
// dump output to new codeception.yml file
137-
file_put_contents(TESTS_BP . DIRECTORY_SEPARATOR . 'codeception.yml', $configYmlText);
140+
file_put_contents(FilePathFormatter::format(TESTS_BP) . 'codeception.yml', $configYmlText);
138141
$output->writeln("codeception.yml configuration successfully applied.");
139142
}
140143

141-
$output->writeln("codeception.yml applied to " . TESTS_BP . DIRECTORY_SEPARATOR . 'codeception.yml');
144+
$output->writeln("codeception.yml applied to " . FilePathFormatter::format(TESTS_BP) . 'codeception.yml');
142145

143146
// copy the functional suite yml, will only copy if there are differences between the template the destination
144147
$fileSystem->copy(
145-
realpath(FW_BP . '/etc/config/functional.suite.dist.yml'),
146-
TESTS_BP . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'functional.suite.yml'
148+
realpath(FilePathFormatter::format(FW_BP) . 'etc/config/functional.suite.dist.yml'),
149+
FilePathFormatter::format(TESTS_BP) . 'tests' . DIRECTORY_SEPARATOR . 'functional.suite.yml'
147150
);
148151
$output->writeln('functional.suite.yml configuration successfully applied.');
149152

150153
$output->writeln("functional.suite.yml applied to " .
151-
TESTS_BP . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'functional.suite.yml');
154+
FilePathFormatter::format(TESTS_BP) . 'tests' . DIRECTORY_SEPARATOR . 'functional.suite.yml');
152155

153156
$fileSystem->copy(
154-
FW_BP . '/etc/config/.credentials.example',
155-
self::CREDENTIALS_FILE_PATH
157+
FilePathFormatter::format(FW_BP) . 'etc/config/.credentials.example',
158+
FilePathFormatter::format(TESTS_BP) . '.credentials.example'
156159
);
157160

158161
// copy command.php into magento instance
159-
if (MAGENTO_BP === FW_BP) {
162+
if (FilePathFormatter::format(MAGENTO_BP, false)
163+
=== FilePathFormatter::format(FW_BP, false)) {
160164
$output->writeln('MFTF standalone detected, command.php copy not applied.');
161165
} else {
162166
$fileSystem->copy(
163-
realpath(FW_BP . '/etc/config/command.php'),
164-
TESTS_BP . DIRECTORY_SEPARATOR . "utils" . DIRECTORY_SEPARATOR .'command.php'
167+
realpath(FilePathFormatter::format(FW_BP) . 'etc/config/command.php'),
168+
FilePathFormatter::format(TESTS_BP) . "utils" . DIRECTORY_SEPARATOR .'command.php'
165169
);
166170
$output->writeln('command.php copied to ' .
167-
TESTS_BP . DIRECTORY_SEPARATOR . "utils" . DIRECTORY_SEPARATOR .'command.php');
171+
FilePathFormatter::format(TESTS_BP) . "utils" . DIRECTORY_SEPARATOR .'command.php');
168172
}
169173

170174
// Remove and Create Log File

src/Magento/FunctionalTestingFramework/Console/CleanProjectCommand.php

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\FunctionalTestingFramework\Console;
99

10+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
11+
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
1012
use Symfony\Component\Console\Command\Command;
1113
use Symfony\Component\Console\Input\InputInterface;
1214
use Symfony\Component\Console\Input\InputOption;
@@ -16,21 +18,6 @@
1618

1719
class CleanProjectCommand extends Command
1820
{
19-
const CONFIGURATION_FILES = [
20-
// codeception.yml file for top level config
21-
TESTS_BP . DIRECTORY_SEPARATOR . 'codeception.yml',
22-
// functional.suite.yml for test execution config
23-
TESTS_BP . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'functional.suite.yml',
24-
// Acceptance Tester Actions generated by codeception
25-
FW_BP . '/src/Magento/FunctionalTestingFramework/_generated',
26-
// AcceptanceTester Class generated by codeception
27-
FW_BP . '/src/Magento/FunctionalTestingFramework/AcceptanceTester.php'
28-
];
29-
30-
const GENERATED_FILES = [
31-
TESTS_MODULE_PATH . '/_generated'
32-
];
33-
3421
/**
3522
* Configures the current command.
3623
*
@@ -52,22 +39,40 @@ protected function configure()
5239
* @param OutputInterface $output
5340
* @return void
5441
* @throws \Symfony\Component\Console\Exception\LogicException
42+
* @throws TestFrameworkException
5543
*/
5644
protected function execute(InputInterface $input, OutputInterface $output)
5745
{
46+
$configFiles = [
47+
// codeception.yml file for top level config
48+
FilePathFormatter::format(TESTS_BP) . 'codeception.yml',
49+
// functional.suite.yml for test execution config
50+
FilePathFormatter::format(TESTS_BP) . 'tests' . DIRECTORY_SEPARATOR . 'functional.suite.yml',
51+
// Acceptance Tester Actions generated by codeception
52+
FilePathFormatter::format(FW_BP) . 'src/Magento/FunctionalTestingFramework/_generated',
53+
// AcceptanceTester Class generated by codeception
54+
FilePathFormatter::format(FW_BP) . 'src/Magento/FunctionalTestingFramework/AcceptanceTester.php'
55+
];
56+
57+
$generatedFiles = [
58+
FilePathFormatter::format(TESTS_MODULE_PATH) . '_generated'
59+
];
60+
5861
$isHardReset = $input->getOption('hard');
5962
$fileSystem = new Filesystem();
6063
$finder = new Finder();
61-
$finder->files()->name('*.php')->in(realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/Group/'));
64+
$finder->files()->name('*.php')->in(
65+
realpath(FilePathFormatter::format(FW_BP) . 'src/Magento/FunctionalTestingFramework/Group/')
66+
);
6267
$filesForRemoval = [];
6368

6469
// include config files if user specifies a hard reset for deletion
6570
if ($isHardReset) {
66-
$filesForRemoval = array_merge($filesForRemoval, self::CONFIGURATION_FILES);
71+
$filesForRemoval = array_merge($filesForRemoval, $configFiles);
6772
}
6873

6974
// include the files mftf generates during test execution in TESTS_BP for deletion
70-
$filesForRemoval = array_merge($filesForRemoval, self::GENERATED_FILES);
75+
$filesForRemoval = array_merge($filesForRemoval, $generatedFiles);
7176

7277
if ($output->isVerbose()) {
7378
$output->writeln('Deleting Files:');

0 commit comments

Comments
 (0)