Skip to content

Conversation

@binaryfire
Copy link
Contributor

When using withSession() in tests with cache-based session drivers (redis, memcached, etc.), the startSession() method would fail because start() was called without first setting a session ID. CacheBasedSessionHandler has strict string type hints on its read/write methods, so passing null caused a TypeError.

In production, StartSession middleware calls setId($cookie) before start(), which generates an ID if the cookie is null. The test trait now mirrors this behavior by calling setId(null) before start() when no ID exists.

Fixes: TypeError when using withSession() with non-array session drivers

When using withSession() in tests with cache-based session drivers
(redis, memcached, etc.), the startSession() method would fail because
start() was called without first setting a session ID. CacheBasedSessionHandler
has strict string type hints on its read/write methods, so passing null
caused a TypeError.

In production, StartSession middleware calls setId($cookie) before start(),
which generates an ID if the cookie is null. The test trait now mirrors
this behavior by calling setId(null) before start() when no ID exists.

Fixes: TypeError when using withSession() with non-array session drivers
@albertcht albertcht added the bug Something isn't working label Dec 27, 2025
The return type `static` is already enforced by PHP's type system,
making these tests unnecessary.
@albertcht albertcht merged commit 40bdf55 into hypervel:main Dec 27, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants