Problem/Motivation

Discovered in #3581155: Investigate if shipmonk/dead-code-detector would be useful to us we have a number of unused property definitions throughout core. This issue deals with kernel tests.

Steps to reproduce

Proposed resolution

Remove the unused properties.

Remaining tasks

Check why and when these properties were added in the first place.
Confirm that no test coverage has been unintentionally lost.

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3581404

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

longwave created an issue. See original summary.

longwave’s picture

Status: Active » Needs work

longwave changed the visibility of the branch 3581404-remove-unused-properties to hidden.

longwave’s picture

Status: Needs work » Needs review
borisson_’s picture

Status: Needs review » Reviewed & tested by the community

I used phpstorm's find usage on these properties and they are not used according to that either. In this case there are a few that are only written to, but they are not being read, so this is also fine imo
So this looks good to me, I also agree with scoping these issues like this.

catch’s picture

Status: Reviewed & tested by the community » Needs review

I think we're missing:

Check why and when these properties were added in the first place.
Confirm that no test coverage has been unintentionally lost.

from the issue summary.

smustgrave’s picture

If each one needs to have it's git history that's a pretty large search should this be broken up?

catch’s picture

I think it's OK in this issue. For most I would guess they haven't been changed since they were added, so it'll just be git blame then checking the commit. If they were added in the first commit and where never used even then, then it's safe to assume it's cruft from the original MR that wasn't spotted at the time, that may or may not have been used in previous iterations of the MR/patch before it was committed.

If they were used in the original MR but the coverage using them was removed since, then it's a bit more digging.

smustgrave’s picture

But still 48 files of checking git history

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

core/modules/big_pipe/tests/src/Kernel/BigPipeInterfacePreviewThemeSuggestionsTest.php was added originally in #2632750 and checking that ticket that variable was never set.

core/modules/block_content/tests/src/Kernel/BlockContentDeriverTest.php was added originally in #3340159. baseDefinition was never called and blockContentStorage/blockContentDerivative were set but never called.

core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php was added originally in #3245967 and that variable was just never called.

core/modules/content_moderation/tests/src/Kernel/ContentModerationResaveTest.php was added originally in #3181439 and that state variable was set but then never called.

core/modules/content_moderation/tests/src/Kernel/ContentModerationWorkflowConfigTest.php was added originally in #2830740 and those variables were never called or in the one case set and never called.

Every single one I checked were from the original issue and not updated since. So believe it's safe to say that removing these properties is fine. If I had to guess when these tests were made they were copied from an existing test but can't prove that. Maybe if any of these tests get expanded they can add the properties back if they need them.

Hope that works vs checking all 48 haha.

longwave’s picture

I think this is fine. The only one that jumped out was TestConfigurableContextAwarePlugin given that's an entire unused test class but even that was added in #2273381: Convert ContextAwarePluginBase to traits and then the test coverage was removed correctly in #3153956: Remove code related to "context from configuration" that was deprecated in Drupal 9 but the setup was not removed at the same time.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Yeah I think spot checks are great here. If we have a habit of accidentally adding unnecessary boilerplate when tests are committed, or leaving some when we remove other bits of the test on purpose, then we know that's because:

1. People iterate on tests when they're working on the patch and it's easy for cruft to creep in

2. Almost no-one (definitely not me) reviews test additions as closely as test refactors or other code additions/changes.

But if we were somehow adding new unused boilerplate when tests are getting changed, it would be a bit weird.

Committed/pushed to main and 11.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.

  • catch committed 6a69f615 on main
    task: #3581404 Remove unused properties from kernel tests
    
    By: longwave...

Status: Fixed » Closed (fixed)

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