Skip to content

Conversation

@yoeunes
Copy link
Contributor

@yoeunes yoeunes commented Nov 8, 2025

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues -
License MIT

This PR fixes a behavioral inconsistency between NativeClock and MockClock when handling negative sleep durations.

The Problem:

  • NativeClock::sleep(-10): Silently does nothing. The time does not change.
  • MockClock::sleep(-10): Travels backward in time by 10 seconds.

This inconsistency can lead to unreliable tests, as the mock does not accurately represent the real implementation's behavior for this edge case.

The Fix:
This fix adds a guard clause to MockClock::sleep() to ignore any duration less than or equal to zero, perfectly matching the behavior of NativeClock.

Before (The Bug):

$clock = new MockClock('2000-01-01 12:00:00');
$clock->sleep(-10);
// $clock->now() is '2000-01-01 11:59:50'

After (The Fix):

$clock = new MockClock('2000-01-01 12:00:00');
$clock->sleep(-10);
// $clock->now() is '2000-01-01 12:00:00'

@yoeunes yoeunes force-pushed the mockclock-negative-sleep branch from b5e7500 to 87ec08d Compare November 11, 2025 21:24
@nicolas-grekas
Copy link
Member

Thank you @yoeunes.

@nicolas-grekas nicolas-grekas merged commit 9e0088f into symfony:6.4 Nov 12, 2025
10 of 11 checks passed
This was referenced Nov 13, 2025
This was referenced Dec 7, 2025
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.

5 participants