PHPackages                             battis/phpunit-sessions - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. battis/phpunit-sessions

ActiveLibrary[Testing &amp; Quality](/categories/testing)

battis/phpunit-sessions
=======================

Extension to PHPUnit to handle PHP sessions more gracefully

v0.1.4(2y ago)023GPL-3.0PHPCI failing

Since Nov 28Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/battis/phpunit-extensions.sessions)[ Packagist](https://packagist.org/packages/battis/phpunit-sessions)[ RSS](/packages/battis-phpunit-sessions/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (6)Used By (0)

PHPUnit Sessions
================

[](#phpunit-sessions)

[![codecov](https://camo.githubusercontent.com/4636765f3b82d251602981b1135ff94adcb96e252034d06db2351ed6d4e66d67/68747470733a2f2f636f6465636f762e696f2f67682f6261747469732f706870756e69742d73657373696f6e732f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d41424b34414a4c594f30)](https://codecov.io/gh/battis/phpunit-sessions)

Extension to PHPUnit to handle PHP sessions more gracefully

Install
-------

[](#install)

```
composer require --dev battis/phpunit-sessions
```

Configure
---------

[](#configure)

In `phpunit.xml`:

```

  ...

```

In `tests/bootstrap.php`:

```
require_once __DIR__ . "/../vendor/autoload.php";

Battis\PHPUnit\Sessions\Bootstrap::execute();
```

How it works
------------

[](#how-it-works)

Fundamentally, there are two problems with working with sessions and cookies when testing in PHP:

1. PHPUnit runs from the CLI, so `$_COOKIES` and `$_SESSIONS` don't exist.
2. PHPUnit starts output before any of the code under test that works with sessions is executed, generating errors about output being sent before headers, etc.

To address this, this extension enables an output buffer as PHPUnit starts, buffering all of the output until after the last test is run. (You lose nothing but the immediacy of the output -- you'll still see it all, but only after a heart-stopping pause.)

In addition, when the script run from the CLI, `$_SESSIONS` AND `$_COOKIES` are initialized as empty arrays which can then be manipulated as usual.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance52

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~133 days

Total

5

Last Release

733d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d0554a28104c65004c6de4d335ada25cf2763c8a9691dc5611314486d461fa4c?d=identicon)[battis](/maintainers/battis)

---

Top Contributors

[![battis](https://avatars.githubusercontent.com/u/419619?v=4)](https://github.com/battis "battis (30 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")

### Embed Badge

![Health badge](/badges/battis-phpunit-sessions/health.svg)

```
[![Health](https://phpackages.com/badges/battis-phpunit-sessions/health.svg)](https://phpackages.com/packages/battis-phpunit-sessions)
```

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4235.9M56](/packages/timacdonald-log-fake)[jasonmccreary/laravel-test-assertions

A set of helpful assertions when testing Laravel applications.

3513.9M32](/packages/jasonmccreary-laravel-test-assertions)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[typo3/testing-framework

The TYPO3 testing framework provides base classes for unit, functional and acceptance testing.

675.0M775](/packages/typo3-testing-framework)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

76460.0k15](/packages/robiningelbrecht-phpunit-pretty-print)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
