Problem/Motivation

\Drupal\Tests\media\Kernel\MediaSourceTest::createMediaTypeViaForm causes deprecations on PHP 8.5 because it doesn't set up entities correctly.

Steps to reproduce

Run \Drupal\Tests\media\Kernel\MediaSourceTest::createMediaTypeViaForm on PHP 8.5

Proposed resolution

Add an ID to the media type in the test.

Remaining tasks

User interface changes

None

Introduced terminology

N/a

API changes

None

Data model changes

None

Release notes snippet

N/a

Issue fork drupal-3556717

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

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
Issue tags: +PHP 8.5
dcam’s picture

Status: Needs review » Needs work

Before the fix, executing the test resulted in four deprecations:

laptop:~/drupal_core$ phpunit core/modules/media/tests/src/Kernel/MediaSourceTest.php
PHPUnit 11.5.42 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.5.0RC3
Configuration: /var/www/html/phpunit.xml

........DD                                                        10 / 10 (100%)

Time: 00:11.784, Memory: 6.00 MB

2 tests triggered 4 PHP deprecations:

1) /var/www/html/core/lib/Drupal/Core/Entity/EntityFieldManager.php:356
Using null as an array offset is deprecated, use an empty string instead

Triggered by:

* Drupal\Tests\media\Kernel\MediaSourceTest::testDifferentSourceFieldDisplays
  /var/www/html/core/modules/media/tests/src/Kernel/MediaSourceTest.php:616

* Drupal\Tests\media\Kernel\MediaSourceTest::testHiddenSourceField
  /var/www/html/core/modules/media/tests/src/Kernel/MediaSourceTest.php:637

2) /var/www/html/core/modules/field/src/Hook/FieldHooks.php:229
Using null as an array offset is deprecated, use an empty string instead

Triggered by:

* Drupal\Tests\media\Kernel\MediaSourceTest::testDifferentSourceFieldDisplays
  /var/www/html/core/modules/media/tests/src/Kernel/MediaSourceTest.php:616

* Drupal\Tests\media\Kernel\MediaSourceTest::testHiddenSourceField
  /var/www/html/core/modules/media/tests/src/Kernel/MediaSourceTest.php:637

3) /var/www/html/core/lib/Drupal/Core/Entity/EntityFieldManager.php:372
Using null as an array offset is deprecated, use an empty string instead

Triggered by:

* Drupal\Tests\media\Kernel\MediaSourceTest::testDifferentSourceFieldDisplays
  /var/www/html/core/modules/media/tests/src/Kernel/MediaSourceTest.php:616

* Drupal\Tests\media\Kernel\MediaSourceTest::testHiddenSourceField
  /var/www/html/core/modules/media/tests/src/Kernel/MediaSourceTest.php:637

4) /var/www/html/core/lib/Drupal/Core/Entity/EntityFieldManager.php:374
Using null as an array offset is deprecated, use an empty string instead

Triggered by:

* Drupal\Tests\media\Kernel\MediaSourceTest::testDifferentSourceFieldDisplays
  /var/www/html/core/modules/media/tests/src/Kernel/MediaSourceTest.php:616

* Drupal\Tests\media\Kernel\MediaSourceTest::testHiddenSourceField
  /var/www/html/core/modules/media/tests/src/Kernel/MediaSourceTest.php:637

Afterward there were no deprecations. I double-checked the deprecation backtraces and verified that they're all due to missing bundle IDs. I really wish we could add parameter type hints to EntityFieldManager::getFieldDefinitions(). /sigh

But this needs a code style change to avoid conflicting with Drupal.Array.Array.LongLineDeclaration which is in an RTBC MR.

r_mahi’s picture

Hi, I’m new to Drupal contribution. I can’t see the Join group or Assign to me option yet. Could someone please add me to the Drupal core contributors group? My username is r_mahi.

dcam’s picture

@r_mahi please read https://www.drupal.org/community/contributor-guide/contribution-areas/core. In particular there is a link to the Drupal #contribute Slack channel. I encourage you to seek assistance there for getting started. Right now Drupal is in the middle of transitioning from its custom issue queue to GitLab. This comes with particular challenges when learning how and where to do things. Putting that information into an issue comment isn't appropriate. It would be best if you could use Slack to communicate directly with other contributors for assistance.

alexpott’s picture

Status: Needs work » Needs review

As pointed out in the MR comments - this line does not fail the Drupal.Array.Array.LongLineDeclaration rule and this code is already checked by said rule.

alexpott’s picture

Well not sure the code is checked... but the code does not fail the rule so my point still stands.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Updated my ddev to 8.5.0RC3 and ran testDifferentSourceFieldDisplays which has createMediaTypeViaForm() and got
1 test triggered 4 PHP deprecations:

Applied the MR.

Re-ran same exact test and got 0 deprecations.

LGTM

  • catch committed d37c9dfc on 11.3.x
    Issue #3556717 by alexpott, dcam: Fix \Drupal\Tests\media\Kernel\...

  • catch committed b9a6a354 on 11.x
    Issue #3556717 by alexpott, dcam: Fix \Drupal\Tests\media\Kernel\...
catch’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked to 11.3.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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