14
14
15
15
class HooksTest extends AbstractTest
16
16
{
17
+ private static $ symlinkOnWindows = null ;
18
+
19
+ public static function setUpBeforeClass ()
20
+ {
21
+ if (defined ('PHP_WINDOWS_VERSION_MAJOR ' )) {
22
+ self ::$ symlinkOnWindows = true ;
23
+ $ originDir = tempnam (sys_get_temp_dir (), 'sl ' );
24
+ $ targetDir = tempnam (sys_get_temp_dir (), 'sl ' );
25
+ if (true !== @symlink ($ originDir , $ targetDir )) {
26
+ $ report = error_get_last ();
27
+ if (is_array ($ report ) && false !== strpos ($ report ['message ' ], 'error code(1314) ' )) {
28
+ self ::$ symlinkOnWindows = false ;
29
+ }
30
+ }
31
+ }
32
+ }
33
+
17
34
public function hookPath ($ repository , $ hook )
18
35
{
19
36
return $ repository ->getGitDir ().'/hooks/ ' .$ hook ;
@@ -77,6 +94,8 @@ public function testGet($repository)
77
94
*/
78
95
public function testSymlink ($ repository )
79
96
{
97
+ $ this ->markAsSkippedIfSymlinkIsMissing ();
98
+
80
99
$ file = $ this ->touchHook ($ repository , 'bar ' , 'barbarbar ' );
81
100
$ repository ->getHooks ()->setSymlink ('foo ' , $ file );
82
101
@@ -90,6 +109,8 @@ public function testSymlink($repository)
90
109
*/
91
110
public function testSymlink_WithExisting_ThrowsLogicException ($ repository )
92
111
{
112
+ $ this ->markAsSkippedIfSymlinkIsMissing ();
113
+
93
114
$ file = $ this ->hookPath ($ repository , 'target-symlink ' );
94
115
$ fooFile = $ this ->hookPath ($ repository , 'foo ' );
95
116
@@ -144,4 +165,15 @@ public function testRemove_NotExisting_ThrowsLogicException($repository)
144
165
{
145
166
$ repository ->getHooks ()->remove ('foo ' );
146
167
}
168
+
169
+ private function markAsSkippedIfSymlinkIsMissing ()
170
+ {
171
+ if (!function_exists ('symlink ' )) {
172
+ $ this ->markTestSkipped ('symlink is not supported ' );
173
+ }
174
+
175
+ if (defined ('PHP_WINDOWS_VERSION_MAJOR ' ) && false === self ::$ symlinkOnWindows ) {
176
+ $ this ->markTestSkipped ('symlink requires "Create symbolic links" privilege on windows ' );
177
+ }
178
+ }
147
179
}
0 commit comments