@@ -16,39 +16,52 @@ class FilePathFormatterTest extends MagentoTestCase
16
16
/**
17
17
* Test file format.
18
18
*
19
- * @param string $path
20
- * @param bool $withTrailingSeparator
19
+ * @param string $path
20
+ * @param bool|null $withTrailingSeparator
21
21
* @param string|null $expectedPath
22
22
*
23
23
* @return void
24
24
* @throws TestFrameworkException
25
25
* @dataProvider formatDataProvider
26
26
*/
27
- public function testFormat (string $ path , bool $ withTrailingSeparator , ?string $ expectedPath ): void
27
+ public function testFormat (string $ path , ? bool $ withTrailingSeparator , ?string $ expectedPath ): void
28
28
{
29
29
if (null !== $ expectedPath ) {
30
+ if ($ withTrailingSeparator === null ) {
31
+ $ this ->assertEquals ($ expectedPath , FilePathFormatter::format ($ path ));
32
+ return ;
33
+ }
30
34
$ this ->assertEquals ($ expectedPath , FilePathFormatter::format ($ path , $ withTrailingSeparator ));
31
35
} else {
32
36
// Assert no exception
33
- FilePathFormatter::format ($ path , $ withTrailingSeparator );
37
+ if ($ withTrailingSeparator === null ) {
38
+ FilePathFormatter::format ($ path );
39
+ } else {
40
+ FilePathFormatter::format ($ path , $ withTrailingSeparator );
41
+ }
34
42
$ this ->assertTrue (true );
35
43
}
36
44
}
37
45
38
46
/**
39
47
* Test file format with exception.
40
48
*
41
- * @param string $path
42
- * @param bool $withTrailingSeparator
49
+ * @param string $path
50
+ * @param bool|null $withTrailingSeparator
43
51
*
44
52
* @return void
45
53
* @throws TestFrameworkException
46
54
* @dataProvider formatExceptionDataProvider
47
55
*/
48
- public function testFormatWithException (string $ path , bool $ withTrailingSeparator ): void
56
+ public function testFormatWithException (string $ path , ? bool $ withTrailingSeparator ): void
49
57
{
50
58
$ this ->expectException (TestFrameworkException::class);
51
59
$ this ->expectExceptionMessage ("Invalid or non-existing file: $ path \n" );
60
+
61
+ if ($ withTrailingSeparator === null ) {
62
+ FilePathFormatter::format ($ path );
63
+ return ;
64
+ }
52
65
FilePathFormatter::format ($ path , $ withTrailingSeparator );
53
66
}
54
67
@@ -63,14 +76,14 @@ public function formatDataProvider(): array
63
76
$ path2 = $ path1 . DIRECTORY_SEPARATOR ;
64
77
65
78
return [
66
- [$ path1 , false , $ path1 ],
79
+ [$ path1 , null , $ path2 ],
67
80
[$ path1 , false , $ path1 ],
68
81
[$ path1 , true , $ path2 ],
69
- [$ path2 , false , $ path1 ],
82
+ [$ path2 , null , $ path2 ],
70
83
[$ path2 , false , $ path1 ],
71
84
[$ 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
74
87
];
75
88
}
76
89
@@ -82,8 +95,8 @@ public function formatDataProvider(): array
82
95
public function formatExceptionDataProvider (): array
83
96
{
84
97
return [
85
- ['abc ' , false ],
86
- ['X://some\dir/@ ' , false ]
98
+ ['abc ' , null ],
99
+ ['X://some\dir/@ ' , null ]
87
100
];
88
101
}
89
102
}
0 commit comments