Skip to content
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

[Clock][RFC] pass \DateTinterval or DateInterface to ClockInterface::sleep() #51850

Closed
nikophil opened this issue Oct 5, 2023 · 7 comments
Closed
Labels
Clock RFC RFC = Request For Comments (proposals about features that you want to be discussed)

Comments

@nikophil
Copy link
Contributor

nikophil commented Oct 5, 2023

Description

I think ClockInterface::sleep() in tests is mainly used to perform "time jumps" to predefined dates, thus it is cumbersome to always have to make the conversion to seconds in userland.

I think it would be useful to be able to pass \DateInterval or \DateInterface to ClockInterface::sleep()

The method would become something like:

public function sleep(float|int|\DateInterval|\DateInterface $sleep) void
{
    $sleep = match(true) {
        $sleep instanceof \DateInterval => // convert interval to seconds, throw if negative,
        $sleep instanceof \DateInterface => // convert date interface to seconds from now(), throw if negative,
       default => $sleep
    }

    // ...
}

I'd be pleased to perform the PR if it seems acceptable.

Example

No response

@carsonbot carsonbot added Clock RFC RFC = Request For Comments (proposals about features that you want to be discussed) labels Oct 5, 2023
@OskarStark
Copy link
Contributor

WDYT @nicolas-grekas ?

@stof
Copy link
Member

stof commented Oct 10, 2023

I'd rather keep the interface simple and have that implemented as a utility function taking the Clock and the interval/datetime.

@stof
Copy link
Member

stof commented Oct 10, 2023

Also, converting an interval to seconds is ill-defined (how many seconds is 1 month ?)

@nicolas-grekas
Copy link
Member

Technically we can add this to MockClock if that can help testing, but for the interface, it'd be a BC break.
More importantly, I don't see the use case: sleeping should happen only for a few (µ)seconds. I don't see any process wait more.

@nikophil
Copy link
Contributor Author

The use case is indeed for tests purpose, in order to check life cycle of an object got example. But now I see your answer, I'm really wondering if this issue is really worth it: something like $mockClock->sleepUntil($date) is really the same as self::mockTime($date)

@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@derrabus
Copy link
Member

I think we can close this. Thank you for the proposal though.

@carsonbot carsonbot removed the Stalled label Apr 13, 2024
@derrabus derrabus closed this as not planned Won't fix, can't repro, duplicate, stale Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clock RFC RFC = Request For Comments (proposals about features that you want to be discussed)
Projects
None yet
Development

No branches or pull requests

6 participants