Problem/Motivation
In \Drupal\Tests\Core\Extension\InfoParserUnitTest we have at least 8 test methods that do that same thing
- Define a broken yml string
- Set 2 yml files to use this exact same string
- set an expected exception
- parse file 1 and make sure the exception is expected
- 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
- Being easier to add and review new test cases
- 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
| Comment | File | Size | Author |
|---|---|---|---|
| #43 | 3119761-43.patch | 6.98 KB | quietone |
| #43 | interdiff-32-43.txt | 2.42 KB | quietone |
| #32 | 3119761-32.patch | 7.29 KB | dww |
Issue fork drupal-3119761
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:
- 3119761-replace-multiple-test
changes, plain diff MR !6061
Comments
Comment #2
tedbowHere is example of removing 3 methods and replacing with 1. Just to show the idea.
Comment #3
tedbowComment #4
tedbowHere is patch that removes all possible methods and puts in the new method and provider.
\Drupal\Tests\Core\Extension\InfoParserUnitTest::testInfoParserBroken()is a bit different than the other exception because we don't throw it\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 3119822Comment #6
dwwNot sure why the bot didn't mark this NW when phplint failed. :(
Comment #7
aleevasTried to fix the failed phplint
Comment #9
hardik_patel_12 commentedTrying to solve error fo 9.1.x.
Comment #11
mrinalini9 commentedComment #12
mrinalini9 commentedUpdated patch #9 to fix the failed test case.
Comment #13
mrinalini9 commentedPlease ignore patch #12, have updated patch #9 to fix the failed test case.
Comment #14
mrinalini9 commentedComment #15
mrinalini9 commentedUpdated patch.
Comment #16
mrinalini9 commentedComment #17
mrinalini9 commentedComment #18
mrinalini9 commentedComment #19
narendra.rajwar27Comment #20
narendra.rajwar27Comment #21
aleevasLet's try to make it green!
I've tried to fix failure test from #9
Comment #27
smustgrave commentedThis 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.
Comment #29
quietone commentedI 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.
Comment #30
_utsavsharma commentedTried to fix CCF for #29.
Comment #31
smustgrave commentedReroll seems good.
Comment #32
dwwThanks! Fixing a super trivial nit. Leaving RTBC.
Comment #34
quietone commentedUnrelated failure.
Retesting
Comment #35
quietone commentedTests passing, restoring RTBC.
@dww, thanks for fixing the capitalization.
Comment #36
quietone commentedI'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.
Comment #37
xjmGot 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()Comment #38
quietone commentedAdd some details to the IS
Comment #40
xjmRestoring status.
Comment #41
xjmFinally finished the first pass of my review.
I don't understand why we still have
testInfoParserBroken()in addition totestInfoException(). Maybe someone can explain?We can add parameter and return typehints to the method signatures.
Nit: We should spell out "second".
Where is there a newline in the middle of the
catchblock but nowhere around thetry/catch? It's not technically wrong, but it's weird and made me initially think theparse()call was outside thetry/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).
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! :PHi Wim (or someone giving homage thereto).
This is not quite a complete sentence. I'd suggest:
Thanks!
Comment #42
xjmSaving credits.
Comment #43
quietone commented#41
1. Yea, that is a bit unusual. I think it all comes down to the face that two of the original methods,
testMissingCoreVersionRequirementandtestInfoParserMissingKey, make duplicate files and then test parsing twice. WithtestInfoParserBrokenthe 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.
Comment #44
smustgrave commentedAppears all points have been answered.
@xjm does #43.1 answer your question?
Comment #46
quietone commentedUnrelated test failure, retesting.
Comment #47
smustgrave commentedSeems rerun was successful
Comment #48
needs-review-queue-bot commentedThe 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.)
Comment #50
dwwTests were failing in the MR pipeline. I pushed a commit that should fix them.
Comment #51
smustgrave commentedReplacement seems good. Meaning no coverage appears to have been lost.
Comment #52
longwaveComment #53
dww- Rebased to 11.x.
- Fixed 2 of the comments from @longwave in testInfoParserBroken().
- The 4 threads about testInfoException() still need help.
Comment #54
dwwFinished 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.
Comment #55
dwwComment #56
smustgrave commentedSeems all feedback has been addressed. There's 1 open thread though @longwave mind taking a look?
Comment #57
longwaveAll feedback was resolved.
Comment #58
alexpottCommitted 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.