Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Mock date() in ClockMock#27890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Mock date() in ClockMock#27890
Uh oh!
There was an error while loading.Please reload this page.
Conversation
dontub commentedJul 7, 2018
The test fails because |
nicolas-grekas commentedJul 8, 2018
Thanks for the PR@dontub |
dontub commentedJul 9, 2018
I thought it is more bug fix than feature because it fixes unexpected behaviour, though I can understand if you see it as feature. |
As to the PHP documentation date() uses the value of time() as timestampif none is given. date() has to be mocked in ClockMock as well for thisstill being true, otherwise \time() is used as default.
acasademont commentedJul 12, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hi@nicolas-grekas and@dontub I detected a small bug in the microtime(false) function (it should have 8 decimal positions instead of 6). I don't know if I should send a specific PR just for that bug or add it to this one? Also...I have the problem of running the tests, it uses the ClockMock of the vendor directory, how did you end up fixing it? Thanks! |
dontub commentedJul 13, 2018
@acasademont I also noticed this issue (see end of the initial comment). You can run the tests for the phpunit bridge directly from the Bridge/PhpUnit/ directory. Just run |
acasademont commentedAug 22, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Oops sorry, missed the comment.@nicolas-grekas should we also fix that? I believe it might depend on the OS PHP is installed in? On Mac/LInux is 8 decimal positions |
nicolas-grekas commentedAug 22, 2018
@acasademont fix welcome (it's always 8 decimals on all OSes so it's safe fixing unconditionally.) |
acasademont commentedAug 24, 2018
@nicolas-grekas sure no problem! I was waiting for this one to be merged so that I could reuse the newly created tests. Although it's such a small fix maybe@dontub can include it in this PR... |
nicolas-grekas commentedAug 24, 2018
Thank you@dontub. |
nicolas-grekas commentedAug 24, 2018
Now merged, fix welcome (on branch 2.8) |
This PR was merged into the 4.2-dev branch.Discussion----------Mock date() in ClockMock| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no (In case `date()` is mocked in some other way execution would fail because of redeclaration. Could be avoided with an extra `function_exists()` check. WDYT?)| Deprecations? | no| Tests pass? | yes| Fixed tickets || License | MIT| Doc PR |As to the [PHP documentation](https://secure.php.net/manual/en/function.date.php) `date()` uses the value of `time()` as timestamp if none is given. `date()` has to be mocked in ClockMock as well for this still being true, otherwise `\time()` is used as default.BTW: The msec part of `microtime()` has 8 fractional digits on my system, ClockMock returns only 6...Commits-------e8ba79a [Bridge/PhpUnit] Mock date() in ClockMock
ro0NL commentedAug 24, 2018
What about related funcs suchs as |
nicolas-grekas commentedAug 24, 2018
Nobody uses them :) |
javiereguiluz commentedSep 7, 2018
I've createdsymfony/symfony-docs#10287 to document this new feature. Please, don't forget to create a doc issue for every new feature. @dontub it'd be great if you could provide the docs for this feature. If you want to try it and need some help, we'll be glad to help you in the Symfony Docs repository. Thanks! |
…ont)This PR was merged into the 2.8 branch.Discussion----------[PHPUnitBridge] Fix ClockMock microtime() format| Q | A| ------------- | ---| Branch? | 2.8 <!-- see below -->| Bug fix? | yes| New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files -->| BC breaks? | no <!-- seehttps://symfony.com/bc -->| Deprecations? | yes/no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tests pass? | no <!-- please add some, will be required by reviewers -->| Fixed tickets | <!-- #-prefixed issue number(s), if any -->| License | MIT| Doc PR | <!-- required for new features -->This is a follow-up PR to#27890 to fix the `microtime` precision, it should be 8 decimals instead of the current 6 (seehttps://3v4l.org/GYacF)The problem now is that due to the new tests the whole testsuite will fail if run from the main directory, as hhvm and 5.4 targets are doing, due to phpunit using the wrong `ClockMock` class. Tests for 7.1 and 7.2 pass because they `cd` into the component directory.Commits-------e3732b6 [PHPUnitBridge] Fix microtime() format
Uh oh!
There was an error while loading.Please reload this page.
date()is mocked in some other way execution would fail because of redeclaration. Could be avoided with an extrafunction_exists()check. WDYT?)As to thePHP documentation
date()uses the value oftime()as timestamp if none is given.date()has to be mocked in ClockMock as well for this still being true, otherwise\time()is used as default.BTW: The msec part of
microtime()has 8 fractional digits on my system, ClockMock returns only 6...