@@ -1321,6 +1321,45 @@ files.
13211321 - ' %kernel.root_dir%/migrations/configuration.php'
13221322 - ' migrations/configuration.yaml'
13231323
1324+ Extending reset mechanism
1325+ .........................
1326+
1327+ The reset mechanism can be extended thanks to decoration:
1328+
1329+ ::
1330+
1331+ use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
1332+ use Symfony\Component\DependencyInjection\Attribute\When;
1333+ use Symfony\Component\HttpKernel\KernelInterface;
1334+ use Zenstruck\Foundry\ORM\ResetDatabase\OrmResetter;
1335+
1336+ // The decorator should be declared in test environment only.
1337+ #[When('test')]
1338+ // You can also decorate `MongoResetter::class`.
1339+ #[AsDecorator(OrmResetter::class)]
1340+ final readonly class DecorateDatabaseResetter implements OrmResetter
1341+ {
1342+ public function __construct(
1343+ private OrmResetter $decorated
1344+ ) {}
1345+
1346+ public function resetBeforeFirstTest(KernelInterface $kernel): void
1347+ {
1348+ // do something once per test suite (for instance: install a PostgreSQL extension)
1349+
1350+ $this->decorated->resetBeforeFirstTest($kernel);
1351+ }
1352+
1353+ public function resetBeforeEachTest(KernelInterface $kernel): void
1354+ {
1355+ // do something once per test case (for instance: restart PostgreSQL sequences)
1356+
1357+ $this->decorated->resetBeforeEachTest($kernel);
1358+ }
1359+ }
1360+
1361+ If using a standard Symfony Flex app, this will be autowired/autoconfigured. If not, register the service
1362+
13241363.. _object-proxy :
13251364
13261365Object Proxy
0 commit comments