Problem/Motivation

In \Drupal\Tests\Core\Extension\InfoParserUnitTest we have at least 8 test methods that do that same thing

  1. Define a broken yml string
  2. Set 2 yml files to use this exact same string
  3. set an expected exception
  4. parse file 1 and make sure the exception is expected
  5. parse file 2 and make sure the exception is expected(only difference is file name)

Really these could all be 1 test method with dataprovider. Not all the current test methods do the double files but they would be better if they did.

Proposed resolution

Make a 1 test method testInfoException that has a dataprovider that covers all the cases by the current 8(or more) test methods.

This will the advantages of

  1. Being easier to add and review new test cases
  2. Make sure when we add test cases we don't forget anything like calling the parser 2x to make sure the static function doesn't affect the result(this happened originally)

Move the test cases used in these methods

  • testInfoParserMissingKeys
  • testMissingCoreVersionRequirement
  • testInfoParserMissingKey

to a new dataprovider providerInfoException used by new test method testInfoException. Then remove those methods.

Remaining tasks

Review, and Commit

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3119761

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

tedbow created an issue. See original summary.

tedbow’s picture

StatusFileSize
new7.88 KB

Here is example of removing 3 methods and replacing with 1. Just to show the idea.

tedbow’s picture

Status: Active » Needs review
tedbow’s picture

Here is patch that removes all possible methods and puts in the new method and provider.

  1. \Drupal\Tests\Core\Extension\InfoParserUnitTest::testInfoParserBroken() is a bit different than the other exception because we don't throw it
  2. \Drupal\Tests\Core\Extension\InfoParserUnitTest::testUnparsableCoreVersionRequirement() actually pointed out a bug that we should fix #3119822: InfoParserDynamic will throw a different exception the 2nd time it is called with bad 'core_version_requirement' value. I think we should fix the current issue first and then remove that function and add a new test case to this data provider in 3119822

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

dww’s picture

Status: Needs review » Needs work

Not sure why the bot didn't mark this NW when phplint failed. :(

aleevas’s picture

Status: Needs work » Needs review
StatusFileSize
new14.95 KB
new21.32 KB
new1.36 KB

Tried to fix the failed phplint

Status: Needs review » Needs work

The last submitted patch, 7: 3119761-9.1-7.patch, failed testing. View results

hardik_patel_12’s picture

Status: Needs work » Needs review
StatusFileSize
new21.33 KB
new499 bytes

Trying to solve error fo 9.1.x.

Status: Needs review » Needs work

The last submitted patch, 9: 3119761-9.1-9.patch, failed testing. View results

mrinalini9’s picture

Assigned: Unassigned » mrinalini9
mrinalini9’s picture

Assigned: mrinalini9 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new21.31 KB
new520 bytes

Updated patch #9 to fix the failed test case.

mrinalini9’s picture

StatusFileSize
new21.33 KB
new537 bytes

Please ignore patch #12, have updated patch #9 to fix the failed test case.

mrinalini9’s picture

Assigned: Unassigned » mrinalini9
Status: Needs review » Needs work
mrinalini9’s picture

Assigned: mrinalini9 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new21.33 KB

Updated patch.

mrinalini9’s picture

Status: Needs review » Needs work
mrinalini9’s picture

Assigned: Unassigned » mrinalini9
mrinalini9’s picture

Assigned: mrinalini9 » Unassigned
narendra.rajwar27’s picture

Assigned: Unassigned » narendra.rajwar27
narendra.rajwar27’s picture

Assigned: narendra.rajwar27 » Unassigned
aleevas’s picture

Status: Needs work » Needs review
StatusFileSize
new21.8 KB
new2.8 KB

Let's try to make it green!
I've tried to fix failure test from #9

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.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.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.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.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.

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Novice

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

At this time we will need a D10 version of the patch
Tagged for novice as the reroll should be easy for beginners.

Version: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Needs review
Issue tags: -Novice
StatusFileSize
new7.27 KB

I have rerolled. I then added a string key for each test case in the new data provider plus some other cleanup for readability. I have not included the diff because it is 3x larger than the patch and the previous patch had out of scope changes.

Now that I have completed this I see the Novice tag. Not sure it was suitable, the out of scope changes were confusing things. Anyway, it is done now.

_utsavsharma’s picture

StatusFileSize
new1.31 KB
new7.29 KB

Tried to fix CCF for #29.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Reroll seems good.

dww’s picture

StatusFileSize
new7.29 KB
new589 bytes

Thanks! Fixing a super trivial nit. Leaving RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 32: 3119761-32.patch, failed testing. View results

quietone’s picture

Unrelated failure.

1) Drupal\Tests\system\Functional\System\CronRunTest::testAutomatedCron
Failed asserting that 1691374878 is less than 1691374878.

Retesting

quietone’s picture

Status: Needs work » Reviewed & tested by the community

Tests passing, restoring RTBC.

@dww, thanks for fixing the capitalization.

quietone’s picture

I'm triaging RTBC issues.

Ah, I made the patch here. The IS is still correct and there have been no questions unanswered. This is a bit of refactoring and I think can remain at RTBC.

xjm’s picture

Got 20% into a review before falling asleep; here's my notes before I forget...

The diff in Dreditor is wonky; this is much easier to review locally. Locally, it's clear that the following methods are being deleted:

  • testInfoParserMissingKey()
  • testMissingCoreVersionRequirement()
  • testMissingCoreVersionRequirement()
  • testInfoParserMissingKeys()
quietone’s picture

Issue summary: View changes

Add some details to the IS

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 32: 3119761-32.patch, failed testing. View results

xjm’s picture

Status: Needs work » Reviewed & tested by the community

Restoring status.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Finally finished the first pass of my review.

  1. I don't understand why we still have testInfoParserBroken() in addition to testInfoException(). Maybe someone can explain?
     

  2. +++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php
    @@ -52,94 +52,116 @@ public function testInfoParserNonExisting() {
    +  public function testInfoException($yaml, $expected_exception_message) {
    ...
    +  public function providerInfoException() {
    

    We can add parameter and return typehints to the method signatures.

  3. +++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php
    @@ -52,94 +52,116 @@ public function testInfoParserNonExisting() {
    +    // Set the expected exception for the 2nd call to parse().
    

    Nit: We should spell out "second".

  4. +++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php
    @@ -52,94 +52,116 @@ public function testInfoParserNonExisting() {
    +      $this->assertSame($exception_message . '.info.txt', $exception->getMessage());
    +
    +      $this->infoParser->parse(vfsStream::url("modules/fixtures/broken-duplicate.info.txt"));
    

    Where is there a newline in the middle of the catch block but nowhere around the try/catch? It's not technically wrong, but it's weird and made me initially think the parse() call was outside the try/catch.

    Edit: Looks like this is in HEAD as well and these are just moved lines. Same for the point above about "2nd". I leave it up to contributors whether to fix this, since the diff is already an illegible mess and it's best reviewed with before and after side-to-side (which I will be doing later).

  5. +++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php
    @@ -52,94 +52,116 @@ public function testInfoParserNonExisting() {
    +name: File
    +version: VERSION
    +type: module
    +dependencies:
    +  - self_awareness
    ...
    -name: Skynet
    

    Ahem. The module is supposed to be called Skynet. Thence the dependency on self_awareness. I don't care if it's not a dictionary word! :P

  6. +++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php
    @@ -52,94 +52,116 @@ public function testInfoParserNonExisting() {
    +  - llama_detector
    +  - alpaca_detector
    

    Hi Wim (or someone giving homage thereto).

  7. +++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php
    @@ -52,94 +52,116 @@ public function testInfoParserNonExisting() {
    -   * Tests that a missing 'core_version_requirement' key is detected.
    +   * Test if correct exception is thrown for a broken info file.
    

    This is not quite a complete sentence. I'd suggest:

    Tests that the correct exception is thrown for a broken info file.

Thanks!

xjm’s picture

Saving credits.

quietone’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new2.42 KB
new6.98 KB

#41
1. Yea, that is a bit unusual. I think it all comes down to the face that two of the original methods,testMissingCoreVersionRequirement and testInfoParserMissingKey, make duplicate files and then test parsing twice. With testInfoParserBroken the YAML itself is broken, so the parser can't examine the data, and the exception message is of a different pattern. The new test method continues to use the testing of two info files.
I found that the duplicate stuff was added in #2313917-203: Core version key in module's .info.yml doesn't respect core semantic versioning but I haven't read that properly because it is too late here.
2. Yes, I forgot that. Done now.
3. Done.
4. For future legibility, I have removed the blank line in the catch block.
5. I have restored Skynet, but it will come up again in a spelling issue.
6. Removed this test, it was actually a duplicate. As you mentioned the diff on this is messy.
7. Done.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Appears all points have been answered.

@xjm does #43.1 answer your question?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 43: 3119761-43.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review

Unrelated test failure, retesting.

1) Drupal\Tests\toolbar\FunctionalJavascript\ToolbarActiveTrailTest::testToolbarActiveTrail with data set #1 ('horizontal')
Failed asserting that false is true.
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems rerun was successful

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » 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.)

dww’s picture

Status: Needs work » Needs review

Tests were failing in the MR pipeline. I pushed a commit that should fix them.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Replacement seems good. Meaning no coverage appears to have been lost.

longwave’s picture

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

- Rebased to 11.x.
- Fixed 2 of the comments from @longwave in testInfoParserBroken().
- The 4 threads about testInfoException() still need help.

dww’s picture

Status: Needs work » Needs review

Finished addressing all threads. There's 1 I'm not sure about (see MR comments). Otherwise, this is ready for re-review.

Thanks,
-Derek

p.s. x-post with mondrake, but I noticed the same thing. That thread can also be resolved.

dww’s picture

smustgrave’s picture

Seems all feedback has been addressed. There's 1 open thread though @longwave mind taking a look?

longwave’s picture

Status: Needs review » Reviewed & tested by the community

All feedback was resolved.

alexpott’s picture

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

Committed and pushed 9f6b172c61 to 11.x and 2a98f61317 to 10.3.x and a9b2d321a4 to 10.2.x. Thanks!

Backported to 10.2.x to keep tests aligned.

  • alexpott committed a9b2d321 on 10.2.x
    Issue #3119761 by dww, aleevas, Hardik_Patel_12, quietone, tedbow,...

  • alexpott committed 2a98f613 on 10.3.x
    Issue #3119761 by dww, aleevas, Hardik_Patel_12, quietone, tedbow,...

  • alexpott committed 9f6b172c on 11.x
    Issue #3119761 by dww, aleevas, Hardik_Patel_12, quietone, tedbow,...

Status: Fixed » Closed (fixed)

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