2

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

2 Answers 2

3

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:

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.

2

I see similar behavior when I haven't installed PHPUnit and use drupal-check to perform the static code analysis on a module. The tests provided by Drupal modules/core require PHPUnit to be run, so when it's missing it seems logical drupal-check reports warnings/errors.

According to the documentation of mglaman/drupal-check you should be able to exclude directories (e.g., */tests/*). However, when you are running this tool you might want to add PHPUnit to your development stack. One way to do this is to add drupal/core-dev by running composer require --dev drupal/core-dev.

Another option is to use the contributed Upgrade Status module, which provides extra functionality on top of drupal-check.

1
  • As a side note, I've written a small article around using these kind of quality assurance tools: sicse.dev/blog/…
    – Watergate
    May 14, 2020 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.