Why is CIUnit needed in order to use PHPUnit with CodeIgniter?

三世轮回 提交于 2019-12-22 05:57:50

问题


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.

Why is it needed?

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


回答1:


Reasons:

  1. Codeigniter's components are tightly coupled. You need some big basic parts running (the loader, the router, the CFG object) before you can use any other pieces.
  2. Codeigniter is not designed to run from a CLI. It has a great deal of bootstrapping code in its index.php front-controller, and it assumes a web server environment.

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.



来源:https://stackoverflow.com/questions/11345667/why-is-ciunit-needed-in-order-to-use-phpunit-with-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!