Skip to content

fix(Session): clear session data on destroy in testing environment#10342

Open
gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:fix/session-destroy-testing
Open

fix(Session): clear session data on destroy in testing environment#10342
gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:fix/session-destroy-testing

Conversation

@gr8man

@gr8man gr8man commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Description
In the testing environment, Session::destroy() returned early without calling session_destroy(). While avoiding raw PHP session functions in CLI/testing is expected, doing nothing meant that the mock session data stored in the $_SESSION superglobal remained completely intact. This caused session state to leak between test cases, leading to test pollution.

This PR addresses the issue by resetting the $_SESSION array ($_SESSION = []) when destroy() is called under the testing environment. A unit test has also been added to verify this behavior.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant