Problem/Motivation
REQUEST_TIME is a deprecated global. There are several issues to remove it's use in core.
This issue is to remove it from just Kernel tests.
There are no usages of REQUEST_TIME in Unit tests.
Proposed resolution
Use \Drupal::time()->getRequestTime() instead of REQUEST_TIME in Kernel tests.
Remaining tasks
Review
Commit
| Comment | File | Size | Author |
|---|
Issue fork drupal-3112284
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:
- 3112284-replace-requesttime-in
changes, plain diff MR !2402
Comments
Comment #2
mpdonadioTook the patch from 2902895-43.patch
- Isolated just the test changes (well, I tried)
- Introduced some changes to KTB and BTB, but not sure how we really want to handle this
- REQUEST_TIME -> $this->requestTime
Comment #4
swatichouhan012 commentedI am working on this issue.
Comment #5
swatichouhan012 commentedI have created patch to remove deprecated REQUEST_TIME, Kindly review .
Comment #6
swatichouhan012 commentedComment #8
hash6 commentedComment #9
mpdonadio@swatichouhan012, thanks for picking up the issue, but #2 really is the starting point. For example,
The scope of this issue is just tests. That particular instance is being handled in a different issue.
This change undoes work in #2. Part of the first patch on the issue was to add the time service and request time to the test bases. We want to avoid using the singleton when possible.
I adjusted the IS to outline this better.
Comment #10
hash6 commentedComment #11
mpdonadioReroll of #2 to account for change in UserBlocksTest.
Comment #13
mpdonadioFew fixes.
Comment #19
mpdonadioCommit credits.
Comment #21
kristen polSee possibly related issues noted here:
https://www.drupal.org/project/drupal/issues/3112283#comment-13605217
Comment #22
adityasingh commentedreroll for 9.1
Comment #23
adityasingh commentedComment #27
andypostComment #28
ankithashettyRerolled the patch in #22, thanks!
Comment #29
andypost@ankithashetty please fix CS report from bot) thank you!
Comment #30
mondrakeWe'll also need a D10 patch with the PHPStan baseline updated, but let's have an agreed D9.4 first
Comment #31
mondrakeComment #32
ankithashettyFixed the CS errors, thanks!
Comment #33
andypostStill not enough)
Comment #34
quietone commentedRemoved some changes in non test files, added some tests, and fixed assertions so an int was compared to an int.
Comment #36
quietone commentedJust noting that the failing tests are all Kernel tests.
Comment #37
jhedstromMoving to NW due to failing tests.
Comment #39
spokjeRebasing against
10.0.xsince in there we have to deal withcore/phpstan-baseline.neon.Also unassigning mpdonadio since it has been 2 years since he worked on this.
Comment #40
spokjeUsed
3112284-34.patchas base for the new MR.Comment #42
daffie commentedLets add a CR for adding the class variables $timeService and $requestTime to the class KernelTestBase and the class BrowserTestBase. Other developers that write tests based on those 2 classes need to know about the added class variables.
Comment #43
spokjeThanks @daffie.
We have a problem here, Houston:
By the looks of it
\Drupal::time()->getRequestTime()and$this->requestTimehave a difference of 2-3 seconds withREQUEST_TIME.This causes test-failures when we compare the timestamp with timestamps like "changed".
How to tackle this?
- Add an offset of 3 seconds to make these tests pass? Which would still cause test failures when we compare timestamps to be equal, since it's either 2 or 3 seconds.
- Use
$_SERVER['REQUEST_TIME']for these tests?- Something completely different?
Putting this on NR (whilst it nowhere nearly ready) to get some eyes/Big Brains/random body parts on this.
Comment #44
spokjeComment #45
andypostonly 5 failures left! great job
Comment #46
spokjeComment #47
mondrakeI would suggest to split this issue in two - one for Functional/FunctionalJavascript and one for Unit/Kernel.
Comment #48
mondrakeFiled #3309104: Replace REQUEST_TIME in Functional and FunctionalJavascript tests.
Comment #49
bhanu951 commentedUpdated title as we created another issue for Replacing REQUEST_TIME in Functional/FunctionalJavascript tests
Comment #50
bhanu951 commentedUploaded current changes to 10.0.x as patch before rebasing to 11.x branch.
@alexpott made below comment on MR #2753
So we might need to replace all usages of
$this->requestTimewith\Drupal::time()->getRequestTime()Comment #51
bhanu951 commentedComment #52
viniciusrp commentedThe patch #50 has error to be applied, I recreated based to version 10.0.x.
Comment #53
smustgrave commentedPatch was moved to an MR. Repostponing on #3309104: Replace REQUEST_TIME in Functional and FunctionalJavascript tests
Comment #54
andypostAny reason it postponed on other conversion?
Comment #55
acbramley commentedThere's still a huge number of changes to non Kernel/Unit test files here. All functional/functionaljs tests are being updated in #3309104: Replace REQUEST_TIME in Functional and FunctionalJavascript tests
Comment #56
acbramley commentedPeeled this back to just Kernel tests and removed the class members entirely. Used variables for $requestTime where appropriate. Pipeline is green :)
No need for a CR now since we're not adding any class members.
Comment #57
smustgrave commentedCould issue summary and title be updated too please
Comment #58
acbramley commentedComment #59
smustgrave commentedmodules/dblog/tests/src/Kernel/DbLogTest.php
modules/views/tests/src/Kernel/RenderCacheIntegrationTest.php
Found 2 more.
Comment #60
acbramley commentedThose 2 come from traits which we're not fixing here (FakeLogEntries and AssertViewsCacheTagsTrait)
If you search the test files you'll see that there are no references to REQUEST_TIME. The traits are fixed in the functional test one
I believe(confirmed).Comment #61
smustgrave commentedThanks for confirming @acbramley
Comment #63
catchCommitted/pushed to 11.x, thanks!