Problem/Motivation

There is no documentation for using the following tags.

  • @coversDefaultClass
  • @covers
  • @group

See

Benefits

If we adopted this change, the Drupal Project would benefit by ...

Three supporters required

  1. https://www.drupal.org/u/{userid} (yyyy-mm-dd they added support)
  2. https://www.drupal.org/u/{userid} (yyyy-mm-dd they added support)
  3. https://www.drupal.org/u/{userid} (yyyy-mm-dd they added support)

Proposed changes

Provide all proposed changes to the Drupal Coding standards. Give a link to each section that will be changed, and show the current text and proposed text as in the following layout:

1. {link to the documentation heading that is to change}

Current text

Add current text in blockquotes

Proposed text

Add proposed text in blockquotes

2. Repeat the above for each page or sub-page that needs to be changed.

Remaining tasks

  1. Create this issue in the Coding Standards queue, using the defined template
  2. Add supporters
  3. Create a Change Record
  4. Review by the Coding Standards Committee
  5. Coding Standards Committee takes action as required
  6. Discussed by the Core Committer Committee, if it impacts Drupal Core
  7. Final review by Coding Standards Committee
  8. Documentation updates
    1. Edit all pages
    2. Publish change record
    3. Remove 'Needs documentation edits' tag
  9. If applicable, create follow-up issues for PHPCS rules/sniffs changes

For a full explanation of these steps see the Coding Standards project page

Problem/Motivation

Comments

dawehner’s picture

I really think we should not even try to write the same documentation as phpunit has already.

If someone wants to write a unit test, he will have to look it up on the phpunit documentation anyway.

clemens.tolboom’s picture

Issue summary: View changes

In #2100637-38: REST views: add special handling for collections test failed due to missing @group which seems to be required. So this is a 'bug' in the documentation.

So we need @group which is used to distinguish tests to run. See http://phpunit.de/manual/current/en/appendixes.annotations.html#appendix...

tim.plunkett’s picture

Title: No documentation about @coversDefaultClass and @covers » No documentation about @group

@group is not required by PHPUnit, but it is currently required for our Simpletest code.

@covers/@coversDefaultClass are best practices, and are documented by PHPUnit.

clemens.tolboom’s picture

Title: No documentation about @group » No documentation about @group @coversDefaultClass @covers

I think all three need to be listed on https://www.drupal.org/node/1354 as our best practice seems to require these.

@group is defined @ phpunit too.

I prefer to have a complete list on mentioned page instead of letting people scatter around various resource. Ie @param and @return are listed too.

tim.plunkett’s picture

Category: Bug report » Task

Feel free.

clemens.tolboom’s picture

The page is locked and I'm not capable documenting the Drupal reason ... but some copy paste from phpunit probably will do.

Let's see what @jhodgdon think.

jhodgdon’s picture

Status: Active » Closed (works as designed)

Please do not add those to node/1354.

These are not API documentation tags. They are like annotation -- used by PHPUnit. We do not document annotation on node/1354, just documentation tags. PHPUnit and how to write tests are documented in this section: https://www.drupal.org/phpunit which should cover those "tags".

webchick’s picture

Priority: Normal » Major
Status: Closed (works as designed) » Active

Opening this back up for consideration, and escalating priority.

We got this report in Drupal Module Upgrader: #2499971: Tests are missing @coversDefaultClass annotations The reason for this was not readily apparent, since http://cgit.drupalcode.org/drupalmoduleupgrader/tree/tests/src/Unit/Plug... *does* have PHPDoc above the class. But it turns out that we're expecting some kind of special format of this PHPDoc in order to not trigger exceptions.

#2422019: Don't use reflection for parsing test annotations went in without a change record, so that's one problem. But people writing new D8 code will also need to know what their docblocks need to look like in order to not completely kill the test listing page.

jhodgdon’s picture

OK. So.. We have a page -- no actually a whole section about writing PHPUnit tests specific to Drupal:
https://www.drupal.org/phpunit
There's not a single thing in that section about what the class doc header needs to be in order for Drupal's PHPUnit testing framework to correctly pick up tests. There definitely should be something added there, maybe on the file structure and namespaces page? https://www.drupal.org/node/2116043

For Simpletest, we also do not have a page on what the class files need to be for D8, what namespace, where to put them, etc. under https://www.drupal.org/simpletest -- and I think we should.

Can someone write these? I personally am not sure what all the requirements are... or if someone can make a quick post here with what the requirements are, and good examples to use, I can make a first pass at writing the pages and then someone can verify/fix errors.

Once that is done, I think the appropriate thing to do on node/1354 would be to:

a) Have a section on node/1354 about doc headers for PHPUnit and Simpletest (up amongst the pages like "Documenting functions" etc.), and rather than putting full docs there, link to the more comprehensive pages we just wrote explaining what to do.

b) In the tag reference section of node/1354, make sure any PHPUnit and/or Simpletest tags are referenced and the explanation section also points to those docs pages we've just written.

How's that for a plan?

webchick’s picture

That sounds like a lovely plan! I'd be happy to write the docs myself, but I have no idea what they should say. :( For now we are doing @coversDefaultClass because it seems to kill two birds with one stone, but I couldn't say what the "proper" template should be. https://api.drupal.org/api/drupal/core%21tests%21Drupal%21Tests%21UnitTe... shows a lot of inconsistency.

webchick’s picture

Oh, neat. In searching change records for @group, I found https://www.drupal.org/node/2301125 which looks like the ticket.

webchick’s picture

Ok here's a first step. Renamed that page from "PHPUnit file structure and namespace" to "PHPUnit file structure, namespace, and required metadata" and added in the content of the change record: https://www.drupal.org/node/2116043/revisions/view/8530219/8530253

I do not know how to write the page under /simpletest, but agree it should exist, and should likely mirror the PHPUnit page here, assuming that looks ok.

jhodgdon’s picture

Weird, so we do not require a one-line description on PHPUnit test class doc blocks??!? Whatever.

OK, I wrote up what I at least think is accurate for Simpletest on https://www.drupal.org/node/2500059

If someone could review both that page and the revisions webchick made in #12, that would be good.

I'll meanwhile update node/1354

jhodgdon’s picture

Status: Active » Needs work

Hm, I noticed the new page for PHPUnit doesn't say anything about @covers, so that needs to be added.

Anyway, I updated node/1354:
https://www.drupal.org/node/1354/revisions/view/8338507/8530331

Setting to Needs Work because the PHPUnit page needs @covers to be covered. Also both pages need reviews:
https://www.drupal.org/node/2500059 [completely new]
https://www.drupal.org/node/2116043/revisions/view/8530219/8530253 [revision]

webchick’s picture

Weird, so we do not require a one-line description on PHPUnit test class doc blocks??!? Whatever.

♪♬ Please don't shoot the messenger! :D ♫♭ I merely copy/pasted from the change record.

Good point on @covers. I actually have no idea what either it nor @coversDefaultClass does, so I'll leave that to someone else to document. (Basically, a one sentence description that links off to the PHPUnit docs.)

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Project: Drupal core » Coding Standards
Version: 11.x-dev »
Component: documentation » Coding Standards
quietone’s picture

Status: Needs work » Active
quietone’s picture

At the recent coding standards meeting mstrelan reported that 'we need to use attributes' and not annotations. See the meeting issue for the full discussion, #3458726: Coding Standards Meeting Tuesday 2024-07-16 2100 UTC

The suggestion was that our docs should point to PHPUnit docs. I currently disagree with that because of the '@group'. There is no documentation to explain how that is used in Drupal. Sometimes it is upper case and sometime it is not. That should be made clear to developers.

quietone’s picture

Issue summary: View changes

Convert to new template.

borisson_’s picture

The suggestion was that our docs should point to PHPUnit docs. I currently disagree with that because of the '@group'. There is no documentation to explain how that is used in Drupal.

I agree we can't just point to the phpunit docs, but I think we should link to them + explain our own additional rules about them if they exist.

mondrake’s picture

This is now partially outdated, in the sense that annotations are deprecated in PHPUnit 10 in favor of PHP attributes, and there is no one to one mapping in all cases.

See https://github.com/sebastianbergmann/phpunit/issues/4502

quietone’s picture

Issue tags: -Coding standards
quietone’s picture

quietone’s picture

@group and @coversDefaultClass are documented at Required PHPDoc metadata for test discoverability

These are not API documentation tags. They are like annotation -- used by PHPUnit. We do not document annotation on node/1354, just documentation tags. PHPUnit and how to write tests are documented in this section: https://www.drupal.org/phpunit which should cover those "tags".

From #7. So, that means that page gets updated with the attribute information. And, that this should have stayed in the core queue.