Skip to content

Commit

Permalink
docs: how to extend database reset mechanism (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil authored Oct 24, 2024
1 parent 3a3c7d6 commit 470d927
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,45 @@ files.
- '%kernel.root_dir%/migrations/configuration.php'
- 'migrations/configuration.yaml'
Extending reset mechanism
.........................

The reset mechanism can be extended thanks to decoration:

::

use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
use Symfony\Component\DependencyInjection\Attribute\When;
use Symfony\Component\HttpKernel\KernelInterface;
use Zenstruck\Foundry\ORM\ResetDatabase\OrmResetter;

// The decorator should be declared in test environment only.
#[When('test')]
// You can also decorate `MongoResetter::class`.
#[AsDecorator(OrmResetter::class)]
final readonly class DecorateDatabaseResetter implements OrmResetter
{
public function __construct(
private OrmResetter $decorated
) {}

public function resetBeforeFirstTest(KernelInterface $kernel): void
{
// do something once per test suite (for instance: install a PostgreSQL extension)

$this->decorated->resetBeforeFirstTest($kernel);
}

public function resetBeforeEachTest(KernelInterface $kernel): void
{
// do something once per test case (for instance: restart PostgreSQL sequences)

$this->decorated->resetBeforeEachTest($kernel);
}
}

If using a standard Symfony Flex app, this will be autowired/autoconfigured. If not, register the service

.. _object-proxy:

Object Proxy
Expand Down

0 comments on commit 470d927

Please sign in to comment.