Problem/Motivation

\Drupal\Tests\PhpUnitCompatibilityTrait doesn't quite work the way it should on the latest PHPStan and PHPStan-Drupal. We get:

 ------ -----------------------------------------------------------------------------
  Line   core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php
 ------ -----------------------------------------------------------------------------
  11     Class Drupal\Tests\PhpUnitVersionDependentTestCompatibilityTrait not found.
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
 ------ -----------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------------------------------
  Line   core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php (in context of class Drupal\BuildTests\Framework\BuildTestBase)
 ------ -----------------------------------------------------------------------------------------------------------------------------
  19     Trait Drupal\Tests\PhpUnitCompatibilityTrait uses unknown trait Drupal\Tests\PhpUnitVersionDependentTestCompatibilityTrait.
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
 ------ -----------------------------------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------------------------------
  Line   core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php (in context of class Drupal\KernelTests\KernelTestBase)
 ------ -----------------------------------------------------------------------------------------------------------------------------
  19     Trait Drupal\Tests\PhpUnitCompatibilityTrait uses unknown trait Drupal\Tests\PhpUnitVersionDependentTestCompatibilityTrait.
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
 ------ -----------------------------------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------------------------------
  Line   core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php (in context of class Drupal\Tests\BrowserTestBase)
 ------ -----------------------------------------------------------------------------------------------------------------------------
  19     Trait Drupal\Tests\PhpUnitCompatibilityTrait uses unknown trait Drupal\Tests\PhpUnitVersionDependentTestCompatibilityTrait.
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
 ------ -----------------------------------------------------------------------------------------------------------------------------

 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php (in context of class Drupal\Tests\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecoratorTest)
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------
  19     Trait Drupal\Tests\PhpUnitCompatibilityTrait uses unknown trait Drupal\Tests\PhpUnitVersionDependentTestCompatibilityTrait.
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ --------------------------------------------------------------------------------------------------------------------------------------
  Line   core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php (in context of class Drupal\Tests\Component\DependencyInjection\ContainerTest)
 ------ --------------------------------------------------------------------------------------------------------------------------------------
  19     Trait Drupal\Tests\PhpUnitCompatibilityTrait uses unknown trait Drupal\Tests\PhpUnitVersionDependentTestCompatibilityTrait.
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
 ------ --------------------------------------------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php (in context of class Drupal\Tests\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumperTest)
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
  19     Trait Drupal\Tests\PhpUnitCompatibilityTrait uses unknown trait Drupal\Tests\PhpUnitVersionDependentTestCompatibilityTrait.
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ -------------------------------------------------------------------------------------------------------------------------------
  Line   core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php (in context of class Drupal\Tests\Component\Gettext\PoStreamWriterTest)
 ------ -------------------------------------------------------------------------------------------------------------------------------
  19     Trait Drupal\Tests\PhpUnitCompatibilityTrait uses unknown trait Drupal\Tests\PhpUnitVersionDependentTestCompatibilityTrait.
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
 ------ -------------------------------------------------------------------------------------------------------------------------------

 ------ ---------------------------------------------------------------------------------------------------------------------------------
  Line   core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php (in context of class Drupal\Tests\Component\Plugin\PluginManagerBaseTest)
 ------ ---------------------------------------------------------------------------------------------------------------------------------
  19     Trait Drupal\Tests\PhpUnitCompatibilityTrait uses unknown trait Drupal\Tests\PhpUnitVersionDependentTestCompatibilityTrait.
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
 ------ ---------------------------------------------------------------------------------------------------------------------------------

 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------
  Line   core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php (in context of class Drupal\Tests\Composer\Plugin\VendorHardening\VendorHardeningPluginTest)
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------
  19     Trait Drupal\Tests\PhpUnitCompatibilityTrait uses unknown trait Drupal\Tests\PhpUnitVersionDependentTestCompatibilityTrait.
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------------------------------
  Line   core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php (in context of class Drupal\Tests\UnitTestCase)
 ------ -----------------------------------------------------------------------------------------------------------------------------
  19     Trait Drupal\Tests\PhpUnitCompatibilityTrait uses unknown trait Drupal\Tests\PhpUnitVersionDependentTestCompatibilityTrait.
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
 ------ -----------------------------------------------------------------------------------------------------------------------------

This is already happening on a DrupalCI that does updates - see https://dispatcher.drupalci.org/job/drupal8_core_regression_tests/55836/...

Steps to reproduce

Checkout core 10.0.x
Run composer update
Run PHPStan

Proposed resolution

Use the same solution as vendor/symfony/phpunit-bridge/SymfonyTestsListener.php to trick PHPStan into finding the trait.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#3 2-3-interdiff.txt624 bytesalexpott
#3 3282395-3.patch1.24 KBalexpott
#2 3282395-2.patch1.24 KBalexpott

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new1.24 KB
alexpott’s picture

StatusFileSize
new1.24 KB
new624 bytes

Lol fixed coding standards.

alexpott’s picture

The

Running PHPStan on *all* files.
 ------ ---------------------------------------------------------------------- 
  Line   core/modules/comment/comment.module                                   
 ------ ---------------------------------------------------------------------- 
         Ignored error pattern #^Call to deprecated constant REQUEST_TIME\:    
         Deprecated in drupal\:8\.3\.0 and is removed from drupal\:10\.0\.0\.  
         Use \\Drupal\:\:time\(\)\->getRequestTime\(\); $# in path             
         /var/www/html/core/modules/comment/comment.module was not matched in  
         reported errors.                                                      
 ------ ---------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------- 
  Line   core/modules/history/history.module                                   
 ------ ---------------------------------------------------------------------- 
  117    Ignored error pattern #^Call to deprecated constant REQUEST_TIME\:    
         Deprecated in drupal\:8\.3\.0 and is removed from drupal\:10\.0\.0\.  
         Use \\Drupal\:\:time\(\)\->getRequestTime\(\); $# in path             
         /var/www/html/core/modules/history/history.module is expected to      
         occur 3 times, but occurred only 2 times.                             
 ------ ---------------------------------------------------------------------- 

 [ERROR] Found 2 errors 

errors on the composer update build are interesting. I do not get them locally and they are incorrect.... for some reason on DrupalCI PHPStan is missing the use of REQUEST_TIME in the define() calls at the top of comment.module and history.module.

Hmmm....

mondrake’s picture

alexpott’s picture

@mondrake this is a better fix for part of #3282315: Update phpstan/phpstan and mglaman/phpstan-drupal to latest versions. We could land this and then solve the REQUEST_TIME stuff and actually do the update in the other issue.

mallezie’s picture

Status: Needs review » Reviewed & tested by the community

This looks good to me. Simple trick, and bot agrees. And this unblocks the upgrade (which improves the performance of running phpstan)

  • catch committed a40e843 on 10.0.x
    Issue #3282395 by alexpott, mallezie: Latest versions of PHPStan and...

  • catch committed 7d15118 on 9.4.x
    Issue #3282395 by alexpott, mallezie: Latest versions of PHPStan and...
  • catch committed 5a802d5 on 9.5.x
    Issue #3282395 by alexpott, mallezie: Latest versions of PHPStan and...
catch’s picture

Version: 10.0.x-dev » 9.4.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 10.0.x, cherry-picked to 9.5.x and 9.4.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.