Skip to content

Commit e4499a3

Browse files
authored
Merge pull request #509 from magento/MQE-1470
MQE-1470: add interface to handle file path and url format
2 parents cf353e4 + ecf1f25 commit e4499a3

32 files changed

+583
-186
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Tests\unit\Magento\FunctionalTestFramework\Util\Path;
7+
8+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
9+
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
10+
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
11+
12+
class FilePathFormatterTest extends MagentoTestCase
13+
{
14+
/**
15+
* Test file format
16+
*
17+
* @dataProvider formatDataProvider
18+
* @param string $path
19+
* @param boolean $withTrailingSeparator
20+
* @param mixed string|boolean $expectedPath
21+
* @return void
22+
* @throws TestFrameworkException
23+
*/
24+
public function testFormat($path, $withTrailingSeparator, $expectedPath)
25+
{
26+
if (null !== $expectedPath) {
27+
$this->assertEquals($expectedPath, FilePathFormatter::format($path, $withTrailingSeparator));
28+
} else {
29+
// Assert no exception
30+
FilePathFormatter::format($path, $withTrailingSeparator);
31+
$this->assertTrue(true);
32+
}
33+
}
34+
35+
/**
36+
* Test file format with exception
37+
*
38+
* @dataProvider formatExceptionDataProvider
39+
* @param string $path
40+
* @param boolean $withTrailingSeparator
41+
* @return void
42+
* @throws TestFrameworkException
43+
*/
44+
public function testFormatWithException($path, $withTrailingSeparator)
45+
{
46+
$this->expectException(TestFrameworkException::class);
47+
$this->expectExceptionMessage("Invalid or non-existing file: $path\n");
48+
FilePathFormatter::format($path, $withTrailingSeparator);
49+
}
50+
51+
/**
52+
* Data input
53+
*
54+
* @return array
55+
*/
56+
public function formatDataProvider()
57+
{
58+
$path1 = rtrim(TESTS_BP, '/');
59+
$path2 = $path1 . DIRECTORY_SEPARATOR;
60+
return [
61+
[$path1, null, $path1],
62+
[$path1, false, $path1],
63+
[$path1, true, $path2],
64+
[$path2, null, $path1],
65+
[$path2, false, $path1],
66+
[$path2, true, $path2],
67+
[__DIR__. DIRECTORY_SEPARATOR . basename(__FILE__), null, __FILE__],
68+
['', null, null] // Empty string is valid
69+
];
70+
}
71+
72+
/**
73+
* Invalid data input
74+
*
75+
* @return array
76+
*/
77+
public function formatExceptionDataProvider()
78+
{
79+
return [
80+
['abc', null],
81+
['X://some\dir/@', null],
82+
];
83+
}
84+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Tests\unit\Magento\FunctionalTestFramework\Util\Path;
7+
8+
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
9+
use Magento\FunctionalTestingFramework\Util\Path\UrlFormatter;
10+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
11+
12+
class UrlFormatterTest extends MagentoTestCase
13+
{
14+
/**
15+
* Test url format
16+
*
17+
* @dataProvider formatDataProvider
18+
* @param string $path
19+
* @param boolean $withTrailingSeparator
20+
* @param mixed string|boolean $expectedPath
21+
* @return void
22+
* @throws TestFrameworkException
23+
*/
24+
public function testFormat($path, $withTrailingSeparator, $expectedPath)
25+
{
26+
$this->assertEquals($expectedPath, UrlFormatter::format($path, $withTrailingSeparator));
27+
}
28+
29+
/**
30+
* Test url format with exception
31+
*
32+
* @dataProvider formatExceptionDataProvider
33+
* @param string $path
34+
* @param boolean $withTrailingSeparator
35+
* @return void
36+
* @throws TestFrameworkException
37+
*/
38+
public function testFormatWithException($path, $withTrailingSeparator)
39+
{
40+
$this->expectException(TestFrameworkException::class);
41+
$this->expectExceptionMessage("Invalid url: $path\n");
42+
UrlFormatter::format($path, $withTrailingSeparator);
43+
}
44+
45+
/**
46+
* Data input
47+
*
48+
* @return array
49+
*/
50+
public function formatDataProvider()
51+
{
52+
$url1 = 'http://magento.local/index.php';
53+
$url2 = $url1 . '/';
54+
$url3 = 'https://www.example.com/index.php/admin';
55+
$url4 = $url3 . '/';
56+
$url5 = 'www.google.com';
57+
$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';
61+
return [
62+
[$url1, null, $url1],
63+
[$url1, false, $url1],
64+
[$url1, true, $url2],
65+
[$url2, null, $url1],
66+
[$url2, false, $url1],
67+
[$url2, true, $url2],
68+
[$url3, null, $url3],
69+
[$url3, false, $url3],
70+
[$url3, true, $url4],
71+
[$url4, null, $url3],
72+
[$url4, false, $url3],
73+
[$url4, true, $url4],
74+
[$url5, true, $url6],
75+
[$url7, false, $url7],
76+
[$url8, false, $url9],
77+
];
78+
}
79+
80+
/**
81+
* Invalid data input
82+
*
83+
* @return array
84+
*/
85+
public function formatExceptionDataProvider()
86+
{
87+
return [
88+
['', null],
89+
];
90+
}
91+
}

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);

0 commit comments

Comments
 (0)