Skip to content

Conversation

@nikophil
Copy link
Member

@nikophil nikophil commented Sep 23, 2025

⚠️ This PR is on top of #968 - please only review the two last commits

@nikophil nikophil changed the title feat/attribute for reset database 2 feat(2.9): deprecate ResetDatabase trait Sep 23, 2025
@nikophil nikophil force-pushed the feat/attribute-for-reset-database-2 branch from 43f4a0b to 91dd0a7 Compare September 23, 2025 10:06
@nikophil nikophil force-pushed the feat/attribute-for-reset-database-2 branch from 91dd0a7 to a3f404b Compare September 24, 2025 17:11
@nikophil nikophil force-pushed the feat/attribute-for-reset-database-2 branch 11 times, most recently from f898cd3 to f48fbd2 Compare October 11, 2025 08:42
public function boot(): void
{
if ($this->container) {
if ($this->container && (!Configuration::isBooted() || !FoundryExtension::isEnabled())) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@HypeMC, just for you to know:

now we're deprecating the usage of ResetDatabase trait in favor of an attribute + usage of the PHPUnit extension, I had errors ServiceNotFoundException: The "kernel" service is synthetic, it needs to be set at boot time before it can be used. in the database reset testsuite.

Because this currently needs to work with and without the ResetDatabase trait, the only solution I found was to check if the extension is enabled.

Don't hesitate if you have another idea. Anyway, this ugly stuff will be removed in Foundry 3

Copy link
Contributor

@HypeMC HypeMC Oct 21, 2025

Choose a reason for hiding this comment

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

@nikophil Hello, thank you for the heads-up. I've tested this branch, and unfortunately, this change seems to bring back the original issue. I haven't had time to look into it in detail yet, but I'll try to figure it out.

EDIT: Switching to the #[ResetDatabase] attribute does solve the problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

The reason the EarlyBootedKernelWithTraitsTest passes is that it's no longer the first test, so ResetDatabaseManager::hasDatabaseBeenReset is true.
It needs to be false for the test to fail, e.g. try running it individually:

./phpunit tests/Integration/ResetDatabase/EarlyBootedKernelWithTraitsTest.php

Perhaps the before() method could be improved:

#[BeforeClass(10)]
public static function before(): void
{
    $ref = new \ReflectionProperty(ResetDatabaseManager::class, 'hasDatabaseBeenReset');
    $ref->setValue(false);

    self::bootKernel();
}

Copy link
Member Author

Choose a reason for hiding this comment

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

@HypeMC I'm not sure what's the best way to fix this: we would need a marker to tell "reset database trait was used" to decide whether to check Configuration::isBooted() in ZenstruckFoundryBundle::boot() method

this becomes overly complex for such a niche bug, moreover that the problem will only occur when using the newly deprecated trait ResetDatabase

I think it will stay this way, unless you have a good idea

@nikophil nikophil force-pushed the feat/attribute-for-reset-database-2 branch 2 times, most recently from bbeb282 to 874ce5a Compare October 17, 2025 05:54
@nikophil nikophil force-pushed the feat/attribute-for-reset-database-2 branch from 874ce5a to 557aa86 Compare October 27, 2025 09:25
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