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

Skip to content

Fix edge case with Doctrine Middleware & early kernel boot#993

Merged
nikophil merged 1 commit into
zenstruck:2.xfrom
HypeMC:doctrine-middleware
Oct 2, 2025
Merged

Fix edge case with Doctrine Middleware & early kernel boot#993
nikophil merged 1 commit into
zenstruck:2.xfrom
HypeMC:doctrine-middleware

Conversation

@HypeMC
Copy link
Copy Markdown
Contributor

@HypeMC HypeMC commented Sep 27, 2025

This fixes an edge case that occurs when Doctrine requires the kernel service (or any other synthetic one) and the kernel is booted before ResetDatabase::_resetDatabaseBeforeFirstTest().

Error example:

  1. Zenstruck\Foundry\Tests\Integration\ResetDatabase\EarlyBootedKernelTest
    Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: The "kernel" service is synthetic, it needs to be set at boot time before it can be used.

This happens because when ResetDatabaseManager calls self::bootKernel(), the old kernel is shut down, but a reference to its container (which no longer has the kernel service) remains. The new container instance is never used because of Configuration::isBooted().

@nikophil
Copy link
Copy Markdown
Member

nikophil commented Oct 2, 2025

thanks @HypeMC

out of curiosity, in which "real world" scenario did you have this edge case?

@nikophil nikophil merged commit 55f2689 into zenstruck:2.x Oct 2, 2025
73 checks passed
@nikophil
Copy link
Copy Markdown
Member

nikophil commented Oct 5, 2025

released in 2.7.3

@HypeMC HypeMC deleted the doctrine-middleware branch October 5, 2025 09:57
@HypeMC
Copy link
Copy Markdown
Contributor Author

HypeMC commented Oct 5, 2025

out of curiosity, in which "real world" scenario did you have this edge case?

@nikophil Hi, sorry for the late reply.

My real world example is a combination of several different features.
The first is a library that has a Doctrine middleware which requires Symfony's router to generate URLs when a transaction is committed.

The second is a router decorator that uses Symfony's translator to generate translated routes. The router caches certain things, so it requires access to the kernel to get the cache directory and environment.

If you have a test that boots the kernel in a setUpBeforeClass() method and that test runs first, you get the error. It was not visible for a long time until I started testing ParaTest. That is when I came across this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants