Skip to content

refactor: explicitly boot Foundry in ResetDatabase#1049

Merged
nikophil merged 1 commit intozenstruck:2.xfrom
nikophil:fix/reset-database-boot-foundry
Jan 10, 2026
Merged

refactor: explicitly boot Foundry in ResetDatabase#1049
nikophil merged 1 commit intozenstruck:2.xfrom
nikophil:fix/reset-database-boot-foundry

Conversation

@nikophil
Copy link
Member

@nikophil nikophil commented Jan 8, 2026

related to #1034

@nikophil nikophil marked this pull request as draft January 8, 2026 12:46
@nikophil nikophil force-pushed the fix/reset-database-boot-foundry branch from 1b8495f to a2a65d5 Compare January 8, 2026 12:58
@nikophil
Copy link
Member Author

nikophil commented Jan 8, 2026

@HypeMC would this do the trick?

@HypeMC
Copy link
Contributor

HypeMC commented Jan 8, 2026

@nikophil Thank you, I'll give it a try right away.

Comment on lines +80 to +81
$kernel = $createKernel();

Copy link
Contributor

Choose a reason for hiding this comment

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

@nikophil Unfortunately, this change sees to break the following case:

class SomeTest extends WebTestCase
{
    use Factories;
    use ResetDatabase;

    public function testMyCode(): void
    {
        $client = self::createClient();

        // ...
    }

LogicException: Booting the kernel before calling "Symfony\Bundle\FrameworkBundle\Test\WebTestCase::createClient()" is not supported, the kernel should only be booted once.

Copy link
Member Author

@nikophil nikophil Jan 8, 2026

Choose a reason for hiding this comment

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

Damn... I'll add this use case to our test suite right now! A test using WebTestCase already exists, but it does not use ResetDatabase trait

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 mind to test this new version, please?

I added a test to ensure ResetDatabase does not mess with self::createClient()

Copy link
Contributor

Choose a reason for hiding this comment

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

On it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@nikophil Sadly, this reintroduces the original issue:

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: The "kernel" service is synthetic, it needs to be set at boot time before it can be used.

Copy link
Member Author

@nikophil nikophil Jan 8, 2026

Choose a reason for hiding this comment

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

but the test you introduced in #993 is still green, we'll have to figure out why, I guess

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll look into it tonight, and try to figure it out.

Copy link
Member Author

@nikophil nikophil Jan 8, 2026

Choose a reason for hiding this comment

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

super nice, thanks. Sorry to come back on this stuff but this would unlock an easy way to integrate Foundry with Behat, which is one of the next things I'd like to see in foundry

Copy link
Contributor

Choose a reason for hiding this comment

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

@nikophil Apologies for the late response, I couldn't find the time yesterday. Long story short, one test failed because it didn't use Factories. Once that was added, everything passed. So this fix is actually good. Thank you for investigating this and sorry for the false alert.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok thanks, this is very nice.

This kind of problem won't exist anymore once we have deprecated Factories trait 😄

@nikophil nikophil force-pushed the fix/reset-database-boot-foundry branch from a2a65d5 to 0c44b18 Compare January 8, 2026 14:15
@nikophil nikophil force-pushed the fix/reset-database-boot-foundry branch from 0c44b18 to f286f3a Compare January 8, 2026 14:20
@nikophil nikophil requested a review from HypeMC January 8, 2026 14:39
@nikophil nikophil merged commit 6c3a127 into zenstruck:2.x Jan 10, 2026
69 checks passed
@nikophil nikophil deleted the fix/reset-database-boot-foundry branch January 10, 2026 08:51
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