File tree Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Expand file tree Collapse file tree 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)
2222 $ path = getenv ('HOME ' ).substr ($ path ,1 );
2323 }
2424
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+ */
2529 if (
26- strpos ($ path , '/ ' )!==0 ||
30+ (! $ isWindows && strpos ($ path , '/ ' )!==0 ) ||
2731 ($ isWindows && !preg_match ("/^[a-z]: \\\/i " , $ path ))
2832 ) { // if we have relative path
2933 $ cwd = $ this ->getCwd ();
@@ -68,4 +72,17 @@ protected function isWindows()
6872
6973 return self ::$ isWindows ;
7074 }
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+
7188}
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