Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FrameworkBundle] Ensure a fresh container is used after cache warmup in KernelTestCase#63016

Merged
nicolas-grekas merged 1 commit into
symfony:6.4from
lyrixx:test-clean-container
Jan 12, 2026
Merged

[FrameworkBundle] Ensure a fresh container is used after cache warmup in KernelTestCase#63016
nicolas-grekas merged 1 commit into
symfony:6.4from
lyrixx:test-clean-container

Conversation

@lyrixx
Copy link
Copy Markdown
Member

@lyrixx lyrixx commented Jan 8, 2026

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

When the cache is empty, and a test starts, it will compile the container, and
warm up the cache. However, this means that the container used during the test
is not fresh anymore, as it has been compiled with the cache warmer service
registered. This change ensures that if the cache warmer is detected in the
container after booting, a new kernel is booted to provide a fresh container for
the test.

Comment thread src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php Outdated
@OskarStark OskarStark changed the title [FrameworkBundle] Ensure a fresh container is used after cache warmup in KernelTestCase [FrameworkBundle] Ensure a fresh container is used after cache warmup in KernelTestCase Jan 8, 2026
… in KernelTestCase

When the cache is empty, and a test starts, it will compile the container, and
warm up the cache. However, this means that the container used during the test
is not fresh anymore, as it has been compiled with the cache warmer service
registered. This change ensures that if the cache warmer is detected in the
container after booting, a new kernel is booted to provide a fresh container for
the test.
@lyrixx lyrixx force-pushed the test-clean-container branch from 76acd37 to 2af5e9c Compare January 12, 2026 08:58
@nicolas-grekas
Copy link
Copy Markdown
Member

Thank you @lyrixx.

@nicolas-grekas nicolas-grekas merged commit 2234b44 into symfony:6.4 Jan 12, 2026
10 of 12 checks passed
@lyrixx lyrixx deleted the test-clean-container branch January 12, 2026 10:11
nicolas-grekas added a commit that referenced this pull request Mar 4, 2026
…elTestCase (nicolas-grekas)

This PR was merged into the 6.4 branch.

Discussion
----------

[FrameworkBundle] Fix stale container after reboot in KernelTestCase

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

The reboot logic added in #63016 to get a fresh container after cache warmup populates two static freshness caches: `Kernel::$freshCache` and `SelfCheckingResourceChecker::$cache`. These caches persist across `shutdown()`/`boot()` cycles within the same PHP process, preventing subsequent boots from detecting resource changes (e.g. `FileExistenceResource`).

This causes `ensureKernelShutdown()` + `bootKernel()` to reuse a stale container even when tracked resources have changed between boots.

The fix clears both static caches via reflection in `ensureKernelShutdown()` when a cache warmer reboot has occurred. The clearing is guarded by a flag to avoid unnecessary reset on every shutdown, and wrapped in try/catch to be forward-compatible with future refactoring of these internals.

Commits
-------

c9f0161 [FrameworkBundle] Fix stale container after reboot in KernelTestCase
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.

4 participants