PHPackages                             cemerson/session - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cemerson/session

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cemerson/session
================

Ultra-simple session abstraction for PHP 7, allowing developers to properly mock session related code

v1.2(3y ago)16.4kMITPHPPHP ^7.0 | ^8.0

Since Oct 20Pushed 3y ago1 watchersCompare

[ Source](https://github.com/chrisemerson/session)[ Packagist](https://packagist.org/packages/cemerson/session)[ RSS](/packages/cemerson-session/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (4)Used By (0)

Session
=======

[](#session)

You can use this library to help unit test applications that have a reliance on the session in some way.

Rationale
---------

[](#rationale)

Unit tests are better when they are completely isolated from the environment in which they are run, and don't ever access parts of that environment such as databases, file system, network sockets or even the current time.

It is deliberately ultra-simple, with no frills, containing just enough to achieve the required results without any added complexity.

Installing
----------

[](#installing)

Session requires PHP 7. Install via composer:

```
composer require cemerson/session

```

Usage
-----

[](#usage)

Whenever you have a class that needs to access the session, don't use the `$_SESSION` global in PHP. Instead, hint for and inject the `Session` interface from this library, and use the methods on that to manipulate session data.

In production, you can set up your dependency injection container to inject the provided `DefaultPHPSession` class to manipulate the default PHP `$_SESSION` global.

```
