Commit 3cbbe26
committed
This PR was merged into the 6.3 branch.
Discussion
----------
[Clock] Fix calling `mockTime()` in `setUpBeforeClass()`
| Q | A
| ------------- | ---
| Branch? | 6.3
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | -
| License | MIT
Currently, calling `mockTime()` in `setUpBeforeClass()` results in the static `$originalClock` variable always being an instance of `MockClock`.
Since `setUpBeforeClass()` is called **before** `saveClockBeforeTest()`, the native clock is never saved. However, by calling `mockTime()` in `setUpBeforeClass()`, the `Clock::set()` method is called, and the clock is set to an instance of `MockClock`. Then, when `saveClockBeforeTest()` is called, it sets the static `$originalClock` variable to that `MockClock` instance.
The problem becomes more noticeable on Symfony 6.4 where `MockClock` uses `DatePoint`, which itself uses `Clock::get()`:
https://github.com/symfony/symfony/blob/d67685897f2246fd22bf8b2ab684e38c14666079/src/Symfony/Component/Clock/DatePoint.php#L24-L27
Commits
-------
522fe98 [Clock] Fix calling `mockTime()` in `setUpBeforeClass()`
File tree
2 files changed
+67
-1
lines changed- src/Symfony/Component/Clock
- Tests
- Test
2 files changed
+67
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
49 | | - | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
53 | 59 | | |
54 | 60 | | |
55 | 61 | | |
| |||
Lines changed: 60 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
0 commit comments