|
3 | 3 | * Copyright © Magento, Inc. All rights reserved.
|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
| 6 | +declare(strict_types=1); |
| 7 | + |
6 | 8 | namespace tests\unit\Magento\FunctionalTestFramework\Util\Path;
|
7 | 9 |
|
8 | 10 | use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
|
9 |
| -use tests\unit\Util\MagentoTestCase; |
10 | 11 | use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
|
| 12 | +use tests\unit\Util\MagentoTestCase; |
11 | 13 |
|
12 | 14 | class FilePathFormatterTest extends MagentoTestCase
|
13 | 15 | {
|
14 | 16 | /**
|
15 |
| - * Test file format |
| 17 | + * Test file format. |
| 18 | + * |
| 19 | + * @param string $path |
| 20 | + * @param bool|null $withTrailingSeparator |
| 21 | + * @param string|null $expectedPath |
16 | 22 | *
|
17 |
| - * @dataProvider formatDataProvider |
18 |
| - * @param string $path |
19 |
| - * @param boolean $withTrailingSeparator |
20 |
| - * @param mixed string|boolean $expectedPath |
21 | 23 | * @return void
|
22 | 24 | * @throws TestFrameworkException
|
| 25 | + * @dataProvider formatDataProvider |
23 | 26 | */
|
24 |
| - public function testFormat($path, $withTrailingSeparator, $expectedPath) |
| 27 | + public function testFormat(string $path, ?bool $withTrailingSeparator, ?string $expectedPath): void |
25 | 28 | {
|
26 | 29 | if (null !== $expectedPath) {
|
| 30 | + if ($withTrailingSeparator === null) { |
| 31 | + $this->assertEquals($expectedPath, FilePathFormatter::format($path)); |
| 32 | + return; |
| 33 | + } |
27 | 34 | $this->assertEquals($expectedPath, FilePathFormatter::format($path, $withTrailingSeparator));
|
28 | 35 | } else {
|
29 | 36 | // Assert no exception
|
30 |
| - FilePathFormatter::format($path, $withTrailingSeparator); |
| 37 | + if ($withTrailingSeparator === null) { |
| 38 | + FilePathFormatter::format($path); |
| 39 | + } else { |
| 40 | + FilePathFormatter::format($path, $withTrailingSeparator); |
| 41 | + } |
31 | 42 | $this->assertTrue(true);
|
32 | 43 | }
|
33 | 44 | }
|
34 | 45 |
|
35 | 46 | /**
|
36 |
| - * Test file format with exception |
| 47 | + * Test file format with exception. |
| 48 | + * |
| 49 | + * @param string $path |
| 50 | + * @param bool|null $withTrailingSeparator |
37 | 51 | *
|
38 |
| - * @dataProvider formatExceptionDataProvider |
39 |
| - * @param string $path |
40 |
| - * @param boolean $withTrailingSeparator |
41 | 52 | * @return void
|
42 | 53 | * @throws TestFrameworkException
|
| 54 | + * @dataProvider formatExceptionDataProvider |
43 | 55 | */
|
44 |
| - public function testFormatWithException($path, $withTrailingSeparator) |
| 56 | + public function testFormatWithException(string $path, ?bool $withTrailingSeparator): void |
45 | 57 | {
|
46 | 58 | $this->expectException(TestFrameworkException::class);
|
47 | 59 | $this->expectExceptionMessage("Invalid or non-existing file: $path\n");
|
| 60 | + |
| 61 | + if ($withTrailingSeparator === null) { |
| 62 | + FilePathFormatter::format($path); |
| 63 | + return; |
| 64 | + } |
48 | 65 | FilePathFormatter::format($path, $withTrailingSeparator);
|
49 | 66 | }
|
50 | 67 |
|
51 | 68 | /**
|
52 |
| - * Data input |
| 69 | + * Data input. |
53 | 70 | *
|
54 | 71 | * @return array
|
55 | 72 | */
|
56 |
| - public function formatDataProvider() |
| 73 | + public function formatDataProvider(): array |
57 | 74 | {
|
58 | 75 | $path1 = rtrim(TESTS_BP, '/');
|
59 | 76 | $path2 = $path1 . DIRECTORY_SEPARATOR;
|
| 77 | + |
60 | 78 | return [
|
61 |
| - [$path1, null, $path1], |
| 79 | + [$path1, null, $path2], |
62 | 80 | [$path1, false, $path1],
|
63 | 81 | [$path1, true, $path2],
|
64 |
| - [$path2, null, $path1], |
| 82 | + [$path2, null, $path2], |
65 | 83 | [$path2, false, $path1],
|
66 | 84 | [$path2, true, $path2],
|
67 |
| - [__DIR__. DIRECTORY_SEPARATOR . basename(__FILE__), null, __FILE__], |
| 85 | + [__DIR__ . DIRECTORY_SEPARATOR . basename(__FILE__), null, __FILE__ . DIRECTORY_SEPARATOR], |
68 | 86 | ['', null, null] // Empty string is valid
|
69 | 87 | ];
|
70 | 88 | }
|
71 | 89 |
|
72 | 90 | /**
|
73 |
| - * Invalid data input |
| 91 | + * Invalid data input. |
74 | 92 | *
|
75 | 93 | * @return array
|
76 | 94 | */
|
77 |
| - public function formatExceptionDataProvider() |
| 95 | + public function formatExceptionDataProvider(): array |
78 | 96 | {
|
79 | 97 | return [
|
80 | 98 | ['abc', null],
|
81 |
| - ['X://some\dir/@', null], |
| 99 | + ['X://some\dir/@', null] |
82 | 100 | ];
|
83 | 101 | }
|
84 | 102 | }
|
0 commit comments