diff --git a/src/IncludeInterceptor.php b/src/IncludeInterceptor.php index 081f705..3ebd627 100644 --- a/src/IncludeInterceptor.php +++ b/src/IncludeInterceptor.php @@ -249,7 +249,7 @@ public function stream_lock($operation) { assert(is_resource($this->fp)); - return flock($this->fp, $operation); + return flock($this->fp, LOCK_SH); } public function stream_metadata($path, $option, $value) diff --git a/tests/IncludeInterceptorTest.php b/tests/IncludeInterceptorTest.php index 7b8900d..17e11b3 100644 --- a/tests/IncludeInterceptorTest.php +++ b/tests/IncludeInterceptorTest.php @@ -36,12 +36,16 @@ namespace Infection\Tests\StreamWrapper; use function count; +use function file_put_contents; use Infection\StreamWrapper\IncludeInterceptor; use InvalidArgumentException; +use function is_link; use const PHP_SAPI; use PHPUnit\Framework\Error\Warning; use PHPUnit\Framework\TestCase; use RuntimeException; +use function symlink; +use function sys_get_temp_dir; /** * Tests IncludeInterceptor for correct operation. @@ -433,4 +437,15 @@ public function test_it_respects_symlinks_in_url_stat(): void $this->assertTrue(is_link($symlink)); } + + public function test_it_works_with_locks(): void + { + IncludeInterceptor::intercept(self::$files[1], self::$files[2]); + IncludeInterceptor::enable(); + + // action - lock the file to check locking does not throw an exception with our stream wrapper + file_put_contents(self::$files[1], 'text', LOCK_EX); + + $this->addToAssertionCount(1); + } }