Improve EntityReference/EntityReferenceFormatterTest::testLabelFormatter() to fail in an explicit way when the fix is reverted

Created on 28 June 2025, 7 days ago

Problem/Motivation

Followup from πŸ› The entity link label formatter should check URL access RTBC . As I said on that issue:

1) Drupal\Tests\field\Kernel\EntityReference\EntityReferenceFormatterTest::testLabelFormatter
Undefined array key "#plain_text"
/builds/issue/drupal-3386313/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php:426
/builds/issue/drupal-3386313/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
ERRORS!
Tests: 8, Assertions: 76, Errors: 1.
PHPUnit 9.6.23 by Sebastian Bergmann and contributors.

That's... not exactly the fail I was expecting, and it also demonstrates that the custom assertion message is not useful because it will never be displayed since it fails on an undefined array key rather than the actual assertion. It would probably be better to assert the existence of it first, I think, since (upon careful review), that is what is being added.

Wherever possible, tests should fail assertions explicitly, not fail because of PHP runtime errors.

Steps to reproduce

Revert 85dc67bf on 11.x (or 302eef63 on 10.6.x if the former does not revert cleanly) and run EntityReferenceFormatterTest::testLabelFormatter().

Proposed resolution

Improve the test to have better assertions and fail more explicitly. Some docs wouldn't hurt, either.

Remaining tasks

TBD

User interface changes

N/A

Introduced terminology

None.

API changes

Better not be any.

Data model changes

None.

Release notes snippet

N/A

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component

entity system

Created by

πŸ‡ΊπŸ‡ΈUnited States xjm

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024