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

Skip to content

Commit 8701b45

Browse files
authored
mnior: reboot kernel in database resetter instead of shutdown (#1059)
1 parent 965fe3c commit 8701b45

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

config/orm.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
->decorate(OrmResetter::class, priority: 10)
4646
->args([
4747
service('.inner'),
48+
param('kernel.build_dir')
4849
])
4950
;
5051
}

src/ORM/ResetDatabase/DamaDatabaseResetter.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;
1717
use Symfony\Component\HttpKernel\KernelInterface;
18+
use Symfony\Component\HttpKernel\RebootableInterface;
19+
use Zenstruck\Assert;
1820
use Zenstruck\Foundry\Configuration;
1921
use Zenstruck\Foundry\Persistence\PersistenceManager;
2022
use Zenstruck\Foundry\Persistence\ResetDatabase\ResetDatabaseManager;
@@ -27,6 +29,7 @@ final class DamaDatabaseResetter implements OrmResetter
2729
{
2830
public function __construct(
2931
private OrmResetter $decorated,
32+
private string $kernelBuildDir,
3033
) {
3134
}
3235

@@ -50,12 +53,15 @@ public function resetBeforeFirstTest(KernelInterface $kernel): void
5053
Configuration::instance()->stories->loadGlobalStories();
5154
}
5255

53-
// shutdown kernel before re-enabling static connections
54-
// this would prevent any error if any ResetInterface execute sql queries (example: symfony/doctrine-messenger)
55-
$kernel->shutdown();
56-
5756
// re-enable static connections
5857
StaticDriver::setKeepStaticConnections(true);
58+
59+
if (!$kernel instanceof RebootableInterface) {
60+
throw new \InvalidArgumentException('Kernel should be rebootable to work with DAMADoctrineTestBundle.');
61+
}
62+
63+
// let's reboot the kernel to ensure the static connections will be re-created
64+
$kernel->reboot($this->kernelBuildDir);
5965
}
6066

6167
public function resetBeforeEachTest(KernelInterface $kernel): void

0 commit comments

Comments
 (0)