-
Notifications
You must be signed in to change notification settings - Fork 824
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NEW: Mock sleep unit test utility. #10317
NEW: Mock sleep unit test utility. #10317
Conversation
I don't think we should be including methods that are only meant to be called in tests into production codebases. I'll leave this open for a day or two in case a core committer disagrees with me, though. |
@GuySartorelli Fair enough, is there a better place for it though? For example we could add a TestOnly service maybe under the Dev namespace? |
I'm not sure, to be honest. I'd love (in the long term) for all of the test-related stuff to be moved out of framework altogether, and be in its own module that can be included as a dev dependency... but we're a ways off doing something like that just yet. This might be the best place for it at the moment, to be honest, now that I've spent a bit more time considering it. |
All good @GuySartorelli , happy to keep the PR open. Having a separate module for this sounds great. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair consideration from Guy, I would agree here. We can wait forever or just get it in now and move it out later with other stuff.
Let's wait a day or two if Max or Steve have a different view, and if not we can get it in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does seem like the wrong place
Somewhere in src/Dev seems like it would be better. There are already some other Test*.php classes there such as TestSession and TestMailer
So perhaps create a new class Dev/TestDateTime.php and put this method it there?
Couldn't it be added to How would one expect this to work if |
@dhensby Move the feature to new location as requested, please review. In case time mock is not set it will fallback to current time which I think is fine. public static function now()
{
$time = self::$mock_now ? self::$mock_now->Value : time();
/** @var DBDatetime $now */
$now = DBField::create_field('Datetime', $time);
return $now;
} |
@mfendeksilverstripe Looks like you added the method twice? |
@GuySartorelli That's because |
Ahh yup, fair point. I forgot about that. |
I'd be inclined to just delete the PHPUnit 5.7 version, it's an ancient API we shouldn't be developing for it. Everyone is encouraged to migrate off it. Unit tests in CI only get tested against PHPUnit 9 What happens if you put a |
Just for the sake of clarity: I assume you mean the 5.7 version of the new method, not of the class itself. |
Cool. Is the time reset after each test? I assume it is, just making sure... |
If it isn't, that's a fundamental issue with the mock now functionality as a whole, not a new problem introduced with this PR. |
Right, but a dev who implements |
@emteknetnz You've still got a review here with requested changes - is that for removing the new method on the old phpunit class? I don't think it's worth holding up merging for that personally, are you okay with the PR as is or do you still want some changes made? |
I'm not too attached, feel free to merge if you see fit |
NEW: Mock sleep unit test utility.
Simple utility function for unit tests. Use instead of
sleep()
. I found this quite handy is several projects, we might as well make the code reusable.