Skip to content

Commit 1790c48

Browse files
committed
Updates one test so that it can run on Windows
1 parent ff15e08 commit 1790c48

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

tests/HelperTest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class HelperTest extends \PHPUnit_Framework_TestCase
2525
*/
2626
private $lockFile;
2727

28+
/**
29+
* @var string
30+
*/
31+
private $copyOfLockFile;
32+
2833
/**
2934
* {@inheritdoc}
3035
*/
@@ -33,6 +38,7 @@ protected function setUp()
3338
$this->helper = new Helper();
3439
$this->tmpDir = $this->helper->getTempDir();
3540
$this->lockFile = $this->tmpDir . '/test.lock';
41+
$this->copyOfLockFile = $this->tmpDir . "/test.lock.copy";
3642
}
3743

3844
/**
@@ -105,12 +111,18 @@ public function testAquireAndReleaseLock()
105111
*/
106112
public function testLockFileShouldContainCurrentPid()
107113
{
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
108118
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;
110123
}
111124

112-
$this->helper->acquireLock($this->lockFile);
113-
$this->assertEquals(getmypid(), file_get_contents($this->lockFile));
125+
$this->assertEquals(getmypid(), file_get_contents($lockFile));
114126

115127
$this->helper->releaseLock($this->lockFile);
116128
$this->assertEmpty(file_get_contents($this->lockFile));
@@ -154,7 +166,7 @@ public function testLockLifetimeShouldBeZeroIfItContainsAInvalidPid()
154166
public function testGetLocklifetime()
155167
{
156168
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");
158170
}
159171

160172
$this->helper->acquireLock($this->lockFile);

0 commit comments

Comments
 (0)