2

Quoting https://phpunit.readthedocs.io/en/9.5/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices , "By default, PHPUnit converts PHP errors, warnings, and notices that are triggered during the execution of a test to an exception". Bearing that in mind, here's my unit test:

<?php

class DemoTest extends PHPUnit\Framework\TestCase
{
    public function testDemo()
    {
        try {
            trigger_error('zzz', E_USER_DEPRECATED);
        } catch (\Throwable $e) {}
    }
}

When I run vendor/bin/phpunit on that with PHPUnit 9.4.0 on PHP 8.0.9 I get the following (irrelevant parts of the output have been removed):

PHPUnit 9.4.0 by Sebastian Bergmann and contributors.

R                                                                   1 / 1 (100%)

When I run vendor/bin/phpunit on that on PHPUnit 9.4.0 on PHP 8.1.0 I get the following:

Deprecated: PHPUnit\Runner\DefaultTestResultCache implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in C:\path\to\code\vendor\phpunit\phpunit\src\Runner\DefaultTestResultCache.php on line 34
PHPUnit 9.4.0 by Sebastian Bergmann and contributors.

R                                                                   1 / 1 (100%)

ie. in PHP 8.1 it's like I'm getting a full dump of the Throwable, stack trace included, whereas I'm not getting that in PHP 8.0.

Any ideas? I don't want to see the error in the output and, if an exception isn't being thrown, then $this->expectException('PHPUnit\\Framework\\Error\\Deprecated') isn't gonna work for me either

neubert
  • 15,947
  • 24
  • 120
  • 212
  • Superficially, one might think that upgrading to PHPUnit 9.5 would do the trick but I'm having a very similar issue with that version: https://stackoverflow.com/q/70321543/569976 Only difference is that in 9.5 I get this behavior in _every_ version of PHP instead of _just_ PHP 8.1.0. – neubert Dec 12 '21 at 06:52

1 Answers1

9

This is an incompatibility of PHPUnit with PHP 8.1 and has already been fixed a while back in 9.5.5, so you need to update.

9.4 is not a supported version anymore.

Tobias K.
  • 2,997
  • 2
  • 12
  • 29