问题描述
我们已决定在下一个项目中使用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.
推荐答案
原因:
- Codeigniter的组件紧密耦合.您需要先运行一些重要的基本零件(装载程序,路由器,CFG对象),然后才能使用其他零件.
- 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!