File tree Expand file tree Collapse file tree 2 files changed +55
-4
lines changed Expand file tree Collapse file tree 2 files changed +55
-4
lines changed Original file line number Diff line number Diff line change @@ -14,22 +14,22 @@ private function __construct(string $path)
1414 $ this ->path = $ path ;
1515 }
1616
17- public function isAbsolute ()
17+ public function isAbsolute (): bool
1818 {
19- return 0 === strpos ($ this ->path , ' / ' );
19+ return Path:: isAbsolute ($ this ->path );
2020 }
2121
2222 public function __toString ()
2323 {
2424 return $ this ->path ;
2525 }
2626
27- public static function fromString ($ path )
27+ public static function fromString ($ path ): FilePath
2828 {
2929 return new self ($ path );
3030 }
3131
32- public static function fromParts (array $ parts )
32+ public static function fromParts (array $ parts ): FilePath
3333 {
3434 $ path = implode ('/ ' , $ parts );
3535
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Phpactor \ClassFileConverter \Tests \Unit \Domain ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+ use Phpactor \ClassFileConverter \Domain \FilePath ;
7+
8+ class FilePathTest extends TestCase
9+ {
10+ /**
11+ * @dataProvider provideIsAbsolute
12+ */
13+ public function testIsAbsolute (string $ path , bool $ expected )
14+ {
15+ $ path = FilePath::fromString ($ path );
16+ self ::assertEquals ($ expected , $ path ->isAbsolute ());
17+ }
18+
19+ public function provideIsAbsolute ()
20+ {
21+ yield 'not absolute unix ' => [
22+ 'foobar/barfoo ' ,
23+ false ,
24+ ];
25+
26+ yield 'absolute unix ' => [
27+ '/foobar/barfoo ' ,
28+ true ,
29+ ];
30+
31+ yield 'absolute windows ' => [
32+ 'c:\foobar\barfoo ' ,
33+ true ,
34+ ];
35+
36+ yield 'not absolute windows ' => [
37+ 'foobar\barfoo ' ,
38+ false ,
39+ ];
40+
41+ yield 'absolute phar ' => [
42+ 'phar:///barfoo ' ,
43+ true
44+ ];
45+
46+ yield 'not absolute phar ' => [
47+ 'phar://barfoo ' ,
48+ false ,
49+ ];
50+ }
51+ }
You can’t perform that action at this time.
0 commit comments