Skip to content

Commit

Permalink
Merge pull request #16 from infection/feature/flock
Browse files Browse the repository at this point in the history
Use the correct lock constant when stream wrapper locks the file
  • Loading branch information
maks-rafalko authored Aug 9, 2021
2 parents 498f0a6 + 32a873e commit 0cc76d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/IncludeInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions tests/IncludeInterceptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 0cc76d9

Please sign in to comment.