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