If you are upgrading from v5.3.6, the next patch release fixes a crash that specifically bites PHP 8.5 users: whenever Pest's TIA recording was active, any file_put_contents(..., LOCK_EX) executed inside a test aborted with a ValueError. The culprit was a courtesy check PHP extends to stream wrappers — a "do you support locking?" probe — being forwarded to the real flock() call, which no longer tolerates it. Pest's file wrapper now answers the probe itself and only forwards genuine lock operations. It is a drop-in patch: no API, configuration, or workflow changes.
What broke on PHP 8.5
When TIA records — the instrumentation that captures which files each test touches, and the layer behind features like type coverage — Pest temporarily replaces the file:// protocol handler with its ReadCapture stream wrapper. Every filesystem operation is passed through to the real stream while Pest captures what each test reads.
Userland stream wrappers that want to support flock()-style locking implement a stream_lock() method. The subtle part: before PHP takes a lock on behalf of a LOCK_EX write, it first asks the wrapper whether locking is supported at all by calling stream_lock(0). Operation 0 is a probe, not a lock request.
ReadCapture::stream_lock() forwarded that 0 straight through to flock() on the real stream:
// Before: even the probe reached the real stream
return $this->forward('stream_lock', fn (mixed $resource): bool => flock($resource, $operation), $operation) === true;
On PHP 8.5, flock() rejects 0 as an operation and throws a ValueError. So code like this would error out whenever recording was active, for instance during a run with type coverage:
it('writes an import lock file', function () {
$path = sys_get_temp_dir().'/import.lock';
file_put_contents($path, 'busy', LOCK_EX); // ValueError on PHP 8.5
expect(file_get_contents($path))->toBe('busy');
});
Any tested code that uses LOCK_EX for atomic or contended writes — cache stores, flock-based mutexes, safe log appends — tripped over the same wire.
The fix: answer the probe, forward real locks
The patched stream_lock() recognizes the probe and answers it directly:
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;
}
LOCK_NB is only a modifier flag that makes a lock non-blocking; on its own it is not a lock request. If stripping it leaves 0, no LOCK_SH, LOCK_EX, or LOCK_UN bit was requested — that is PHP's probe, and the wrapper now simply answers true: "yes, locking is supported." PHP then follows up with the genuine stream_lock(LOCK_EX) call, which is still forwarded to flock() on the underlying stream exactly as before. Real locks — exclusive, shared, non-blocking, unlock — behave precisely as they did in v5.3.6.
Why it matters
First, it turns a hard failure into a pass on PHP 8.5. A single LOCK_EX write anywhere in exercised code was enough to error the test, and the resulting ValueError pointed at flock() deep inside Pest's wrapper rather than at anything you wrote — a genuinely confusing stack trace.
Second, behavior parity. Answering the probe with true means PHP actually performs the requested lock on the real stream, which is exactly what happens when Pest's wrapper is not installed. Tests now observe the same locking semantics as the production code paths they exercise.
The regression test added alongside the fix demonstrates this end to end: it calls file_put_contents($path, 'locked', LOCK_EX) while a test records, then asserts both the byte count and the file contents. Without the fix it fails on PHP 8.5.12 with the ValueError; with it, the write lands and the lock is taken on the real file. The ReadCapture test suite passes with all 18 tests.
Upgrade impact
This is a patch-level change with no migration steps:
- No public API, configuration, or expectation syntax changes — update and move on.
- On PHP versions before 8.5 nothing changes for you in practice: real lock operations were forwarded then exactly as they are now, and only the probe path behaves differently.
- On PHP 8.5,
file_put_contents(..., LOCK_EX)— and anything else that triggers PHP's lock path through the wrapper — works again while TIA records.
The diff also carries two pieces of housekeeping, neither of which requires action: the HigherOrderExpectation::scoped() docblock now also accepts EachExpectation (a type-hint-only change with no runtime effect), and Pest's own development dependencies add an upper bound of < 2.3.6 on phpstan/phpstan to keep static analysis stable. Your own composer.json is unaffected.
Once the release is out, upgrade as usual:
composer update pestphp/pest
Takeaways
file_put_contents(..., LOCK_EX)inside tests no longer throws aValueErrorwhile Pest's TIA recording is active on PHP 8.5.- The
ReadCapturewrapper now answers PHP'sstream_lock(0)support probe itself; genuineLOCK_SH/LOCK_EX/LOCK_UNoperations still hit the real filesystem viaflock(). - Behavior on PHP versions before 8.5 is unchanged, and there are no API or configuration changes — a plain patch upgrade from v5.3.6.
- If your PHP 8.5 type-coverage runs were dying with a
ValueErrorfromflock(), this is the fix you were waiting for.