保存教义记录而不保留

发布于 2024-09-27 02:20:29 字数 478 浏览 0 评论 0原文

在我的单元测试中,我希望具有以下行为:

$myNewDoctrineRecord = new Dto_MyRecord();
$myNewDoctrineRecord->pk = 1; //the primary key
...
$myNewDoctrineRecord->save();

现在该记录不应该真正保留到数据库中。但我想做的是

$myFetchedDoctrineRecord = Doctrine::getTable('Dto_MyRecord')->find(1);
//result should be $myFetchedDoctrineRecord === $myNewDoctrineRecord

,我知道这可以通过 DAO 模式来实现,我将 DAO 替换为某种模拟。但也许有某种可能性,所以只是说教义不坚持,而只是“记住”记录。

谢谢你! 马库斯

within my Unit-tests i would like to have the following behavior:

$myNewDoctrineRecord = new Dto_MyRecord();
$myNewDoctrineRecord->pk = 1; //the primary key
...
$myNewDoctrineRecord->save();

Now this record shouldnt really persist to the database. But i would like to do

$myFetchedDoctrineRecord = Doctrine::getTable('Dto_MyRecord')->find(1);
//result should be $myFetchedDoctrineRecord === $myNewDoctrineRecord

I know this could be achived with a DAO pattern, where i replace the DAO to some mock. But maybe there is some possibility so just say Doctrine not to persist, but only to "remember" the records.

Thank you!
Markus

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

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

发布评论

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

评论(2

濫情▎り 2024-10-04 02:20:29

您可以启动一个事务,并在测试结束时回滚。这样您仍然可以 find() 在事务中创建的记录,但回滚将确保它们不会被持久化。

You could start a transaction, and at the end of the test rollback. That way you can still find() the records created within the transaction, but the rollback will ensure they're not persisted.

甜扑 2024-10-04 02:20:29

如果您的机器有一些空间,那么您可以将对象放入 $_SESSION 中。但请注意,Doctrine 对象可能会变得相当大。

If your machine has some space then you could put your objects into the $_SESSION. But beware, Doctrine objects can grow pretty large.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文