Problem/Motivation

Discovered via PHPStan in #3178534: Start running PHPStan on Drupal core (level 0):

  Line   core/tests/Drupal/Tests/Component/Annotation/PluginIdTest.php                                                            
 ------ ------------------------------------------------------------------------------------------------------------------------- 
  19     Class Drupal\Component\Annotation\PluginID does not have a constructor and must be instantiated without any parameters.  
  24     Class Drupal\Component\Annotation\PluginID does not have a constructor and must be instantiated without any parameters.  
  50     Class Drupal\Component\Annotation\PluginID does not have a constructor and must be instantiated without any parameters.  

The test checks that instantiating the class with parameters does nothing, but as there is no constructor then this test is meaningless.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#2 3205037.patch1.09 KBlongwave

Comments

longwave created an issue. See original summary.

longwave’s picture

Status: Active » Needs review
StatusFileSize
new1.09 KB
quietone’s picture

Status: Needs review » Reviewed & tested by the community

This looks correct to me.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Well the comment does say // Assert plugin starts empty regardless of constructor.

That sounds intentional to me. I think we need to do the git archaeology to see why this was added.

longwave’s picture

Status: Needs work » Reviewed & tested by the community

Not really sure what that comment is about nor what it is trying to test.

#2435607: Tests for Annotation Component is where this test was introduced, and this wasn't commented on at the time although it's present from the first patch in the issue.

The PluginID annotation was introduced in #1965164: Add a @PluginID annotation for plugins that only need an ID, like Views handlers and it has never had a constructor.

PluginID was converted to extend AnnotationBase in #2005716: Promote EntityType to a domain object but that has never had a constructor either.

So really I have no idea what that comment is supposed to mean or why this test was ever added!

neclimdul’s picture

Looks like maybe I was assuming doctrine would throw any values into the constructor... or something? Annotation parsing checks there's a constructor before doing that even back then though so it didn't do anything when this was committed and looks like well before. Also, that wouldn't have covered anything. I have to wonder if that came out of a discussion or something... very weird.

+1 to the changes, doesn't really make sense the way its written.

alexpott’s picture

Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed

Backported 9.1.x to keep tests aligned.

Committed and pushed 70eb124d5f to 9.2.x and 43136cd9e8 to 9.1.x. Thanks!

  • alexpott committed 70eb124 on 9.2.x
    Issue #3205037 by longwave, neclimdul: Drupal\Tests\Component\Annotation...

  • alexpott committed 43136cd on 9.1.x
    Issue #3205037 by longwave, neclimdul: Drupal\Tests\Component\Annotation...

Status: Fixed » Closed (fixed)

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