Description
Description
Hello,
There is a little (annoying) piece of code in symfony, and I would like to enhance of it
symfony/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php
Lines 157 to 160 in 7ce2db5
If you want to configure the container before the first request, it's possible.
But if you already have issued a request, it's not possible anymore.
I know it's possible to disable the reboot() of the container, but it has drawbacks (that's why we added the reboot). And in my case I do want a restart!
Some code to understand:
class HomepageTest extends WebTestCase
{
public function testSomething(): void
{
$client = static::createClient();
// $client->disableReboot(); // it fix this issue, but it's a bad idea.
$client->request('GET', '/');
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('h1', 'Hello World');
static::getContainer()->set(You::class, new class implements HelloInterface {
public function hello(): string
{
return 'Hello mock';
}
});
$client->request('GET', '/you');
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('h1', 'Hello mock');
}
}
This test does not work. Since the container is restarted just before issuing the second request, our mock doesn't exist anymore.
I would like to introduce something like this:
// test.php
$client->configureContainer(function ($container) {
$container->set(You::class, new class implements HelloInterface {
public function hello(): string
{
return 'Hello mock';
}
});
});
And this code will be execute after the reboot, but before the request is issued.
WDTY?
If accepted, I'll do the PR!
Side note: I tried so many things, like static::ensureKernelIsShutDown
, or self::$kernel->shutdown()
and nothing works! It's even worse : there is a miss-match between the kernel in the client and the one in the test (because everything is static)
Example
No response