MigrateSourceTestBase::getPluginClass() finds the source plugin to test by reading the test's first #[CoversClass]. If a test has none, it falls back to the old @covers annotations:
$covers = $this->valueObjectForEvents()->metadata()->isCovers()->isClassLevel()->asArray();
Problem: PHPUnit 12 dropped annotation support and removed MetadataCollection::isCovers(). A test without #[CoversClass] errors with "Call to undefined method PHPUnit\Metadata\MetadataCollection::isCovers()".
The fallback was kept for backwards compatibility in #3543658: Migrate plugin tests using @cover annotation to indicate the plugin class block conversion to attributes when Drupal Core used PHPUnit 11.
To reproduce, remove #[CoversClass(ConfigEntity::class)] from core/modules/migrate/tests/src/Kernel/Plugin/source/ConfigEntityTest.php and run the tests. All three tests error with "Call to undefined method PHPUnit\Metadata\MetadataCollection::isCovers()".
Solution: Remove the @covers fallback, so getPluginClass() fails with "No plugin class was specified" as intended.
Issue fork drupal-3631040
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
dries commentedI created a simple MR. It's just old code that shouldn't be used anymore. I don't believe this requires a test?
Comment #4
dries commentedI forgot to mention: I searched for existing tests that need updating but couldn't find any. Nothing in Drupal Core tested this code path, which is why it broke without anyone noticing. Somewhat ironic as I was working on code coverage in #3631031: Remove coverage targets not measured by phpunit.xml.dist.
Committers: this is for main only. 11.x supports PHPUnit 11, which still supports
@covers.Comment #5
mondrakeIt probably was a mistake to rely on PHPUnit annotations to implement a discoverabilty process that is not PHPUnit related in the first place - now we expose that to the winds of changing PHPUnit logic. Which is exactly what happened here and in the earlier conversion to attributes.
Maybe we could implement an attribute of our own instead for this purpose, or other logic?
However, this issue itself should not be held on any of that IMO, could use a follow up.
Setting to RTBC even if not in NR - the cleanup is just obvious.