PHPackages                             yoast/phpunit-polyfills - 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. yoast/phpunit-polyfills

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

yoast/phpunit-polyfills
=======================

Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests

4.0.0(1y ago)18438.5M↑11.9%13[4 issues](https://github.com/Yoast/PHPUnit-Polyfills/issues)[1 PRs](https://github.com/Yoast/PHPUnit-Polyfills/pulls)20BSD-3-ClausePHPPHP &gt;=7.1CI passing

Since Oct 26Pushed 1w ago13 watchersCompare

[ Source](https://github.com/Yoast/PHPUnit-Polyfills)[ Packagist](https://packagist.org/packages/yoast/phpunit-polyfills)[ Docs](https://github.com/Yoast/PHPUnit-Polyfills)[ RSS](/packages/yoast-phpunit-polyfills/feed)WikiDiscussions 4.x Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (38)Used By (20)

PHPUnit Polyfills
=================

[](#phpunit-polyfills)

[![Version](https://camo.githubusercontent.com/0ba80bf2a89092efad808a3c38072c1b4d6ccf3303d8a2afb6b752be7fe5b1d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796f6173742f706870756e69742d706f6c7966696c6c733f6c6162656c3d737461626c65)](https://packagist.org/packages/yoast/phpunit-polyfills)[![CS Build Status](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/cs.yml/badge.svg?branch=4.x)](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/cs.yml)[![Lint Build Status](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/lint.yml/badge.svg?branch=4.x)](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/lint.yml)[![Test Build Status](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/test.yml/badge.svg?branch=4.x)](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/test.yml)[![Coverage Status](https://camo.githubusercontent.com/2b72dd23fce1742a4b36ef133e96d617480c0cf631a8315374cffb32d613d7ca/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f596f6173742f504850556e69742d506f6c7966696c6c732f62616467652e7376673f6272616e63683d342e78)](https://coveralls.io/github/Yoast/PHPUnit-Polyfills?branch=4.x)

[![Minimum PHP Version](https://camo.githubusercontent.com/e563da313abd64968bb0afe3c00e6c09dc2f6b4883c11da03000e437c54ffd00/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f796f6173742f706870756e69742d706f6c7966696c6c732f7068702e737667)](https://packagist.org/packages/yoast/phpunit-polyfills)[![License: BSD3](https://camo.githubusercontent.com/647e64b89f9115c3ff10bb80fe42193271a3920fcc5075450ae271f3133e2f0a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f596f6173742f504850556e69742d506f6c7966696c6c73)](https://github.com/Yoast/PHPUnit-Polyfills/blob/main/LICENSE)

Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests.

- [Requirements](#requirements)
- [Installation](#installation)
    - [Autoloading](#autoloading)
- [Why use the PHPUnit Polyfills?](#why-use-the-phpunit-polyfills)
    - [PHPUnit support](#phpunit-support)
- [Using this library](#using-this-library)
    - [Supported ways of calling the assertions](#supported-ways-of-calling-the-assertions)
- [Features](#features)
    - [Polyfill traits](#polyfill-traits)
    - [TestCases](#testcases)
    - [TestListener](#testlistener)
- [Frequently Asked Questions](#frequently-asked-questions)
- [Contributing](#contributing)
- [License](#license)

Requirements
------------

[](#requirements)

- PHP 7.1 or higher.
- [PHPUnit](https://packagist.org/packages/phpunit/phpunit) 7.5 - 9.x, 11.x and 12.x (automatically required via Composer).

Installation
------------

[](#installation)

To install this package, run:

```
composer require --dev yoast/phpunit-polyfills:"^4.0"
```

To update this package, run:

```
composer update --dev yoast/phpunit-polyfills --with-dependencies
```

### Autoloading

[](#autoloading)

Make sure to:

- Either use the Composer `vendor/autoload.php` file *as* your test bootstrap file;
- Or require the `vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php` file *in* your test bootstrap.

Why use the PHPUnit Polyfills?
------------------------------

[](#why-use-the-phpunit-polyfills)

This library is set up to allow for creating PHPUnit cross-version compatible tests by offering a number of polyfills for functionality which was introduced, split up or renamed in PHPUnit.

### Write your tests for PHPUnit 12.x and run them on PHPUnit 7.5 - 12.x

[](#write-your-tests-for-phpunit-12x-and-run-them-on-phpunit-75---12x)

The polyfills have been setup to allow tests to be *forward*-compatible. What that means is, that your tests can use the assertions supported by the *latest* PHPUnit version, even when running on older PHPUnit versions.

This puts the burden of upgrading to use the syntax of newer PHPUnit versions at the point when you want to *start* running your tests on a newer version. By doing so, dropping support for an older PHPUnit version becomes as straight-forward as removing it from the version constraint in your `composer.json` file.

### PHPUnit support

[](#phpunit-support)

- Releases in the `1.x` series of the PHPUnit Polyfills support PHPUnit 4.8 - 9.x.
- Releases in the `2.x` series of the PHPUnit Polyfills support PHPUnit 5.7 - 10.x.
- Releases in the `3.x` series of the PHPUnit Polyfills support PHPUnit 6.4 - 11.x (but don't support running tests on PHPUnit 10).
- Releases in the `4.x` series of the PHPUnit Polyfills support PHPUnit 7.5 - 12.x (but don't support running tests on PHPUnit 10).

Please keep in mind that the PHPUnit Polyfills provide *forward*-compatibility. This means that features which PHPUnit no longer supports in PHPUnit 10.x, like expecting PHP deprecation notices or warnings, will not be supported in the PHPUnit Polyfills 2.x series and features not supported in PHPUnit 11.x, will not be supported in the PHPUnit Polyfills 3.x series etc.

Please refer to the [PHPUnit 10 release notification](https://phpunit.de/announcements/phpunit-10.html)/[PHPUnit 10 changelog](https://github.com/sebastianbergmann/phpunit/blob/10.0.19/ChangeLog-10.0.md), [PHPUnit 11 release notification](https://phpunit.de/announcements/phpunit-11.html)/[PHPUnit 11 changelog](https://github.com/sebastianbergmann/phpunit/blob/11.0.10/ChangeLog-11.0.md) and/or the [PHPUnit 12 release notification](https://phpunit.de/announcements/phpunit-12.html)/[PHPUnit 12 changelog](https://github.com/sebastianbergmann/phpunit/blob/12.0.2/ChangeLog-12.0.md) to inform your decision on whether or not to upgrade (yet).

Using this library
------------------

[](#using-this-library)

Each of the polyfills and helpers has been setup as a trait and can be imported and `use`d in any test file which extends the PHPUnit native `TestCase` class.

If the polyfill is not needed for the particular PHPUnit version on which the tests are being run, the autoloader will automatically load an empty trait with that same name, so you can safely use these traits in tests which need to be PHPUnit cross-version compatible.

```
