Problem/Motivation

The method \Drupal\Tests\field\Kernel\Number\NumberItemTest::setUp() doesn't have any comment.

Proposed resolution

Add inheritdoc comment.

CommentFileSizeAuthor
#45 3264947-45-10.1.x.patch258.98 KBNiklan
#45 interdiff_44_45_10.1.x.txt778 bytesNiklan
#45 interdiff_40_45_10.1.x.txt848 bytesNiklan
#44 3264947-44-10.1.x.patch257.91 KBNiklan
#44 interdiff_40_44_10.1.x.txt1.46 KBNiklan
#44 3264947-44-10.0.x.patch259.6 KBNiklan
#44 interdiff_40_44_10.0.x.txt848 bytesNiklan
#44 3264947-44-9.5.x.patch277.15 KBNiklan
#44 interdiff_40_44_9.5.x.txt842 bytesNiklan
#40 3264947-40-10.1.x.patch258.65 KBNiklan
#40 interdiff_38_40_10.1.x.txt26.93 KBNiklan
#40 3264947-40-10.0.x.patch259.27 KBNiklan
#40 interdiff_38_40_10.0.x.txt26.17 KBNiklan
#40 3264947-40-9.5.x.patch276.81 KBNiklan
#40 interdiff_38_40_9.5.x.txt27.05 KBNiklan
#38 3264947-38-10.1.x.patch222.42 KBNiklan
#38 interdiff_36_38_10.1.x.txt9.69 KBNiklan
#38 3264947-38-10.0.x.patch224.11 KBNiklan
#38 interdiff_34_38_10.0.x.txt9.07 KBNiklan
#38 3264947-38-9.5.x.patch240.44 KBNiklan
#38 interdiff_34_38_9.5.x.txt1.8 KBNiklan
#36 3264947-36-10.1.x.patch235.81 KBNiklan
#34 3264947-34-10.0.x.patch236.42 KBNiklan
#34 interdiff_29_34.txt31.21 KBNiklan
#34 3264947-34-9.5.x.patch240.42 KBNiklan
#34 interdiff_31_34.txt8.5 KBNiklan
#31 3264947-31-9.5.x.patch240.94 KBNiklan
#29 3264947-29-10.0.x.patch272.51 KBquietone
#29 interdiff-26-29.txt755 bytesquietone
#26 interdiff_25_26_10.0.x.txt380 bytesNiklan
#26 3264947-26_10.0.x.patch272.49 KBNiklan
#26 interdiff_25_26_9.4.x.txt380 bytesNiklan
#26 3264947-26_9.4.x_9.5.x.patch277.27 KBNiklan
#25 interdiff_23-25_10.0.x.txt743 bytesravi.shankar
#25 3264947-25_10.0.x.patch271.97 KBravi.shankar
#25 interdiff_23-25_9.5.x.txt737 bytesravi.shankar
#25 3264947-25_9.5.x.patch276.74 KBravi.shankar
#23 3264947-23-10.0.x.patch272.19 KBquietone
#23 interdiff-21-23-10.0.txt2.19 KBquietone
#23 3264947-23-9.5.patch276.96 KBquietone
#23 interdiff-21-23-9.5.txt1.57 KBquietone
#21 drupal-3264947-20-9.4.x.patch277.54 KBNiklan
#21 drupal-3264947-20-10.0.x.patch273.83 KBNiklan
#19 drupal-3264947-19-9.4.x.patch240.98 KBNiklan
#19 drupal-3264947-19-10.0.x.patch238.48 KBNiklan
#17 drupal-3264947-17-9.4.x.patch235.56 KBNiklan
#17 drupal-3264947-17-10.0.x.patch236.87 KBNiklan
#7 drupal-3264947-7.patch223.52 KBNiklan
#2 drupal-3264947-2.patch520 bytesNiklan
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Niklan created an issue. See original summary.

Niklan’s picture

Status: Active » Needs review
FileSize
520 bytes
longwave’s picture

There are hundreds of setUp methods without docblocks, if we are to fix this I think we should add them all in one go instead of one by one.

Niklan’s picture

@longwave sounds reasonable. Should be core tests covered by Drupal Coding Standards? Because, it seems like most parts of tests will not pass PHPCS check. I don't understand this is intentional, or they're ignored? Does it even worth to address such issues?

longwave’s picture

Coding standards say that all methods should have docblocks, but Drupal core has never fully implemented this and the Drupal.Commenting.FunctionComment.Missing rule is currently excluded in phpcs.xml.dist.

#3212066: Fix Drupal.Commenting.FunctionComment.Missing is the open issue to work on this, but there are probably hundreds if not thousands of functions/methods that need a docblock adding, and many of those are not inheritdoc so someone has to write a sentence for each. Maybe rescoping this to add docblocks to all setUp() methods would be a good start.

Niklan’s picture

Title: Add comment for method \Drupal\Tests\field\Kernel\Number\NumberItemTest::setUp() » Add missing docblocks for test method ::setUp()
Status: Needs review » Needs work
Niklan’s picture

Status: Needs work » Needs review
FileSize
223.52 KB

Here it is, the all (401) empty ::setUp() is now having inheritdoc comment.

P.s.

Used PHPStorm to do so with search and replace using regex:

Search pattern:

^$
  protected function setUp\(\): void \{

Replace pattern:

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
Niklan’s picture

marciaibanez’s picture

Assigned: Unassigned » marciaibanez

I'll review this issue.

marciaibanez’s picture

Assigned: marciaibanez » Unassigned
Status: Needs review » Reviewed & tested by the community

I tested the patch, everything seems to work well.

xjm’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +beta target

I think the chosen scope makes sense.

Looks like it needs a reroll. It might also need different versions for different branches, so I'd check to see whether the same patch applies to 10.0.x and 9.4.x.

Large cleanups like this are often scheduled as beta targets because they fall out of sync with HEAD so quickly. That way we ensure they're less disruptive to other patches and also get committer attention right away so they don't have to be rerolled so many times while awaiting commit. The beta phase for 9.4 will begin on May 23. @Niklan, if you're available around then, we could schedule recreating this patch for some time that week? Thanks!

@marciaibanez, there is nothing to test with this patch and nothing that would be "working well". Posting that as a review makes it look like no review actually happened.

To get contribution credit for reviewing an issue like this, I would expect to see the reviewer document what references they looked at to confirm that this is the correct fix, how they checked to ensure all the added docblocks were only for test setUp() methods, and how they checked to make sure there were no typos. I would also expect them to show the grep or similar commands they used to make sure no other setUp()methods in HEAD were still missing docblocks once the patch is applied.

So, I haven't assigned @marciaibanez contribution credit for this issue, but hopefully this will help with reviewing similar issues in the future.

Thanks everyone!

quietone’s picture

Issue tags: +Coding standards

Adding tag.

Niklan’s picture

@Niklan, if you're available around then, we could schedule recreating this patch for some time that week? Thanks!

Yeah, sure. So I need to provide two patches for 10.0.x and 9.4.x around May 23 or after that date (next day e.g.)?

TR’s picture

Search pattern:

^$
  protected function setUp\(\): void \{

This is not sufficient. Drupal did not consistently use the :void return type for the setUp() method in Drupal 9 - that was not fully fixed until Drupal 10.

So your pattern doesn't find all the places that need a docblock. For example, core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php
and
core/modules/image/tests/src/Functional/ImageFieldTestBase.php
and
core/modules/serialization/tests/src/Kernel/NormalizerTestBase.php
etc.

This means the patch is going to need a lot of changes for Drupal 10.

IMO this should be done in Drupal 10 first, then backported to Drupal 9 if desired. I would hate to see the effort wasted on fixing this in Drupal 9 and not getting the fixes into Drupal 10 ...

Niklan’s picture

Assigned: Unassigned » Niklan

Nice catch! Thank you, I'll adjust search pattern and update patches. Will prioritize 10.0.x patch then.

longwave’s picture

Title: Add missing docblocks for test method ::setUp() » [May 23, 2022] Add missing docblocks for test method ::setUp()
Status: Needs work » Postponed

Adding a date tag and postponing so we know when to work on this again.

> IMO this should be done in Drupal 10 first

Yes, we will need separate patches for 10.0.x and 9.4.x, with the intent to commit them at the same time.

Niklan’s picture

Sorry for noise, having time to adjust regex pattern for search and replace missing docblocks.

Search:

^$
  protected function setUp\(\)

I removed : void { part as mentioned above, not all ::setUp() methods has it in 9.4.x branch. It found 21 more results. We don't need to capture group here ((\: void)?) because seems like this pattern is enough to find all of them.

And updated replace pattern (note an empty line before comment starts):


  /**
   * {@inheritdoc}
   */
  protected function setUp()

Attach separate patches for 9.4.x and 10.0.x, will update them on May 23.

  • 9.4.x — 423 replacements.
  • 10.0.x — 425 replacements.
TR’s picture

The patches in #17 look good, but a few more things are needed for the D9 patch.

I forgot to mention that in Drupal 9, in addition to the missing :void, many of the setUp() methods are still declared public instead of protected. So there are some public function setUp() and some public function setUp(): void methods that also need a docblock. Again, the visibility of the setUp() method has been fixed in D10, so this only affects the D9 patch.

I'm wondering if we should address tearDown() at the same time? We usually do. There are only a few of these, but they are strongly correlated with the setUp() changes so it will help minimize disruption if we do them at the same time. (If a class has a tearDown() (not many do) and if that tearDown() is missing a docblock, the setUp() method in that class is almost certainly also missing a docblock. So the classes that need a change to tearDown() will be the same as the classes that need a change to setUp().)

Searching for tearDown() in D9 has the same problems as setUp() - some are public, some are protected, some have :void, some don't.

Niklan’s picture

Updated regex which covers method visibility and both ::setUp() and ::tearDown() methods.

Search:

^$
  (protected|public) function (setUp|tearDown)\(\)

Replace:


  /**
   * {@inheritdoc}
   */
  $1 function $2()
Niklan’s picture

Saw a new commit (f1aad3c2) into core and seems like this issue should also cover ::setUp() method with parameters. E.g. \Drupal\Tests\rest\Functional\Views\StyleSerializerTest::setUp(), \Drupal\Tests\views\Functional\ViewTestBase::setUp()

Should it be addressed? If so, how? E.g. StyleSerializerTest::setUp() should have just an inhertdoc docblock, but ViewTestBase::setUp() should also have a parameters docs.

UPD: ^$\n(protected|public) function (setUp|tearDown)\(\$ found 58 results in 10.0.x branch. And it seems like this is only for tests that extends ViewTestBase.

Niklan’s picture

Title: [May 23, 2022] Add missing docblocks for test method ::setUp() » [May 23, 2022] Add missing docblocks for test methods ::setUp() and ::tearDown()
Status: Postponed » Needs review
FileSize
273.83 KB
277.54 KB

Attaching updated patches.

These patches covers ::setUp() and ::tearDown() methods.

I've also added extended docblock for ViewTestBase::setUp(), please someone check my language here:

  /**
   * {@inheritdoc}
   *
   * @param bool $import_test_views
   *   Indicates whether test views configuration should be imported.
   * @param array $modules
   *   An array with modules from which views configurations should be imported.
   */

The last submitted patch, 21: drupal-3264947-20-10.0.x.patch, failed testing. View results

quietone’s picture

@Niklan, hope you don't mind that I rerolled this. I was looking at coding standards issues today and discovered this needed a reroll.

I did not search for any new instances that need this change.

longwave’s picture

Status: Needs review » Needs work

Thanks for rerolling.

+++ b/core/modules/views/tests/src/Functional/ViewTestBase.php
@@ -29,6 +29,14 @@ abstract class ViewTestBase extends BrowserTestBase {
+  /**
+   * {@inheritdoc}
+   *
+   * @param bool $import_test_views
+   *   Indicates whether test views configuration should be imported.
+   * @param array $modules
+   *   An array with modules from which views configurations should be imported.
+   */

This is not allowed according to standards, you can either use @inheritdoc alone or a full docblock, but not combine the two. See #1994890: Allow {@inheritdoc} and additional documentation for history and discussion to change this.

ravi.shankar’s picture

I think @inheritdoc will be enough here, so I have made changes as per that.

Niklan’s picture

Thank you for helping me, folks.

Both patches miss a new \Drupal\Tests\ckeditor5\FunctionalJavascript\TableTest::setUp() empty method for all branches.

Providing new patches, the patch for 9.4.x and 9.5.x the same because there is no diff between them.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Wim Leers’s picture

Title: [May 23, 2022] Add missing docblocks for test methods ::setUp() and ::tearDown() » [Sep 12, 2022] Add missing docblocks for test methods ::setUp() and ::tearDown()

This patch was neither RTBC nor passing tests. So moving this back to 9.4.x for a commit now seems imprudent, since it's not in a committable state.

Hence moving this to the next beta target phase. https://www.drupal.org/about/core/policies/core-release-cycles/schedule says May 18-27 is the 9.4.x beta phase. The 9.5.x equivalent is Sep 12.

quietone’s picture

Version: 9.5.x-dev » 10.0.x-dev
FileSize
755 bytes
272.51 KB

Yes, I know but I felt like getting this back to green. Let's see if this works.

Wim Leers’s picture

Hehehe … 😄

Who knows 🤞

Niklan’s picture

I've also completely updated patch for Drupal 9.5.x, but not sure do we need it at this point because target is 10.0.x

borisson_’s picture

The last test here ran into a random JS fail, queued it again.

quietone’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Needs some rerolls here. Neither patch applies to 9.5.x or 10.0.x

Niklan’s picture

Status: Needs work » Needs review
FileSize
8.5 KB
240.42 KB
31.21 KB
236.42 KB
quietone’s picture

Status: Needs review » Needs work

@Niklan, thanks for keeping this up to date!

The patches apply to 9.5 and 10.0 but not 10.1. Setting to NW for a 10.1 patch.

Niklan’s picture

Status: Needs work » Needs review
FileSize
235.81 KB

Added patch for Drupal 10.1.

Checked patches for 9.5.x and 10.0.x from #34. They are still valid, interdiffs are empty.

quietone’s picture

Issue tags: -Needs reroll

@Niklan, thanks!

Removing re-roll tag.

Niklan’s picture

longwave’s picture

Status: Needs review » Needs work

Thank you for continuing to work on this. However, there are lots of files still missing docblocks for setUp(). I generated a list with:

$ rg -il 'function setUp\(' core|xargs rg -i --files-without-match --multiline '\*/\n.*function setUp\('|sort
core/modules/block_content/tests/src/Functional/Views/BlockContentTestBase.php
core/modules/comment/tests/src/Functional/Views/CommentFieldFilterTest.php
core/modules/comment/tests/src/Functional/Views/CommentTestBase.php
core/modules/comment/tests/src/Functional/Views/DefaultViewRecentCommentsTest.php
core/modules/comment/tests/src/Kernel/Views/CommentViewsKernelTestBase.php
core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php
core/modules/field/tests/src/Functional/Views/FieldTestBase.php
core/modules/forum/tests/src/Functional/Views/ForumIntegrationTest.php
core/modules/hal/tests/src/Functional/comment/Views/CommentHalExportTest.php
core/modules/hal/tests/src/Functional/rest/Views/StyleSerializerTest.php
core/modules/image/tests/src/Kernel/Views/RelationshipUserImageDataTest.php
core/modules/language/tests/src/Kernel/Views/LanguageTestBase.php
core/modules/options/tests/src/Kernel/Views/OptionsTestBase.php
core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php
core/modules/statistics/tests/src/Functional/Views/IntegrationTest.php
core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldFilterTest.php
core/modules/user/tests/src/Functional/Views/FilterPermissionUiTest.php
core/modules/user/tests/src/Functional/Views/HandlerFilterUserNameTest.php
core/modules/user/tests/src/Functional/Views/UserChangedTest.php
core/modules/user/tests/src/Functional/Views/UserTestBase.php
core/modules/user/tests/src/Kernel/Views/UserKernelTestBase.php
core/modules/views/tests/src/Functional/DefaultViewsTest.php
core/modules/views/tests/src/Functional/Handler/AreaTest.php
core/modules/views/tests/src/Functional/Handler/FieldEntityOperationsTest.php
core/modules/views/tests/src/Functional/Handler/FieldWebTest.php
core/modules/views/tests/src/Functional/Handler/FilterDateTest.php
core/modules/views/tests/src/Functional/Handler/HandlerTest.php
core/modules/views/tests/src/Functional/Plugin/AccessTest.php
core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php
core/modules/views/tests/src/Functional/Plugin/CacheTagTest.php
core/modules/views/tests/src/Functional/Plugin/DisabledDisplayTest.php
core/modules/views/tests/src/Functional/Plugin/DisplayAttachmentTest.php
core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php
core/modules/views/tests/src/Functional/Plugin/DisplayFeedTranslationTest.php
core/modules/views/tests/src/Functional/Plugin/DisplayTest.php
core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php
core/modules/views/tests/src/Functional/Plugin/FilterTest.php
core/modules/views/tests/src/Functional/Plugin/MiniPagerTest.php
core/modules/views/tests/src/Functional/Plugin/NumericFormatPluralTest.php
core/modules/views/tests/src/Functional/Plugin/ViewsBulkTest.php
core/modules/views/tests/src/Functional/TaxonomyGlossaryTest.php
core/modules/views/tests/src/Functional/ViewAjaxTest.php
core/modules/views/tests/src/Functional/ViewTestBase.php
core/modules/views/tests/src/Functional/Wizard/BasicTest.php
core/modules/views/tests/src/Functional/Wizard/ItemsPerPageTest.php
core/modules/views/tests/src/Functional/Wizard/SortingTest.php
core/modules/views/tests/src/Functional/Wizard/TaggedWithTest.php
core/modules/views/tests/src/Functional/Wizard/WizardTestBase.php
core/modules/views/tests/src/Kernel/Handler/AreaTextTest.php
core/modules/views/tests/src/Kernel/Handler/HandlerAliasTest.php
core/modules/views/tests/src/Kernel/PluginInstanceTest.php
core/modules/views/tests/src/Kernel/Plugin/JoinTest.php
core/modules/views/tests/src/Kernel/ViewsHooksTest.php
core/modules/views/tests/src/Kernel/Wizard/WizardPluginBaseKernelTest.php
core/modules/views_ui/tests/src/Functional/DefaultViewsTest.php
core/modules/views_ui/tests/src/Functional/DisplayPathTest.php
core/modules/views_ui/tests/src/Functional/DuplicateTest.php
core/modules/views_ui/tests/src/Functional/ExposedFormUITest.php
core/modules/views_ui/tests/src/Functional/OverrideDisplaysTest.php
core/modules/views_ui/tests/src/Functional/TranslatedViewTest.php
Niklan’s picture

I see, these with parameters. Attaching updated patches. But these tests methods are using parameters, shouldn't they have descriptions?

Patches in #48 only adds @inheritdoc comment for setUp() and tearDown() methods without (!) parameters.

Patches in this comment adds @inheritdoc to all setUp() and tearDown() methods, even if they have parameters.

Command above, still showing a single file for all branches:

$ rg -il 'function setUp\(' core|xargs rg -i --files-without-match --multiline '\*/\n.*function setUp\('|sort
core/tests/Drupal/Tests/Component/Annotation/Doctrine/Ticket/DCOM58Test.php

I don't know how to handle this one. It looks like (and it tells that in comments) a copy-paste code in PSR code style.

Niklan’s picture

Status: Needs work » Needs review
longwave’s picture

DCOM58Test was copied from Doctrine and is fine to leave as-is I think.

For the tests with parameters I guess we should document the base classes correctly, but any subclasses that have the same parameters should use @inheritdoc. I will double check this later.

longwave’s picture

Status: Needs review » Needs work

I reviewed the whole 9.5.x patch as that is the largest (some modules have been removed in 10.0.x). The only issue I found was:

+++ b/core/modules/views/tests/src/Functional/ViewTestBase.php
@@ -29,6 +29,9 @@ abstract class ViewTestBase extends BrowserTestBase {
+  /**
+   * {@inheritdoc}
+   */
   protected function setUp($import_test_views = TRUE, $modules = ['views_test_config']) {

This is the only docblock where new parameters are introduced so this cannot use @inheritdoc. I suggest the docblock is something like:

  /**
   * Sets up the test.
   *
   * @param bool $import_test_views
   *   Should the views specified on the test class be imported. If you need
   *   to setup some additional stuff, like fields, you need to call false and
   *   then call createTestViews for your own.
   * @param array $modules
   *   The module directories to look in for test views.
   */

The docs are borrowed from ViewsKernelTestBase which already has a docblock.

All others in this patch are fine to use @inheritdoc as they extend from other base classes.

Niklan’s picture

Niklan’s picture

Woops, PHPStorm again not found empty setUps for MigrateExecutableTest and EntityRevisionTest in 10.1.x branch. Attaching updated 10.1.x patch and two interdiffs for #40 and #44 patches.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Thank you for working on this. I checked the patches for all three branches and can't find any missing docblocks, so this issue is RTBC.

alexpott’s picture

Version: 10.0.x-dev » 9.5.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 2c468a0 and pushed to 10.1.x. Thanks!
Committed c5b049b and pushed to 10.0.x. Thanks!
Committed 1f60cd2 and pushed to 9.5.x. Thanks!

Backported to 9.5.x to keep things aligned - use --3way to apply all the patch successfully.

  • alexpott committed 2c468a0 on 10.1.x
    Issue #3264947 by Niklan, quietone, ravi.shankar, longwave, TR, xjm: [...

Status: Fixed » Closed (fixed)

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