Rename EntityReferenceTestTrait to help discoverability

Created on 13 November 2023, 10 months ago
Updated 23 November 2023, 10 months ago

Problem/Motivation

Core has several test traits which help with setup, e.g.

- Drupal\Tests\media\Traits\MediaTypeCreationTrait
- Drupal\Tests\node\Traits\NodeCreationTrait
- Drupal\Tests\image\Kernel\ImageFieldCreationTrait

These generally follow the pattern of ending in 'CreationTrait'. This helps developers identify them as reusable in their own tests, and automated tools such as Module Builder can find them and suggest them when generating test classes.

EntityReferenceTestTrait is a reusable trait for creating entity reference fields, but it does not follow this pattern.

Steps to reproduce

Proposed resolution

Rename the trait to EntityReferenceFieldCreationTrait.

Determine whether a deprecation notice is necessary for the existing trait or whether it can just be removed.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Fixed

Version

10.2

Component
Field 

Last updated 1 day ago

Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Comments & Activities

  • Issue created by @joachim
  • Status changed to Needs review 10 months ago
  • 🇮🇳India pradhumanjainOSL

    Renamed the EntityReferenceTestTrait to EntityReferenceFieldCreationTrait.

  • Status changed to Needs work 10 months ago
  • The Needs Review Queue Bot tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update 10 months ago
    30,546 pass, 2 fail
  • First commit to issue fork.
  • @sourabhjain opened merge request.
  • Status changed to Needs review 10 months ago
  • Status changed to RTBC 10 months ago
  • 🇺🇸United States smustgrave

    This issue was tagged novice for new users @sourabhjain based on your posts you can work on non novice issues.

    Reroll into MR seems fine.

  • 🇺🇸United States xjm

    Thanks @sourabhjain. Note that converting a patch to a merge request without other contributions to the issue does not receive credit. Also, I wonder if maybe you could work on some more advanced contributions rather than novice ones? Based on your profile, you are ready for that. 🙂 It's best to leave novice-tagged issues for those who are new to the contribution process.

  • 🇺🇸United States xjm

    Saving credits, including for @smustgrave for mentoring.

  • 🇺🇸United States xjm

    Also remember to hide old patch files when converting an issue to an MR.

  • 🇺🇸United States xjm

    Thanks everyone for your work on this.

    In general, we treat test base classes and traits as APIs, since it's very likely that contrib might also use them in their tests. It's okay to change them in a minor release as development code, but we should have a change record for it.

    Thanks!

  • Status changed to Needs work 10 months ago
  • 🇺🇸United States xjm
  • Status changed to RTBC 10 months ago
  • 🇺🇸United States smustgrave

    Not sure if CR falls under novice but wrote a quick one https://www.drupal.org/node/3401941

  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪

    I don't think there is more to say in the CR :) looks good @smustgrave!

    If the issue is novice, the CR could be novice as well. But in general I don't think creating a CR is a novice task as it sometimes requires deep understanding of what is being fixed.

    • xjm committed 73b46284 on 11.x
      Issue #3401236 by pradhumanjain2311, xjm, joachim, smustgrave: Rename...
    • xjm committed d5cfbbf1 on 10.2.x
      Issue #3401236 by pradhumanjain2311, xjm, joachim, smustgrave: Rename...
  • Status changed to Fixed 10 months ago
  • 🇺🇸United States xjm

    I reviewed locally with git diff --color-words and verified that the only changes are renaming the trait. I also grepped for EntityReferenceTestTrait and confirmed there are no remaining usages.

    Committed to 11.x and 10.2.x as a minor-only test API improvement and internal API change. Also published the CR. Thanks!

  • 🇮🇳India sourabhjain

    Hi @xjm @smustgrave
    I intentionally deferred work on these issues. All the updates were made on November 14, 2023, and I've been addressing them sequentially in the Drupal issue queue without initially considering the tags assigned to each. I acknowledge this oversight and apologize for any confusion. Moving forward, I will ensure to prioritize and address issues based on their respective tags.

  • 🇮🇳India sourabhjain

    Hi @xjm @smustgrave
    I intentionally deferred work on these issues. All the updates were made on November 14, 2023, and I've been addressing them sequentially in the Drupal issue queue without initially considering the tags assigned to each. I acknowledge this oversight and apologize for any confusion. Moving forward, I will ensure to prioritize and address issues based on their respective tags.

  • 🇺🇸United States mglaman WI, USA

    So, contrib modules cannot run tests on 10.0, 10.1 if they fix this for 10.2. Or they cannot run for 10.2. There is no bridge.

    Can the CR be updated to explain how to use class aliasing to make this work? Or have Drupal core provide a class alias for the trait.

  • 🇨🇭Switzerland Berdir Switzerland

    I think this should not have been committed and should be reverted. The old trait should be deprecated and I'm honestly not sure if that's worth that.

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

Production build 0.71.5 2024