Skip to content

test: Add unit tests for Session FileHandler - #10435

Open
gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:feature/session-file-handler-tests
Open

test: Add unit tests for Session FileHandler#10435
gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:feature/session-file-handler-tests

Conversation

@gr8man

@gr8man gr8man commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Description
Adds unit tests for system/Session/Handlers/FileHandler.php, reaching 100%
statement and method coverage. No production code changed.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@github-actions github-actions Bot added the testing Pull requests that changes tests only label Jul 31, 2026
@gr8man
gr8man force-pushed the feature/session-file-handler-tests branch from c95820f to 5a6106e Compare July 31, 2026 20:19
@github-actions github-actions Bot removed the testing Pull requests that changes tests only label Jul 31, 2026
@gr8man
gr8man force-pushed the feature/session-file-handler-tests branch from ff3a113 to e4a9039 Compare July 31, 2026 20:33
@github-actions github-actions Bot added the testing Pull requests that changes tests only label Jul 31, 2026
@gr8man
gr8man force-pushed the feature/session-file-handler-tests branch from a6c9a5e to 7aad5ac Compare July 31, 2026 20:43
@michalsn
michalsn requested a balanced review from Copilot August 10, 2026 07:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 develop base; 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Pull requests that changes tests only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants