test: Add unit tests for Session FileHandler - #10435
Open
gr8man wants to merge 5 commits into
Open
Conversation
gr8man
force-pushed
the
feature/session-file-handler-tests
branch
from
July 31, 2026 20:19
c95820f to
5a6106e
Compare
gr8man
force-pushed
the
feature/session-file-handler-tests
branch
from
July 31, 2026 20:33
ff3a113 to
e4a9039
Compare
gr8man
force-pushed
the
feature/session-file-handler-tests
branch
from
July 31, 2026 20:43
a6c9a5e to
7aad5ac
Compare
There was a problem hiding this comment.
Pull request overview
Adds unit tests and failure-injection helpers for the Session FileHandler.
Changes:
- Covers constructor, file operations, cleanup, and failure paths.
- Adds configurable stream and close-failure test doubles.
- Assumed
developbase; focused tests were not run.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
tests/system/Session/Handlers/FileHandlerTest.php |
Adds comprehensive handler tests. |
tests/_support/Session/FileHandlerCloseFail.php |
Simulates failed session closing. |
tests/_support/Session/FaultyStream.php |
Simulates stream operation failures. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+27
to
+31
| public $context; | ||
| private static bool $failLock = false; | ||
| private static bool $failRead = false; | ||
| private static bool $failWrite = false; | ||
| private $stream; |
| ini_set('session.sid_bits_per_character', $this->originalSidBits); | ||
| ini_set('session.sid_length', $this->originalSidLength); | ||
|
|
||
| FaultyStream::reset(); |
Comment on lines
+111
to
+129
| * @return array<string, int> | ||
| */ | ||
| public function url_stat(): array | ||
| { | ||
| return [ | ||
| 'dev' => 0, | ||
| 'ino' => 0, | ||
| 'mode' => 0o100600, | ||
| 'nlink' => 1, | ||
| 'uid' => 0, | ||
| 'gid' => 0, | ||
| 'rdev' => 0, | ||
| 'size' => 5, | ||
| 'atime' => time(), | ||
| 'mtime' => time(), | ||
| 'ctime' => time(), | ||
| 'blksize' => -1, | ||
| 'blocks' => -1, | ||
| ]; |
| { | ||
| $dir = $this->tempPath . '/readonly'; | ||
| mkdir($dir, 0700); | ||
| chmod($dir, 0555); |
| { | ||
| $dir = $this->tempPath . '/unreadable'; | ||
| mkdir($dir, 0700); | ||
| chmod($dir, 0000); |
Comment on lines
+67
to
+69
| public function stream_write(string $data): false|int | ||
| { | ||
| return self::$failWrite ? false : fwrite($this->stream, $data); |
gr8man
force-pushed
the
feature/session-file-handler-tests
branch
from
August 10, 2026 22:37
857e85c to
99bb18a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Suppressed comments (3)
tests/_support/Session/FileHandlerCloseFail.php:28
- Returning
falsewithout performing the parent's cleanup leaves the session file open and locked. The corresponding destroy test then relies on POSIX's ability to unlink an open file; on Windowsdestroy()returnsfalsebecause the open file cannot be deleted. Close the resource normally, then report failure so the fallback branch remains exercised portably.
return false;
tests/system/Session/Handlers/FileHandlerTest.php:242
- The OS requirement does not exclude a root test process. Under root, a
0555directory is still writable, soopen()succeeds and this expected-exception test fails (a common case in containers). Skip when the permission change cannot make the directory non-writable, or use a deterministic filesystem double.
chmod($dir, 0555);
tests/system/Session/Handlers/FileHandlerTest.php:534
- A root process can still open a
0000directory, so on root-based containersgc()scans this empty directory and returns0rather thanfalse. The Linux/macOS attribute does not guard that case; verify thatopendir()actually fails and skip otherwise, or use a deterministic failure double.
chmod($dir, 0000);
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
gr8man
force-pushed
the
feature/session-file-handler-tests
branch
from
August 12, 2026 11:28
2d2f278 to
783396f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds unit tests for
system/Session/Handlers/FileHandler.php, reaching 100%statement and method coverage. No production code changed.
Checklist: