如何设置学说测试以自动回滚交易(以避免DIRTY DB)?

发布于 2025-02-08 08:10:26 字数 396 浏览 2 评论 0原文

我想在主Symfony Dev数据库中进行有关学说的测试。最好是完全不存储东西(每次测试回滚)。我该怎么做?我可以使用现成的框架/libs/设置吗?

在工作中,我们有一个非常流畅的Java设置,其中数据库测试扩展了我们创建的自定义Junit测试类。 thractionallySolatedItest用于运行在交易中运行所有内容的所有内容(fast),firmolisolatedItest用于测试自己begin> begin()<代码> > commit(),Quitt等。这会创建并撕下每个测试模板创建的数据库(重/慢)。

在PHP中进行Symfony Development时,拥有这样的东西会很漂亮。

I would like to have tests dealing with Doctrine not persist stuff in the main Symfony dev database. Preferably by not storing stuff at all (rolling back per test). How would I do this? Are there ready-made frameworks/libs/setups I can use?

At work we have a really smooth working Java setup where database tests extends custom JUnit test classes we have created. TransactionallyIsolatedITest for running everything within a transaction that is rolled back (fast), FullyIsolatedITest for testing stuff that do their own begin(), commit(), stuff, etc. This creates and tears down a database created from a template for each test (heavy/slow).

Having something like this would be beautful when doing Symfony development in PHP.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

错々过的事 2025-02-15 08:10:26

In the Symfony 6 documentation they actually describe and show how to reset the database before every test using the DAMADoctrineTestBundle.

鲜血染红嫁衣 2025-02-15 08:10:26

您可以尝试覆盖设置方法,
在其中您可以在此内获取eNityManager实例$ em = self :: getContainer() - &gt; get('doctrine') - &gt; getManager();
然后通过学说ORM Purger清除数据库

$purger = new Doctrine\Common\DataFixtures\Purger\ORMPurger($em);
$purger->purge();

You could try overriding the setUp method,
inside that you can get the enityManager instance like this $em = self::getContainer()->get('doctrine')->getManager();
and then purge the database via the Doctrine ORM purger

$purger = new Doctrine\Common\DataFixtures\Purger\ORMPurger($em);
$purger->purge();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文