PHPUnit errors occur when running drupal-check I am trying to run drupal-check on the social_auth_dropbox module (vendor/bin/drupal-check -ad web/modules/contrib/social_auth_dropbox) and I'm facing this error:

Warning: Class 'PHPUnit\Framework\MockObject\Matcher\InvokedRecorder' not found in /Users/Documents/sample/my_site_name_dir/web/core/tests/bootstrap.php on line 197
0/11 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0%
Fatal error: Declaration of Drupal\Tests\BrowserTestBase::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in /Users/Documents/sample/my_site_name_dir/web/core/tests/Drupal/Tests/BrowserTestBase.php on line 39
The first warning could make you think PHPUnit isn't installed, but since drupal-check is able to tell you that the declaration of Drupal\Tests\BrowserTestBase::setUp() is not compatible with the declaration of PHPUnit\Framework\TestCase::setUp(), that is not the case. If PHPUnit weren't installed, drupal-check would report more missing classes.

PHPUnit is installed, but it's version 9.0.0 or higher version, where:


The PHPUnit\Framework\MockObject\Matcher\InvokedRecorder class doesn't exist (but it's defined in PHPUnit 8.0.0)
The PHPUnit\Framework\TestCase::setUp() method is defined as setUp(): void, while PHPUnit 7 defines it as setUp() (The difference is enough to cause the fatal error.)


So, in short:


The installed version of PHPUnit is at least 9
The Drupal version you installed still requires PHPUnit 7


Notice that, so far, only Drupal 9.x has been updated to PHPUnit 8, and in future it will support PHPUnit 9. Previous Drupal versions still need PHPUnit 7, and eventually they will be updated to support PHPUnit 8.