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 5mo 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 today

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

27

—

LowBetter than 47% of packages

Maintenance48

Moderate activity, may be stable

Popularity6

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

781d 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

[brianium/paratest

Parallel testing for PHP

2.5k136.1M984](/packages/brianium-paratest)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2022.6M341](/packages/drupal-core-dev)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

30314.4k7](/packages/webmozarts-strict-phpunit)

PHPackages © 2026

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