@@ -25,6 +25,11 @@ class HelperTest extends \PHPUnit_Framework_TestCase
25
25
*/
26
26
private $ lockFile ;
27
27
28
+ /**
29
+ * @var string
30
+ */
31
+ private $ copyOfLockFile ;
32
+
28
33
/**
29
34
* {@inheritdoc}
30
35
*/
@@ -33,6 +38,7 @@ protected function setUp()
33
38
$ this ->helper = new Helper ();
34
39
$ this ->tmpDir = $ this ->helper ->getTempDir ();
35
40
$ this ->lockFile = $ this ->tmpDir . '/test.lock ' ;
41
+ $ this ->copyOfLockFile = $ this ->tmpDir . "/test.lock.copy " ;
36
42
}
37
43
38
44
/**
@@ -105,12 +111,18 @@ public function testAquireAndReleaseLock()
105
111
*/
106
112
public function testLockFileShouldContainCurrentPid ()
107
113
{
114
+ $ this ->helper ->acquireLock ($ this ->lockFile );
115
+
116
+ //on Windows, file locking is mandatory not advisory, so you can't do file_get_contents on a locked file
117
+ //therefore, we need to make a copy of the lock file in order to read its contents
108
118
if ($ this ->helper ->getPlatform () === Helper::WINDOWS ) {
109
- $ this ->markTestSkipped ("Unable to read a locked file on Windows " );
119
+ copy ($ this ->lockFile , $ this ->copyOfLockFile );
120
+ $ lockFile = $ this ->copyOfLockFile ;
121
+ } else {
122
+ $ lockFile = $ this ->lockFile ;
110
123
}
111
124
112
- $ this ->helper ->acquireLock ($ this ->lockFile );
113
- $ this ->assertEquals (getmypid (), file_get_contents ($ this ->lockFile ));
125
+ $ this ->assertEquals (getmypid (), file_get_contents ($ lockFile ));
114
126
115
127
$ this ->helper ->releaseLock ($ this ->lockFile );
116
128
$ this ->assertEmpty (file_get_contents ($ this ->lockFile ));
@@ -154,7 +166,7 @@ public function testLockLifetimeShouldBeZeroIfItContainsAInvalidPid()
154
166
public function testGetLocklifetime ()
155
167
{
156
168
if ($ this ->helper ->getPlatform () === Helper::WINDOWS ) {
157
- $ this ->markTestSkipped ("Unable to read a locked file on Windows " );
169
+ $ this ->markTestSkipped ("Test relies on posix_ functions " );
158
170
}
159
171
160
172
$ this ->helper ->acquireLock ($ this ->lockFile );
0 commit comments