PHPUnit 7

February 2, 2018

The PHPUnit development team announces the immediate availability of PHPUnit 7. This release adds new features, changes and removes existing features, and fixes bugs.

A detailed list of changes is available here.

PHPUnit now requires PHP 7.1 (or newer)

Active support for PHP 7.0 by the PHP project ended on December 3, 2017. The only actively supported versions of PHP as of February 2, 2018 are PHP 7.1 and PHP 7.2.

PHPUnit now uses (more) PHP 7 syntax

The first lines of code for PHPUnit were written more than sixteen years ago, back when PHP 4 was the "latest and greatest". In order to keep PHPUnit compatible with new versions of PHP and to make new features possible, the codebase of PHPUnit needs constant modernization.

It has cost Sebastian Bergmann thousands of hours to develop, test, and support PHPUnit.

With this new release out, perhaps now it is the time to contribute to PHPUnit's development or show your appreciation for Sebastian's work.

A lot of time and effort went into the development of PHPUnit to make better use of syntax features such as scalar type declarations and return type declarations, for instance, that were introduced in PHP 7. And quite a few methods that can raise exceptions were missing @throws annotations, there were now added to the documentation of those methods.

Backwards Compatibility Issues

While the aforementioned changes make PHPUnit's code easier to read and more robust to work on, they come at the price of backward compatibility breaks.

  • If you implement an interface provided by PHPUnit, for instance PHPUnit\Framework\TestListener, then you may need to update the signatures of your methods.
  • If you overwrite a method provided by PHPUnit, for instance a method of PHPUnit\Framework\TestCase, then you may need to update the signatures of your methods.
  • PhpStorm currently reports violations for unhandled exceptions raised by PHPUnit's assertion methods. JetBrains is aware of this and they are working on a solution.
  • The PHPUnit\Framework\BaseTestListener class has been removed, it was deprecated since PHPUnit 6.4. Please use the PHPUnit\Framework\TestListenerDefaultImplementation instead.
  • The @scenario annotation is no longer an alias for @test, it no longer has any effect.
  • The PHPUnit\Framework\TestCase::prepareTemplate() template method has been removed.

Looking Forward

The following methods do not have a return value and should therefore have a void return type declaration:

  • PHPUnit\Framework\TestCase::setUpBeforeClass()
  • PHPUnit\Framework\TestCase::setUp()
  • PHPUnit\Framework\TestCase::assertPreConditions()
  • PHPUnit\Framework\TestCase::assertPostConditions()
  • PHPUnit\Framework\TestCase::tearDown()
  • PHPUnit\Framework\TestCase::tearDownAfterClass()
  • PHPUnit\Framework\TestCase::onNotSuccessfulTest()

These methods will have a void return type declaration in PHPUnit 8. Please declare your methods that overwrite the above mentioned methods void now so you are not affected by this backward compatibility break.

PHPUnit now has a modern documentation toolchain

The documentation for PHPUnit has been migrated from DocBook to reStructuredText and is now hosted on phpunit.readthedocs.io. Details on the new locations can be found here.

Getting PHPUnit 7

We distribute a PHP Archive (PHAR) that contains everything you need in order to use PHPUnit. Alternatively, you may use Composer to download and install PHPUnit as well as its dependencies.

Here is a tutorial that gets you started.

Supported Versions

Detailed information on supported versions of PHPUnit is available here. Below is a summary as of February 2, 2018:

  • PHPUnit 7 receives bug fixes until February 7, 2020
  • PHPUnit 6 receives bug fixes until February 8, 2019
  • PHPUnit 5 has reached its End of Life on February 2, 2018 and no longer receives bug fixes