Skip to content

Commit 0cc76d9

Browse files
authored
Merge pull request #16 from infection/feature/flock
Use the correct lock constant when stream wrapper locks the file
2 parents 498f0a6 + 32a873e commit 0cc76d9

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/IncludeInterceptor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public function stream_lock($operation)
249249
{
250250
assert(is_resource($this->fp));
251251

252-
return flock($this->fp, $operation);
252+
return flock($this->fp, LOCK_SH);
253253
}
254254

255255
public function stream_metadata($path, $option, $value)

tests/IncludeInterceptorTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@
3636
namespace Infection\Tests\StreamWrapper;
3737

3838
use function count;
39+
use function file_put_contents;
3940
use Infection\StreamWrapper\IncludeInterceptor;
4041
use InvalidArgumentException;
42+
use function is_link;
4143
use const PHP_SAPI;
4244
use PHPUnit\Framework\Error\Warning;
4345
use PHPUnit\Framework\TestCase;
4446
use RuntimeException;
47+
use function symlink;
48+
use function sys_get_temp_dir;
4549

4650
/**
4751
* Tests IncludeInterceptor for correct operation.
@@ -433,4 +437,15 @@ public function test_it_respects_symlinks_in_url_stat(): void
433437

434438
$this->assertTrue(is_link($symlink));
435439
}
440+
441+
public function test_it_works_with_locks(): void
442+
{
443+
IncludeInterceptor::intercept(self::$files[1], self::$files[2]);
444+
IncludeInterceptor::enable();
445+
446+
// action - lock the file to check locking does not throw an exception with our stream wrapper
447+
file_put_contents(self::$files[1], 'text', LOCK_EX);
448+
449+
$this->addToAssertionCount(1);
450+
}
436451
}

0 commit comments

Comments
 (0)