Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Part of meta-issue #2002650: [meta, no patch] improve maintainability by removing unused local variables
take out unused vars in
core/tests/Drupal/Tests/
DateTimePlusTest
CssCollectionRendererUnitTest
LocalTaskIntegrationTest
CsrfTokenGeneratorTest
#2080299: Remove Unused local variable $record from /core/tests/Drupal/Tests/Core/Database/EmptyStatementTest.php is fixed in this issue also.
Comment | File | Size | Author |
---|---|---|---|
#57 | 2081153.57.patch | 4.65 KB | alexpott |
#57 | 43-57-interdiff.txt | 1.11 KB | alexpott |
#43 | interdiff-2081153-38-43.txt | 3.08 KB | YesCT |
#43 | removeunused-2081153-43.patch | 3.27 KB | YesCT |
#38 | removeunused-2081153-38.patch | 2.31 KB | lauriii |
Comments
Comment #1
smira CreditAttribution: smira commentedComment #2
smira CreditAttribution: smira commentedComment #3
areke CreditAttribution: areke commentedThe patch doesn't apply; it needs to be rebased.
Comment #4
Enxebre CreditAttribution: Enxebre commentedRerolling!
Comment #6
leslieg CreditAttribution: leslieg commentedComment #7
xjmLet's also check the rest of the tests in this directory and confirm that there are no other unused local variables.
Comment #8
Enxebre CreditAttribution: Enxebre commentedNo more unused variables found in asset form me.
Regards!
Comment #9
Enxebre CreditAttribution: Enxebre commentedComment #10
areke CreditAttribution: areke commentedI checked and there are no other unused local variables in this directory.
Comment #11
areke CreditAttribution: areke commented4: removeunused-2081153-4.patch queued for re-testing.
Comment #12
parthipanramesh CreditAttribution: parthipanramesh commentedApplies totaly fine and there aren't any other unused local variables.
Comment #13
xjm4: removeunused-2081153-4.patch queued for re-testing.
Comment #15
Enxebre CreditAttribution: Enxebre commented4: removeunused-2081153-4.patch queued for re-testing.
Comment #17
gokulnk CreditAttribution: gokulnk commentedComment #18
gokulnk CreditAttribution: gokulnk commented4: removeunused-2081153-4.patch queued for re-testing.
Comment #20
InternetDevels CreditAttribution: InternetDevels commented4: removeunused-2081153-4.patch queued for re-testing.
Comment #21
gokulnk CreditAttribution: gokulnk commentedApplies totally fine. There are no more unused variables.
The previous fails were false alarms due to the outdated Tests in Views module. They are removed now.
I think this is Good To Go.
Comment #22
YesCT CreditAttribution: YesCT commented@xjm asked in #7 to check the rest of core/tests
I looked at the meta, most of the other core/tests... were closed fixed, one was marked wont fix (#2080299: Remove Unused local variable $record from /core/tests/Drupal/Tests/Core/Database/EmptyStatementTest.php).
But on inspecting core/tests, I *did* find other unused variables.
in core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php
$definitions is unused. (if we take it out, $discovery would be unused)
Perhaps these last two lines are not needed at all, there are no asserts or expects after them. Are they just doing something and hoping that if an exception is fired, that the test will fail? Oh, the docs say expectedException.
also:
/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php
$date in
Similar? does it need a var to assign a return value to, but is just checking if an exception is fired?
I tried googling a bit and found http://phpunit.de/manual/3.7/en/appendixes.annotations.html but .. not really sure.
Comment #23
YesCT CreditAttribution: YesCT commentedok. got some info from irc.
we dont need to store the result.
only need code to trigger the exception, it wont return from the call to even try and store the result.
As far as I can tell, this is now taking out all the unused vars in core/tests (that are not being handled by other issues, or aren't won't fixed in other issues)
Comment #26
martin107 CreditAttribution: martin107 commentedInspecting testbot output from #23
Drupal\image\Tests\ImageFieldDisplayTest 140 passes, fails 2
Local browser results 168 passes, 0 fails
Requesting retest,,, the number of tests was 142 now 168 HEAD has changed too much in a week
Comment #27
martin107 CreditAttribution: martin107 commented23: removeunused-2081153-23.patch queued for re-testing.
Comment #28
martin107 CreditAttribution: martin107 commentedYeah green
Visual Inspection of patch reveals nothing I have not seen before in "Remove unused local variables" like tasks.
So +1
Comment #29
miraj9093 CreditAttribution: miraj9093 commentedthe latest patch is not able to apply any more.working on reroll.
Comment #30
miraj9093 CreditAttribution: miraj9093 commentedRerolled patch.
Comment #31
rdatar CreditAttribution: rdatar commentedAdded new patch with only some of the changes from previous patch.
Comment #33
Stefan Lehmann CreditAttribution: Stefan Lehmann commented31: removeunsused-2081153-30.patch queued for re-testing.
Comment #34
Stefan Lehmann CreditAttribution: Stefan Lehmann commentedI can confirm, that PHP Storm says, that these variables are unused and that they get deleted by the patch in #31.
Comment #35
Stefan Lehmann CreditAttribution: Stefan Lehmann commentedPatch is still working.
Comment #36
Stefan Lehmann CreditAttribution: Stefan Lehmann commented31: removeunsused-2081153-30.patch queued for re-testing.
Comment #37
filijonka CreditAttribution: filijonka commentedok this is very strange..in #23 we have a patch that #30 is trying to reroll but that has failed. In #31 it suddenly a new patch not based on #23 and this one is then retested today. No explanations on what some of changes are added and apparently from a patch that has failed..
We need a proper reroll of #23 or a good explanation on #31
Comment #38
lauriiiComment #40
filijonka CreditAttribution: filijonka commented$definitions are used in the first assertEquals so can't be removed
Comment #41
filijonka CreditAttribution: filijonka commentedand it would be nice if could get an interdiff so we know what's the latest patch is related too
Comment #42
YesCT CreditAttribution: YesCT commented(note, did this investigation before #38 was posted)
====
1st, what happened to the unused vars from #23 and #30:
#23 addressed
DateTimePlusTest CssCollectionRendererUnitTest DerivativeDiscoveryDecoratorTest MimeTypeMatcherTest
#30 did also.
but in #23
- $definitions = $discovery->getDefinitions();
+ $discovery->getDefinitions();
}
was in function testInvalidDerivativeFetcher()
this was fixed in #2168159: Plugin Derivatives don't work with Objects returned from Annotations
the reroll in #30
- $definitions = $discovery->getDefinitions();
+ $discovery->getDefinitions();
// Ensure that both test derivatives got added.
$this->assertEquals(2, count($definitions));
took out a used $definitions from testGetDerivativeFetcherWithAnnotationObjects()
oops!
so that should not be done.
#2019123: Use the same canonical URI paths as for HTML routes took out MimeTypeMatcherTest
(I think AcceptHeaderMatcherTest::testNoRouteFound() has the equivalent test, and it does not have the unused var. So, ok.)
but #31 is still missing the DateTime one.
--
#2080299: Remove Unused local variable $record from /core/tests/Drupal/Tests/Core/Database/EmptyStatementTest.php is a separate (won't fix) issue.
--
new unused vars:
core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTest.php
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
#2223615: Use request stack in local task/action manager took out where $request was used, but didn't take out where it was set.
core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php
testValidateParameterTypes()
$ignored_token = $this->generator->get();
testInvalidParameterTypes()
$ignored_token = $this->generator->get();
from #2245003: Use a random seed instead of the session_id for CSRF token generation (but the interdiff there didn't show the unused vars being added.... :( )
=============
patch coming.
Comment #43
YesCT CreditAttribution: YesCT commented#38 added back taking out the DateTimePlusTest removing of the unused var. good.
Some weirdness in CssCollectionRendererUnitTest newlines after removing unused code, so fixing that.
Interdiff shows that, and also removing the new unused vars from LocalTaskIntegrationTest and CsrfTokenGeneratorTest
---
Rerunning the inspector in phpstorm for unused vars in core/tests shows only the wont fixed EmptyStatementTest one. So I think we have them all now.
---
Issue summary is up-to-date.
Probably the whole patch is the one to review.
Comment #44
filijonka CreditAttribution: filijonka commentedis this needed? A get function should always return a value and which previous line indicated, if we don't use that value the call for this function shouldn't be needed at all.
Comment #45
YesCT CreditAttribution: YesCT commented@filijonka the comment above it is:
"// Ensure that there is a valid token seed on the session."
so seems like it needs the get to ensure there is a *seed*.
Maybe that line needs a better comment?
Comment #46
filijonka CreditAttribution: filijonka commentedomg how could I not see that line!? well the answer is clear and in this case the get is also used to add the value to the session.
I think that was the only thing that caught my eye so probably rtbc but will do one more check before I do that
Comment #47
filijonka CreditAttribution: filijonka commentedComment #49
filijonka CreditAttribution: filijonka commentedComment #50
martin107 CreditAttribution: martin107 commentedSit down to reroll now.
Comment #51
martin107 CreditAttribution: martin107 commentedPatch still applies... looks like testbot may be down
close inspection of fail reveals
"No space left on device"
will force retest in a short while....
Comment #52
martin107 CreditAttribution: martin107 commented43: removeunused-2081153-43.patch queued for re-testing.
Ok have seen testbot behave itself in other issues
Comment #53
YesCT CreditAttribution: YesCT commentedok. green again. rtbc per #47.
Comment #54
martin107 CreditAttribution: martin107 commentedPatch looks good to me
Shamelessly nominating this for a quickFix
BUT realistically recognise this may be LOW priority as it will be NOT be affected by the looming May 27 deadline
https://drupal.org/node/2247991
Comment #55
YesCT CreditAttribution: YesCT commented@alexpott said let's wait for the disruptive patch window, which would be May 29 since Alpha 12 is due May 28: https://groups.drupal.org/node/422743
Comment #56
martin107 CreditAttribution: martin107 commentedThanks for the prompt response....
Comment #57
alexpottThe patch in #43 does not remove all unused variables.
Comment #58
YesCT CreditAttribution: YesCT commentedSorry, I dont know how I missed that one.
I checked it again, and this does remove all the unused variables.
And that iterator change looks fine.
Comment #59
alexpottCommitted e1351af and pushed to 8.x. Thanks!
Comment #62
Stefan Lehmann CreditAttribution: Stefan Lehmann commented