Skip to content

Commit c2d5d6b

Browse files
authored
Merge branch 'develop' into imported-magento-magento2-functional-testing-framework-868
2 parents bbf9b20 + 9c4aaaf commit c2d5d6b

File tree

10 files changed

+132
-82
lines changed

10 files changed

+132
-82
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"phpmd/phpmd": "^2.8.0",
4646
"phpunit/phpunit": "^9.0",
4747
"sebastian/phpcpd": "~6.0.0",
48-
"squizlabs/php_codesniffer": "~3.5.4"
48+
"squizlabs/php_codesniffer": "~3.6.0"
4949
},
5050
"autoload": {
5151
"files": ["src/Magento/FunctionalTestingFramework/_bootstrap.php"],

composer.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+39-21
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,100 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace tests\unit\Magento\FunctionalTestFramework\Util\Path;
79

810
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
9-
use tests\unit\Util\MagentoTestCase;
1011
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
12+
use tests\unit\Util\MagentoTestCase;
1113

1214
class FilePathFormatterTest extends MagentoTestCase
1315
{
1416
/**
15-
* Test file format
17+
* Test file format.
18+
*
19+
* @param string $path
20+
* @param bool|null $withTrailingSeparator
21+
* @param string|null $expectedPath
1622
*
17-
* @dataProvider formatDataProvider
18-
* @param string $path
19-
* @param boolean $withTrailingSeparator
20-
* @param mixed string|boolean $expectedPath
2123
* @return void
2224
* @throws TestFrameworkException
25+
* @dataProvider formatDataProvider
2326
*/
24-
public function testFormat($path, $withTrailingSeparator, $expectedPath)
27+
public function testFormat(string $path, ?bool $withTrailingSeparator, ?string $expectedPath): void
2528
{
2629
if (null !== $expectedPath) {
30+
if ($withTrailingSeparator === null) {
31+
$this->assertEquals($expectedPath, FilePathFormatter::format($path));
32+
return;
33+
}
2734
$this->assertEquals($expectedPath, FilePathFormatter::format($path, $withTrailingSeparator));
2835
} else {
2936
// Assert no exception
30-
FilePathFormatter::format($path, $withTrailingSeparator);
37+
if ($withTrailingSeparator === null) {
38+
FilePathFormatter::format($path);
39+
} else {
40+
FilePathFormatter::format($path, $withTrailingSeparator);
41+
}
3142
$this->assertTrue(true);
3243
}
3344
}
3445

3546
/**
36-
* Test file format with exception
47+
* Test file format with exception.
48+
*
49+
* @param string $path
50+
* @param bool|null $withTrailingSeparator
3751
*
38-
* @dataProvider formatExceptionDataProvider
39-
* @param string $path
40-
* @param boolean $withTrailingSeparator
4152
* @return void
4253
* @throws TestFrameworkException
54+
* @dataProvider formatExceptionDataProvider
4355
*/
44-
public function testFormatWithException($path, $withTrailingSeparator)
56+
public function testFormatWithException(string $path, ?bool $withTrailingSeparator): void
4557
{
4658
$this->expectException(TestFrameworkException::class);
4759
$this->expectExceptionMessage("Invalid or non-existing file: $path\n");
60+
61+
if ($withTrailingSeparator === null) {
62+
FilePathFormatter::format($path);
63+
return;
64+
}
4865
FilePathFormatter::format($path, $withTrailingSeparator);
4966
}
5067

5168
/**
52-
* Data input
69+
* Data input.
5370
*
5471
* @return array
5572
*/
56-
public function formatDataProvider()
73+
public function formatDataProvider(): array
5774
{
5875
$path1 = rtrim(TESTS_BP, '/');
5976
$path2 = $path1 . DIRECTORY_SEPARATOR;
77+
6078
return [
61-
[$path1, null, $path1],
79+
[$path1, null, $path2],
6280
[$path1, false, $path1],
6381
[$path1, true, $path2],
64-
[$path2, null, $path1],
82+
[$path2, null, $path2],
6583
[$path2, false, $path1],
6684
[$path2, true, $path2],
67-
[__DIR__. DIRECTORY_SEPARATOR . basename(__FILE__), null, __FILE__],
85+
[__DIR__ . DIRECTORY_SEPARATOR . basename(__FILE__), null, __FILE__ . DIRECTORY_SEPARATOR],
6886
['', null, null] // Empty string is valid
6987
];
7088
}
7189

7290
/**
73-
* Invalid data input
91+
* Invalid data input.
7492
*
7593
* @return array
7694
*/
77-
public function formatExceptionDataProvider()
95+
public function formatExceptionDataProvider(): array
7896
{
7997
return [
8098
['abc', null],
81-
['X://some\dir/@', null],
99+
['X://some\dir/@', null]
82100
];
83101
}
84102
}

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

+37-22
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,62 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace tests\unit\Magento\FunctionalTestFramework\Util\Path;
79

8-
use tests\unit\Util\MagentoTestCase;
9-
use Magento\FunctionalTestingFramework\Util\Path\UrlFormatter;
1010
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
11+
use Magento\FunctionalTestingFramework\Util\Path\UrlFormatter;
12+
use tests\unit\Util\MagentoTestCase;
1113

1214
class UrlFormatterTest extends MagentoTestCase
1315
{
1416
/**
15-
* Test url format
17+
* Test url format.
1618
*
17-
* @dataProvider formatDataProvider
1819
* @param string $path
19-
* @param boolean $withTrailingSeparator
20-
* @param mixed string|boolean $expectedPath
20+
* @param bool|null $withTrailingSeparator
21+
* @param string $expectedPath
22+
*
2123
* @return void
22-
* @throws TestFrameworkException
24+
* @dataProvider formatDataProvider
2325
*/
24-
public function testFormat($path, $withTrailingSeparator, $expectedPath)
26+
public function testFormat(string $path, ?bool $withTrailingSeparator, string $expectedPath): void
2527
{
28+
if ($withTrailingSeparator === null) {
29+
$this->assertEquals($expectedPath, UrlFormatter::format($path));
30+
return;
31+
}
2632
$this->assertEquals($expectedPath, UrlFormatter::format($path, $withTrailingSeparator));
2733
}
2834

2935
/**
30-
* Test url format with exception
36+
* Test url format with exception.
3137
*
32-
* @dataProvider formatExceptionDataProvider
3338
* @param string $path
34-
* @param boolean $withTrailingSeparator
39+
* @param bool|null $withTrailingSeparator
40+
*
3541
* @return void
36-
* @throws TestFrameworkException
42+
* @dataProvider formatExceptionDataProvider
3743
*/
38-
public function testFormatWithException($path, $withTrailingSeparator)
44+
public function testFormatWithException(string $path, ?bool $withTrailingSeparator): void
3945
{
4046
$this->expectException(TestFrameworkException::class);
4147
$this->expectExceptionMessage("Invalid url: $path\n");
48+
49+
if ($withTrailingSeparator === null) {
50+
UrlFormatter::format($path);
51+
return;
52+
}
4253
UrlFormatter::format($path, $withTrailingSeparator);
4354
}
4455

4556
/**
46-
* Data input
57+
* Data input.
4758
*
4859
* @return array
4960
*/
50-
public function formatDataProvider()
61+
public function formatDataProvider(): array
5162
{
5263
$url1 = 'http://magento.local/index.php';
5364
$url2 = $url1 . '/';
@@ -58,34 +69,38 @@ public function formatDataProvider()
5869
$url7 = 'http://127.0.0.1:8200';
5970
$url8 = 'wwøw.goåoøgle.coøm';
6071
$url9 = 'http://www.google.com';
72+
6173
return [
62-
[$url1, null, $url1],
74+
[$url1, null, $url2],
6375
[$url1, false, $url1],
6476
[$url1, true, $url2],
65-
[$url2, null, $url1],
77+
[$url2, null, $url2],
6678
[$url2, false, $url1],
6779
[$url2, true, $url2],
68-
[$url3, null, $url3],
80+
[$url3, null, $url4],
6981
[$url3, false, $url3],
7082
[$url3, true, $url4],
71-
[$url4, null, $url3],
83+
[$url4, null, $url4],
7284
[$url4, false, $url3],
7385
[$url4, true, $url4],
7486
[$url5, true, $url6],
7587
[$url7, false, $url7],
7688
[$url8, false, $url9],
89+
['https://magento.local/path?', false, 'https://magento.local/path?'],
90+
['https://magento.local/path#', false, 'https://magento.local/path#'],
91+
['https://magento.local/path?#', false, 'https://magento.local/path?#']
7792
];
7893
}
7994

8095
/**
81-
* Invalid data input
96+
* Invalid data input.
8297
*
8398
* @return array
8499
*/
85-
public function formatExceptionDataProvider()
100+
public function formatExceptionDataProvider(): array
86101
{
87102
return [
88-
['', null],
103+
['', null]
89104
];
90105
}
91106
}

src/Magento/FunctionalTestingFramework/Config/Dom/ArrayNodeConfig.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct(
6464
public function isNumericArray($nodeXpath)
6565
{
6666
foreach ($this->numericArrays as $pathPattern) {
67-
if ($this->nodePathMatcher->match($pathPattern, $nodeXpath)) {
67+
if ($this->nodePathMatcher->pathMatch($pathPattern, $nodeXpath)) {
6868
return true;
6969
}
7070
}
@@ -84,7 +84,7 @@ public function getAssocArrayKeyAttribute($nodeXpath)
8484
}
8585

8686
foreach ($this->assocArrays as $pathPattern => $keyAttribute) {
87-
if ($this->nodePathMatcher->match($pathPattern, $nodeXpath)) {
87+
if ($this->nodePathMatcher->pathMatch($pathPattern, $nodeXpath)) {
8888
return $keyAttribute;
8989
}
9090
}

src/Magento/FunctionalTestingFramework/Config/Dom/NodeMergingConfig.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(NodePathMatcher $nodePathMatcher, array $idAttribute
4444
public function getIdAttribute($nodeXpath)
4545
{
4646
foreach ($this->idAttributes as $pathPattern => $idAttribute) {
47-
if ($this->nodePathMatcher->match($pathPattern, $nodeXpath)) {
47+
if ($this->nodePathMatcher->pathMatch($pathPattern, $nodeXpath)) {
4848
return $idAttribute;
4949
}
5050
}

src/Magento/FunctionalTestingFramework/Config/Dom/NodePathMatcher.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class NodePathMatcher
1717
* @param string $xpathSubject Example: '/some[@attr="value"]/static/ns:path'.
1818
* @return boolean
1919
*/
20-
public function match($pathPattern, $xpathSubject)
20+
public function pathMatch($pathPattern, $xpathSubject)
2121
{
2222
$pathSubject = $this->simplifyXpath($xpathSubject);
2323
$pathPattern = '#^' . $pathPattern . '$#';

src/Magento/FunctionalTestingFramework/Util/Path/FilePathFormatter.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\FunctionalTestingFramework\Util\Path;
89

@@ -11,14 +12,15 @@
1112
class FilePathFormatter implements FormatterInterface
1213
{
1314
/**
14-
* Return formatted full file path from input string, or false on error
15+
* Return formatted full file path from input string, or false on error.
1516
*
1617
* @param string $path
1718
* @param boolean $withTrailingSeparator
19+
*
1820
* @return string
1921
* @throws TestFrameworkException
2022
*/
21-
public static function format($path, $withTrailingSeparator = true)
23+
public static function format(string $path, bool $withTrailingSeparator = true): string
2224
{
2325
$validPath = realpath($path);
2426

src/Magento/FunctionalTestingFramework/Util/Path/FormatterInterface.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\FunctionalTestingFramework\Util\Path;
89

@@ -11,12 +12,13 @@
1112
interface FormatterInterface
1213
{
1314
/**
14-
* Return formatted path (file path, url, etc) from input string, or false on error
15+
* Return formatted path (file path, url, etc) from input string, or false on error.
1516
*
1617
* @param string $input
1718
* @param boolean $withTrailingSeparator
19+
*
1820
* @return string
1921
* @throws TestFrameworkException
2022
*/
21-
public static function format($input, $withTrailingSeparator = true);
23+
public static function format(string $input, bool $withTrailingSeparator = true): string;
2224
}

0 commit comments

Comments
 (0)