Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Clock] Autowire PSR interface #48347

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

Merged
merged 1 commit into from
Nov 28, 2022
Merged

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Nov 26, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

Sorry for doing two things in a single PR, but it felt too small to split.

  • The first commit I'm sure about: autowire PSR's ClockInterface, just like we do for e.g. the EventDispatcherInterface
  • The second commit is something I want to propose after trying to write some docs on using Clock as a framework user: It isn't trivial to change the class of a definition from an application... and using a fixed moment in time while testing is the advantage of a clock component. So what about automatically switching to it when test mode is enabled? @nicolas-grekas

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the test part, I think I'd prefer not have it but I can't argue why 😬

@wouterj
Copy link
Member Author

wouterj commented Nov 27, 2022

I'm not sure about the test part, I think I'd prefer not have it but I can't argue why 😬

Yeah, same. It doesn't feel very idiomatic Symfony to "force" something like this depending on the test mode. But on the other hand, I would like to argue that this is the only feature of the Clock component/service. Using this service implies you want to fix testability of your time-based logic and as such, I'm thinking this is sort of opt-in when deciding using the clock service?

Anyway, we have to think about the practical side of the clock service and answer two questions before 6.2.0 stable (as that's our last chance to freely change behavior of this service):

  1. Do we want people to use MockClock in integration/application tests, or do we want to only recommend this in unit tests?
  2. If we want to, how would anyone use MockClock in integration tests of an application while using the clock service?

If the answer of (1) is only unit tests, we can forget about this change and always use NativeClock in the service container.
If we need to answer (2), I would say the current way is using a compiler pass - which isn't that great of a DX for application developers.

@chalasr
Copy link
Member

chalasr commented Nov 27, 2022

I tend to think we'd better only document the testing part for now.

@nicolas-grekas
Copy link
Member

MockClock for unit testing LGTM. For integration, ppl can redefine the clock service under when@test, no need for a compiler pass, isn't it? They could also call self::getContainer()->set() if I'm not wrong (although @lyrixx has a case where this doesn't work as smoothly as we might want?)

@wouterj wouterj changed the title [Clock] Autowire PSR interface (and use MockClock in test?) [Clock] Autowire PSR interface Nov 28, 2022
@nicolas-grekas
Copy link
Member

Thank you @wouterj.

@nicolas-grekas nicolas-grekas merged commit 3bc06b3 into symfony:6.2 Nov 28, 2022
@wouterj wouterj deleted the clock-psr branch November 28, 2022 12:43
@fabpot fabpot mentioned this pull request Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.