为什么要使用PHPUnit和CodeIgniter才能使用CIUnit? [英] Why is CIUnit needed in order to use PHPUnit with CodeIgniter?

查看:82
本文介绍了为什么要使用PHPUnit和CodeIgniter才能使用CIUnit?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已决定在下一个项目中使用PHPUnit(与Jenkins一起使用).我们正在考虑使用不同的PHP框架,其中之一就是CodeIgniter.我看到 a 的phpunit-codeigniter-multiple-objects-with-same-name>使用我的CIUNIT 桥" PHPUnit和Codeigniter.在线文档中几乎没有解释.

We've decided to use PHPUnit (with Jenkins) in our next project. We're considering different PHP frameworks, one of which is CodeIgniter. I see that a lot of people use My CIUNIT to "bridge" PHPUnit and Codeigniter. There is little to no explanation in the online documentation.

其他框架似乎不需要这样的酷桥" .

Other frameworks don't seem to need a "cool bridge" like this.

推荐答案

原因:

  1. Codeigniter的组件紧密耦合.您需要先运行一些重要的基本零件(装载程序,路由器,CFG对象),然后才能使用其他零件.
  2. Codeigniter并非旨在从CLI运行.它在index.php前端控制器中具有大量自举代码,并且假定使用Web服务器环境.

您并非绝对要求 CIUNIT对CI进行单元测试.但是您将必须执行某事.就我而言,我为index.php写了一个替代的前端控制器,该控制器仅加载获取CI超级对象所需的最低要求.我在测试文件的顶部require_once,在SetUp()方法中的$this->CI =& get_instance().但是,如果我是一个绝对的纯单元测试人员,则应该在每次测试后销毁并重新创建CI对象,以防某些状态陷入其中.我不确定CIUNIT是否会为您这样做.

You do not absolutely require CIUNIT to unit-test CI. But you will have to do something. In my case, I wrote an alternative front controller to index.php which just loads the minimum necessary to get a CI superobject. I require_once it at the top of my test files, and $this->CI =& get_instance() in SetUp() methods. If I were being an absolutely pure unit-tester, however, I should be destroying and re-creating the CI object after every test in case some state got trapped in it. I'm not sure if CIUNIT does this for you.

这篇关于为什么要使用PHPUnit和CodeIgniter才能使用CIUnit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆