如何设置学说测试以自动回滚交易(以避免DIRTY DB)?
我想在主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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在Symfony 6文档中,它们实际上描述并显示在每个测试之前使用 damAdoctrinetestbundle 。
In the Symfony 6 documentation they actually describe and show how to reset the database before every test using the DAMADoctrineTestBundle.
您可以尝试覆盖
设置
方法,在其中您可以在此内获取eNityManager实例
$ em = self :: getContainer() - &gt; get('doctrine') - &gt; getManager();
然后通过学说ORM Purger清除数据库
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