File tree 2 files changed +49
-1
lines changed
2 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -22,8 +22,12 @@ public function getAbsolute($path)
22
22
$ path = getenv ('HOME ' ).substr ($ path ,1 );
23
23
}
24
24
25
+ /*
26
+ * A path is relative when it does not start with / and, in the case of a Windows system,
27
+ * it does not start with x:\ where x is letter from a to z.
28
+ */
25
29
if (
26
- strpos ($ path , '/ ' )!==0 ||
30
+ (! $ isWindows && strpos ($ path , '/ ' )!==0 ) ||
27
31
($ isWindows && !preg_match ("/^[a-z]: \\\/i " , $ path ))
28
32
) { // if we have relative path
29
33
$ cwd = $ this ->getCwd ();
@@ -68,4 +72,17 @@ protected function isWindows()
68
72
69
73
return self ::$ isWindows ;
70
74
}
75
+
76
+ /**
77
+ * Allows explicitly setting if this is a Windows system or not.
78
+ * @param boolean $isWindows
79
+ * @return boolean the old state
80
+ */
81
+ public function setWindows ($ isWindows )
82
+ {
83
+ $ currentState = self ::$ isWindows ;
84
+ self ::$ isWindows = $ isWindows ;
85
+ return $ currentState ;
86
+ }
87
+
71
88
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ namespace ClientTest \Service ;
3
+
4
+ use PHPUnit_Framework_TestCase ;
5
+ use Client \Service \PathInvokable ;
6
+
7
+ class PathInvokableTest extends PHPUnit_Framework_TestCase
8
+ {
9
+ /**
10
+ * @var PathInvokable
11
+ */
12
+ protected $ pathService ;
13
+
14
+ public function setUp ()
15
+ {
16
+ $ this ->pathService = new PathInvokable ();
17
+ }
18
+
19
+ /**
20
+ * Tests to see if the absolute path resolver functions correctly on most systems
21
+ */
22
+ public function testGetAbsolute ()
23
+ {
24
+ $ this ->assertEquals ($ this ->pathService ->getAbsolute ('/tmp ' ), '/tmp ' );
25
+ $ this ->assertEquals ($ this ->pathService ->getAbsolute ('tmp/a/b ' ), getcwd ().'/tmp/a/b ' );
26
+
27
+ $ this ->pathService ->setWindows (true );
28
+ $ this ->assertEquals ($ this ->pathService ->getAbsolute ('E: \\tmp ' ), 'E: \\tmp ' );
29
+ $ this ->assertEquals ($ this ->pathService ->getAbsolute ('tmp \\' ), getcwd ().DIRECTORY_SEPARATOR .'tmp \\' );
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments