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

CommentFileSizeAuthor
#2 3401236-2.patch40.91 KBpradhumanjain2311

Issue fork drupal-3401236

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

joachim created an issue. See original summary.

pradhumanjain2311’s picture

Status: Active » Needs review
StatusFileSize
new40.91 KB

Renamed the EntityReferenceTestTrait to EntityReferenceFieldCreationTrait.

needs-review-queue-bot’s picture

Status: Needs review » Needs work

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.)

sourabhjain made their first commit to this issue’s fork.

sourabhjain’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

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.

xjm’s picture

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.

xjm’s picture

Title: rename EntityReferenceTestTrait to help discoverability » Rename EntityReferenceTestTrait to help discoverability

Saving credits, including for @smustgrave for mentoring.

xjm’s picture

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

xjm’s picture

Priority: Minor » Normal
Issue tags: +Needs change record

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!

xjm’s picture

Status: Reviewed & tested by the community » Needs work
smustgrave’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs change record

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

bramdriesen’s picture

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...
xjm’s picture

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

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!

sourabhjain’s picture

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.

sourabhjain’s picture

.

mglaman’s picture

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.

berdir’s picture

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.

berdir’s picture

Component: phpunit » field system

Status: Fixed » Closed (fixed)

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