简体   繁体   English

使用PHPUnit和CodeIgniter 1.7.2

[英]Working with PHPUnit and CodeIgniter 1.7.2

I recently started with the unit testing for my php website made in CodeIgniter 1.7.2. 我最近开始使用CodeIgniter 1.7.2对我的php网站进行单元测试。 I want to test my web site using PHPUnit. 我想使用PHPUnit测试我的网站。

So I Googled it and came to know that there is a library for CodeIgniter & PHPUnit Bridge: http://www.foostack.com/foostack/ . 因此,我用Google搜索了它,然后知道有一个CodeIgniter和PHPUnit Bridge库: http : //www.foostack.com/foostack/ I have followed all the steps, and got the code running, but when I execute a test case from console, my default controller is executed and the html for the page is printed on the console. 我已经完成所有步骤,并运行了代码,但是当我从控制台执行测试用例时,将执行我的默认控制器,并将页面的html打印在控制台上。

Can any one please tell me what exactly is happening or am I doing something wrong? 谁能告诉我到底是什么情况,或者我做错了什么? Also if any one has any other ideas to test the model without using the foostack library please suggest it. 另外,如果有人有其他想法可以在不使用foostack库的情况下测试模型,请提出建议。 Please let me know if any other details are required. 如果需要其他详细信息,请告诉我。

Thanks in Advance. 提前致谢。

CodeIgniter is not an ideal framework where you can unit test your code with PHPUnit. CodeIgniter并不是理想的框架,您可以在其中使用PHPUnit对代码进行单元测试。 I have myself tried using FooStack once and was successful then, but it is too cumbersome. 我曾经尝试使用FooStack一次,但后来成功了,但这太麻烦了。 There is no way of testing a model isolated in CI because of the god object CI makes. 由于CI制造的上帝对象,因此无法测试在CI中隔离的模型。

You can however try SimpleTest, here is a good library that can help you with it: https://github.com/ericbarnes/codeigniter-simpletest 但是,您可以尝试SimpleTest,这是一个可以帮助您的良好库: https : //github.com/ericbarnes/codeigniter-simpletest

Other than that there is the Unit Test library provided with CI - which in nowhere near a full unit testing framework, but does let you do basic assertions, reporting etc. 除此之外,CI还提供了单元测试库-它远不及完整的单元测试框架,但确实可以让您进行基本声明,报告等。

If you're really serious about unit testing, I'd suggest you move to frameworks that value this. 如果您真的对单元测试很认真,建议您转到重视这一点的框架。 My favorite is Zend Framework, but there are other good ones as well: Symfony, Kohana, Lithium, etc. 我最喜欢的是Zend Framework,但还有其他一些好的:Symfony,Kohana,Lithium等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM