|
| 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 | +} |
0 commit comments