Skip to content

Commit e6c50d8

Browse files
committed
update: add some unit tests for fs methods
1 parent aa67c12 commit e6c50d8

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/FileSystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function isAbsPath(string $path): bool
4747
}
4848

4949
if (strpos($path, '/') === 0 || // linux/mac
50-
1 === preg_match('#^[a-z]:[\/|\\\]{1}.+#i', $path) // windows
50+
1 === preg_match('#^[a-z]:[\/|\\\].+#i', $path) // windows
5151
) {
5252
return true;
5353
}

test/FsTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Toolkit\FsUtilTest;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Toolkit\FsUtil\FS;
7+
8+
/**
9+
* class FsTest
10+
*/
11+
class FsTest extends TestCase
12+
{
13+
public function testIsAbsPath(): void
14+
{
15+
$tests = [
16+
'/tmp',
17+
'C:/tmp',
18+
'C:\\tmp',
19+
'C:\tmp',
20+
"C:\\tmp",
21+
];
22+
23+
foreach ($tests as $case) {
24+
$this->assertTrue(FS::isAbsPath($case));
25+
$this->assertTrue(FS::isAbsolutePath($case));
26+
}
27+
}
28+
29+
public function testClearPharPath(): void
30+
{
31+
$tests = [
32+
['phar://E:/workenv/xxx/yyy/app.phar/web', 'E:/workenv/xxx/yyy/web'],
33+
['phar:///workenv/xxx/yyy/app.phar/web', '/workenv/xxx/yyy/web'],
34+
['E:/workenv/xxx/yyy/web', 'E:/workenv/xxx/yyy/web'],
35+
['/workenv/xxx/yyy/web', '/workenv/xxx/yyy/web'],
36+
];
37+
38+
foreach ($tests as [$test, $want]) {
39+
$this->assertSame($want, FS::clearPharPath($test));
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)