PHPackages                             sanmai/phpunit-legacy-adapter - 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. sanmai/phpunit-legacy-adapter

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

sanmai/phpunit-legacy-adapter
=============================

PHPUnit Legacy Versions Adapter

8.2.2(3y ago)388.2k↓23.7%120Apache-2.0PHPCI passing

Since Aug 21Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/sanmai/phpunit-legacy-adapter)[ Packagist](https://packagist.org/packages/sanmai/phpunit-legacy-adapter)[ RSS](/packages/sanmai-phpunit-legacy-adapter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (3)Versions (10)Used By (20)

PHPUnit Legacy Versions Adapter
-------------------------------

[](#phpunit-legacy-versions-adapter)

As you're here, you are probably well aware that PHPUnit 8+ requires [common template methods](https://phpunit.readthedocs.io/en/latest/fixtures.html)like `setUp()` or `tearDown()` to have a `void` return type declaration, which methods naturally break anything below PHP 7.1.

Although it is not a big deal to automatically update your code to use these return type declaration with help from the likes of [PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) or [Rector](https://github.com/rectorphp/rector/blob/master/docs/rector_rules_overview.md#phpunit), it might become a problem if, for whatever unfortunate (but, hopefully, lucrative) reasons, you have to ensure your code is working under PHP 7.0 or PHP 5.6, all the while wanting using the best world can give you in the more-less recent versions of PHPUnit.

In this case, you'll have two problems. One, newer versions of PHPUnit [do not have old assertions](https://thephp.cc/news/2019/02/help-my-tests-stopped-working), but you can find a way around this, and another, as mentioned, newer versions of PHPUnit require `void` return type declarations for the convenient template methods, and then you're stuck because rewriting tests to work without these template methods is a major pain and might be impossible even. And then this small library comes to save your day!

```
composer require --dev sanmai/phpunit-legacy-adapter:"^6.4 || ^8.2.1"

```

### How to use

[](#how-to-use)

First, update your tests to extend from `\LegacyPHPUnit\TestCase` instead of `\PHPUnit\Framework\TestCase`:

```
- class MyTest extends \PHPUnit\Framework\TestCase
+ class MyTest extends \LegacyPHPUnit\TestCase
```

Then, where you had to use `setUp(): void` template method, use `doSetUp()` method, omitting all any any return types in a fully backward-compatible way.

```
- protected function setUp(): void
+ protected function doSetUp()
```

There are similar replacements for most other template method:

```
- public static function setUpBeforeClass(): void
+ public static function doSetUpBeforeClass()
```

```
- public static function tearDownAfterClass(): void
+ public static function doTearDownAfterClass()
```

```
- protected function setUp(): void
+ protected function doSetUp()
```

```
- protected function tearDown(): void
+ protected function doTearDown()
```

```
- protected function assertPreConditions(): void
+ protected function doAssertPreConditions()
```

```
- protected function assertPostConditions(): void
+ protected function doAssertPostConditions()
```

### Reference

[](#reference)

MethodReplacement`setUpBeforeClass(): void``doSetUpBeforeClass()``tearDownAfterClass(): void``doTearDownAfterClass()``setUp(): void``doSetUp()``tearDown(): void``doTearDown()``assertPreConditions(): void``doAssertPreConditions()``assertPostConditions(): void``doAssertPostConditions()`### Supported versions

[](#supported-versions)

- 6.x version branch supports [PHPUnit 4](https://phpunit.de/getting-started/phpunit-4.html), [PHPUnit 5](https://phpunit.de/getting-started/phpunit-5.html), and [PHPUnit 6](https://phpunit.de/getting-started/phpunit-6.html).
    - It was tested to work under PHP 5.3 - PHP 7.4.
    - [![Continuous Integration](https://github.com/sanmai/phpunit-legacy-adapter/workflows/Continuous%20Integration/badge.svg?branch=master)](https://github.com/sanmai/phpunit-legacy-adapter/workflows/Continuous%20Integration/badge.svg?branch=master)
- 8.x version branch supports [PHPUnit 7](https://phpunit.de/getting-started/phpunit-7.html), [PHPUnit 8](https://phpunit.de/getting-started/phpunit-8.html), and [PHPUnit 9](https://phpunit.de/getting-started/phpunit-9.html).
    - It was tested to work under PHP 7.1 - PHP 8.1.
    - [![Continuous Integration](https://github.com/sanmai/phpunit-legacy-adapter/workflows/Continuous%20Integration/badge.svg?branch=legacy)](https://github.com/sanmai/phpunit-legacy-adapter/workflows/Continuous%20Integration/badge.svg?branch=legacy)

Future versions will likely follow the same pattern.

### What this library does not do

[](#what-this-library-does-not-do)

Although this library solves the most annoying part of the problem, there are other parts the library was not designed to cover. For example:

- Some versions of PHPUnit allow `assertContains` to be used with strings, while other do not.
- In some versions one method is called `expectExceptionMessageRegExp`, while in others the same method is called `expectExceptionMessageMatches`.
- And so on and on.

There are polyfills for these changed methods (see below), but it should not be a big deal to write an ad hoc polyfill just for the methods you need. E.g.:

```
    public function __call($method, $args)
    {
        if ($method === 'assertStringContainsString') {
            $this->assertContains(...$args);
        }

        if ($method === 'assertIsBool') {
            $this->assertTrue(\is_bool($args[0]));
        }

        if ($method === 'expectExceptionMessageRegExp') {
            $this->expectExceptionMessageMatches(...$args);
        }

        throw new \InvalidArgumentException();
    }
```

If there are several modular (and not) multi-version polyfills for these, and other methods:

- One of the most used is one that comes with [Symfony's PHPUnit Bridge](https://github.com/symfony/phpunit-bridge). You can [check the source here](https://github.com/symfony/phpunit-bridge/tree/5.x/Legacy). Note that [it does not support inheritance](https://github.com/symfony/symfony/pull/35311) (you'll have to import the trait into every class).
- There's [`yoast/phpunit-polyfills`](https://github.com/Yoast/PHPUnit-Polyfills/).
- There's [`phpunitgoodpractices/polyfill`](https://github.com/PHPUnitGoodPractices/polyfill).

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~141 days

Recently: every ~219 days

Total

8

Last Release

1107d ago

Major Versions

6.0 → 8.12020-11-12

6.4 → 8.22020-12-11

PHP version history (2 changes)6.0PHP ^5.6 || ^7.0 &lt;7.5

6.4PHP &lt;8

### Community

Maintainers

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

---

Top Contributors

[![sanmai](https://avatars.githubusercontent.com/u/139488?v=4)](https://github.com/sanmai "sanmai (49 commits)")

---

Tags

phpunitphpunit-legacy-adapter

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/sanmai-phpunit-legacy-adapter/health.svg)

```
[![Health](https://phpackages.com/badges/sanmai-phpunit-legacy-adapter/health.svg)](https://phpackages.com/packages/sanmai-phpunit-legacy-adapter)
```

###  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)
