Cakephp 中单元测试功能的通用库放在哪里?

发布于 2024-08-16 23:09:49 字数 323 浏览 4 评论 0原文

目前,我的几个单元测试需要通用功能,例如从模拟对象登录特定用户或确保没有人登录。我目前在一个文件中包含这些函数,我通过常规的旧 include 语句包含该文件。这对我来说似乎不太蛋糕。我也不想在每次测试时都继续输入 include 语句,因此我想在较高的级别上进行操作,并使其可用于我的所有测试,当然,无需修改核心 cakephp 文件。

因此,我需要寻找一个位置来放置 mustbeLoggedIn('usertype'); 类型的函数,这将有助于保持我的测试干燥,但更适合对象。到目前为止,我还没有成功地通过 cake 使用的常见行为、助手或供应商​​来扩展测试对象。有什么最佳实践吗?

Currently several of my unit tests need common functions such as logging in a specific user from the mock objects or making sure that no one is logged in. I currently have those functions in a file which I include via a regular old include statement. That doesn't seem very cakey to me. I also don't want to keep typing the include statement at every test, so I'd like to do it a high level and have it available to all my tests and do so, of course, without modifying the core cakephp files.

So I'm left looking for a place to put the mustbeLoggedIn('usertype'); -type functions that will help keep my testing DRY, but fit better in the objects. So far I havent been successful extending the test object via the usual behaviors, helpers, or vendors that cake uses. Any best practices?

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

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

发布评论

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

评论(1

装纯掩盖桑 2024-08-23 23:09:49

/app/app_controller.php

/app/app_controller.php

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