Skip to content

Commit db58ed5

Browse files
committed
Merge branch 'pr-867' into imported-magento-magento2-functional-testing-framework-867
2 parents 7e2187d + 860a39e commit db58ed5

File tree

2 files changed

+44
-22
lines changed

2 files changed

+44
-22
lines changed

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,52 @@ class FilePathFormatterTest extends MagentoTestCase
1616
/**
1717
* Test file format.
1818
*
19-
* @param string $path
20-
* @param bool $withTrailingSeparator
19+
* @param string $path
20+
* @param bool|null $withTrailingSeparator
2121
* @param string|null $expectedPath
2222
*
2323
* @return void
2424
* @throws TestFrameworkException
2525
* @dataProvider formatDataProvider
2626
*/
27-
public function testFormat(string $path, bool $withTrailingSeparator, ?string $expectedPath): void
27+
public function testFormat(string $path, ?bool $withTrailingSeparator, ?string $expectedPath): void
2828
{
2929
if (null !== $expectedPath) {
30+
if ($withTrailingSeparator === null) {
31+
$this->assertEquals($expectedPath, FilePathFormatter::format($path));
32+
return;
33+
}
3034
$this->assertEquals($expectedPath, FilePathFormatter::format($path, $withTrailingSeparator));
3135
} else {
3236
// Assert no exception
33-
FilePathFormatter::format($path, $withTrailingSeparator);
37+
if ($withTrailingSeparator === null) {
38+
FilePathFormatter::format($path);
39+
} else {
40+
FilePathFormatter::format($path, $withTrailingSeparator);
41+
}
3442
$this->assertTrue(true);
3543
}
3644
}
3745

3846
/**
3947
* Test file format with exception.
4048
*
41-
* @param string $path
42-
* @param bool $withTrailingSeparator
49+
* @param string $path
50+
* @param bool|null $withTrailingSeparator
4351
*
4452
* @return void
4553
* @throws TestFrameworkException
4654
* @dataProvider formatExceptionDataProvider
4755
*/
48-
public function testFormatWithException(string $path, bool $withTrailingSeparator): void
56+
public function testFormatWithException(string $path, ?bool $withTrailingSeparator): void
4957
{
5058
$this->expectException(TestFrameworkException::class);
5159
$this->expectExceptionMessage("Invalid or non-existing file: $path\n");
60+
61+
if ($withTrailingSeparator === null) {
62+
FilePathFormatter::format($path);
63+
return;
64+
}
5265
FilePathFormatter::format($path, $withTrailingSeparator);
5366
}
5467

@@ -63,14 +76,14 @@ public function formatDataProvider(): array
6376
$path2 = $path1 . DIRECTORY_SEPARATOR;
6477

6578
return [
66-
[$path1, false, $path1],
79+
[$path1, null, $path2],
6780
[$path1, false, $path1],
6881
[$path1, true, $path2],
69-
[$path2, false, $path1],
82+
[$path2, null, $path2],
7083
[$path2, false, $path1],
7184
[$path2, true, $path2],
72-
[__DIR__. DIRECTORY_SEPARATOR . basename(__FILE__), false, __FILE__],
73-
['', false, null] // Empty string is valid
85+
[__DIR__ . DIRECTORY_SEPARATOR . basename(__FILE__), null, __FILE__ . DIRECTORY_SEPARATOR],
86+
['', null, null] // Empty string is valid
7487
];
7588
}
7689

@@ -82,8 +95,8 @@ public function formatDataProvider(): array
8295
public function formatExceptionDataProvider(): array
8396
{
8497
return [
85-
['abc', false],
86-
['X://some\dir/@', false]
98+
['abc', null],
99+
['X://some\dir/@', null]
87100
];
88101
}
89102
}

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,39 @@ class UrlFormatterTest extends MagentoTestCase
1717
* Test url format.
1818
*
1919
* @param string $path
20-
* @param bool $withTrailingSeparator
20+
* @param bool|null $withTrailingSeparator
2121
* @param string $expectedPath
2222
*
2323
* @return void
2424
* @dataProvider formatDataProvider
2525
*/
26-
public function testFormat(string $path, bool $withTrailingSeparator, string $expectedPath): void
26+
public function testFormat(string $path, ?bool $withTrailingSeparator, string $expectedPath): void
2727
{
28+
if ($withTrailingSeparator === null) {
29+
$this->assertEquals($expectedPath, UrlFormatter::format($path));
30+
return;
31+
}
2832
$this->assertEquals($expectedPath, UrlFormatter::format($path, $withTrailingSeparator));
2933
}
3034

3135
/**
3236
* Test url format with exception.
3337
*
3438
* @param string $path
35-
* @param bool $withTrailingSeparator
39+
* @param bool|null $withTrailingSeparator
3640
*
3741
* @return void
3842
* @dataProvider formatExceptionDataProvider
3943
*/
40-
public function testFormatWithException(string $path, bool $withTrailingSeparator): void
44+
public function testFormatWithException(string $path, ?bool $withTrailingSeparator): void
4145
{
4246
$this->expectException(TestFrameworkException::class);
4347
$this->expectExceptionMessage("Invalid url: $path\n");
48+
49+
if ($withTrailingSeparator === null) {
50+
UrlFormatter::format($path);
51+
return;
52+
}
4453
UrlFormatter::format($path, $withTrailingSeparator);
4554
}
4655

@@ -62,16 +71,16 @@ public function formatDataProvider(): array
6271
$url9 = 'http://www.google.com';
6372

6473
return [
65-
[$url1, false, $url1],
74+
[$url1, null, $url2],
6675
[$url1, false, $url1],
6776
[$url1, true, $url2],
68-
[$url2, false, $url1],
77+
[$url2, null, $url2],
6978
[$url2, false, $url1],
7079
[$url2, true, $url2],
71-
[$url3, false, $url3],
80+
[$url3, null, $url4],
7281
[$url3, false, $url3],
7382
[$url3, true, $url4],
74-
[$url4, false, $url3],
83+
[$url4, null, $url4],
7584
[$url4, false, $url3],
7685
[$url4, true, $url4],
7786
[$url5, true, $url6],
@@ -91,7 +100,7 @@ public function formatDataProvider(): array
91100
public function formatExceptionDataProvider(): array
92101
{
93102
return [
94-
['', false]
103+
['', null]
95104
];
96105
}
97106
}

0 commit comments

Comments
 (0)