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.5.10 (on either PHP 8.0.9 or PHP 8.1.0) I get the following:
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.
R 1 / 1 (100%)
Deprecated: zzz in C:\path\to\code\tests\DemoTest.php on line 8
Time: 00:00.007, Memory: 6.00 MB
There was 1 risky test:
1) DemoTest::testDemo
This test did not perform any assertions
C:\path\to\code\tests\DemoTest.php:5
OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Risky: 1.
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.
Any ideas?