From 2d9dcd750ab28e70bf4315549527bca1314a54a7 Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Mon, 16 Nov 2026 08:57:18 -0500 Subject: [PATCH] fix(tia): answer the stream_lock support probe (#2029) * fix(tia): answer the stream_lock support probe * Refresh stream lock regression snapshots * Correct scoped callback typing and PHPStan compatibility --------- Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com> --- composer.json | 1 + src/Expectations/HigherOrderExpectation.php | 2 +- src/Plugins/Tia/ReadCapture.php | 4 ++++ tests/.snapshots/success.txt | 3 ++- tests/Unit/Plugins/Tia/ReadCapture.php | 15 +++++++++++++++ tests/Visual/Parallel.php | 2 +- 6 files changed, 24 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index cfbd4cac..1a518200 100644 --- a/composer.json +++ b/composer.json @@ -65,6 +65,7 @@ "pestphp/pest-plugin-phpstan": "^5.3.1", "pestphp/pest-plugin-rector": "^5.0.6", "pestphp/pest-plugin-type-coverage": "^5.1.0", + "phpstan/phpstan": "^2.3.4 <2.3.6", "psy/psysh": "^0.12.24" }, "minimum-stability": "dev", diff --git a/src/Expectations/HigherOrderExpectation.php b/src/Expectations/HigherOrderExpectation.php index 12c5decb..14e2a1fa 100644 --- a/src/Expectations/HigherOrderExpectation.php +++ b/src/Expectations/HigherOrderExpectation.php @@ -71,7 +71,7 @@ final class HigherOrderExpectation } /** - * @param Closure(Expectation): void $expectation + * @param Closure(Expectation|EachExpectation): void $expectation * @return HigherOrderExpectation */ public function scoped(Closure $expectation): self diff --git a/src/Plugins/Tia/ReadCapture.php b/src/Plugins/Tia/ReadCapture.php index 471b5d4a..4cf38fcb 100644 --- a/src/Plugins/Tia/ReadCapture.php +++ b/src/Plugins/Tia/ReadCapture.php @@ -197,6 +197,10 @@ final class ReadCapture */ public function stream_lock(int $operation): bool { + if (($operation & ~LOCK_NB) === 0) { + return true; + } + return $this->forward('stream_lock', fn (mixed $resource): bool => flock($resource, $operation), $operation) === true; } diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 3d20dbbf..ccef587a 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -2037,6 +2037,7 @@ ✓ the file wrapper → it is replaced while a test records and restored after it ✓ the file wrapper → it is restored when the recorder resets ✓ the file wrapper → it passes filesystem operations through while a test records + ✓ the file wrapper → it writes with LOCK_EX while a test records ✓ the file wrapper → it reports symlinks as links while a test records with dataset "a link to an existing file" ✓ the file wrapper → it reports symlinks as links while a test records with dataset "a dangling link" ✓ a wrapper already registered for file:// → it opens reads through it and still links them @@ -2388,4 +2389,4 @@ ✓ pass with dataset with ('my-datas-set-value') ✓ within describe → pass with dataset with ('my-datas-set-value') - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1703 passed (3758 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1704 passed (3760 assertions) \ No newline at end of file diff --git a/tests/Unit/Plugins/Tia/ReadCapture.php b/tests/Unit/Plugins/Tia/ReadCapture.php index 1186b915..373619ba 100644 --- a/tests/Unit/Plugins/Tia/ReadCapture.php +++ b/tests/Unit/Plugins/Tia/ReadCapture.php @@ -187,6 +187,21 @@ describe('the file wrapper', function (): void { ]); }); + it('writes with LOCK_EX while a test records', function (): void { + $path = sys_get_temp_dir().DIRECTORY_SEPARATOR.'pest-read-capture-lock-'.bin2hex(random_bytes(8)); + + try { + tiaReadCaptureLinks(function () use ($path, &$written): void { + $written = file_put_contents($path, 'locked', LOCK_EX); + }); + + expect($written)->toBe(6) + ->and(file_get_contents($path))->toBe('locked'); + } finally { + @unlink($path); + } + }); + it('reports symlinks as links while a test records', function (bool $targetExists, bool $expectedExists): void { $directory = sys_get_temp_dir().DIRECTORY_SEPARATOR.'pest-read-capture-'.bin2hex(random_bytes(8)); mkdir($directory); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 0eeb25ca..77e31c06 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -21,7 +21,7 @@ test('parallel', function () use ($run): void { $output = implode("\n", array_slice(explode("\n", (string) $output), -10)); $profileOutput = $run('tests/Fixtures/Suites/SuccessOnly.php', '--profile'); - $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 29 skipped, 1674 passed (3680 assertions)'; + $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 29 skipped, 1675 passed (3682 assertions)'; expect($output) ->toContain("Tests: {$expected}")