Problem/Motivation

Currently, running the phpunit job in at least some contrib modules will print the following warning several times:

PHP Warning: Undefined array key 0 in /builds/project/search_api/web/core/lib/Drupal/Core/Test/PhpUnitTestDiscovery.php on line 410

(Line number varies by Drupal version, of course, but that’s the one in 11.4.x dev.)

It seems that in \Drupal\Core\Test\PhpUnitTestDiscovery::getTestClassInfo() even though there is an explicit check whether $groups is empty, it can then happen that $groups[0] is not set. My conclusion would be that $groups is not necessarily a list but could be an associative array.

Examples can be seen here and here.

Steps to reproduce

Run the phpunit job of a contrib module. It might only produce the error when test classes use the @group annotation instead of the Group attribute but that is simply a guess.

Proposed resolution

Maybe use array_first($groups) instead of $groups[0]? (It’s part of symfony/polyfill-php85 so should be fine to use even though we don’t require PHP 8.5 yet.)

Remaining tasks

  • Create MR.
  • Discuss solution.
  • Review MR.

User interface changes

N/A

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Issue fork drupal-3607165

Command icon 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

drunken monkey created an issue. See original summary.

drunken monkey’s picture

Assigned: drunken monkey » Unassigned
Status: Active » Needs review

My suggested very simple solution is in this MR, but there might of course be more to it than that. I’m not at all familiar with this code so can’t say.

smustgrave’s picture

Version: 11.4.x-dev » main
Status: Needs review » Needs work

Issue would have to land in main first but probably will need test coverage

mondrake’s picture

The problem is in the tests:

/**
 * Tests the "Date-based boosting" processor.
 *
 * @group search_api
 *
 * @coversDefaultClass \Drupal\search_api\Plugin\search_api\processor\DateFieldBoost
 */
#[RunTestsInSeparateProcesses]
class DateFieldBoostTest extends ProcessorTestBase {

won't work because since PHPUnit 10, if you add at least one attribute then the annotations are discarded. So the bug appears because there's no group metadata detected for the test. So yes maybe we could add some protection to prevent the warning but the array would still be empty.

mondrake’s picture

mondrake’s picture

BTW, it looks like Drupal core own PHPStan rules are not included in contrib. Those would report the above as errors. Will ask in Slack #gitlab.

mondrake’s picture

Issue tags: +run-tests.sh