Working with PHPUnit and CodeIgniter 1.7.2 - php

I recently started with the unit testing for my php website made in CodeIgniter 1.7.2. I want to test my web site using PHPUnit.
So I Googled it and came to know that there is a library for 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.
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. 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. I have myself tried using FooStack once and was successful then, but it is too cumbersome. There is no way of testing a model isolated in CI because of the god object CI makes.
You can however try SimpleTest, here is a good library that can help you with it: 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.
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.

Related

Zend Framework 2 Codeception integration

I would like to use codeception as a testing framework in my existing zend framework 2 project. I installed codeception via composer but i dont know what to do next to get my first tests running.
I found the following github file but i dont really understand for what this is good for.
ZF2 Module - Codeception
Can someone tell me what to do next ?
THX
Since acceptance tests are not FW dependent (Codeception accesses your web application via URL), you shouldn't have problems with running those tests. I was following these great tutorials from Jeffrey, and I really advice you check them out if you have no idea where to start: https://tutsplus.com/course/modern-testing-in-php-with-codeception/
However, I still didn't figure out how to configure CC to run functional tests on ZF2 (I think this is the only hard part, since form here on you just use pre-defined TestGuy methods), neither I found any examples online, so I really hope that someone who got this working will be able to provide a more complete answer or maybe even share a config example. In case I find a way I'll update my answer at that point.

Using Codeigniter in Zf2

I have an project that is used by many users and it's written in Codeigniter. I'm very happy with my application but I'm getting lost with Codeigniter because of the functionality of the framework and my application is getting too big for Codeigniter (that is what I think).
I want to go from Codeigniter to Zend, but the application is too big to begin all over again because there is still more functionality to come.
I don't know if someone has experienced or tried it, but does anybody know if it is possible to integrate Codeigniter into Zend as an module and migrate in steps to the Zend Framework 2?
Sorry for my bad english by the way :-)
Having experience with small and medium-scale projects with both CodeIgniter (CI) and Zend Framework (ZF), I can tell you that using one framework over the other will not solve any problem you might be having.
If you are looking for the added functionality provided by the ZF components, such as a ready-made class for Date or the Form verification class, know that you can use ZF components in Code Igniter. You will need to create a special class in CI that will jumpstart the ZF class autoloader. From there you can simply include ZF classes and use them as if you were inside a ZF application.
See http://www.beyondcoding.com/2008/02/21/using-zend-framework-with-codeigniter/ and http://fr.slideshare.net/samsonasik/codeigniter-using-third-party-components-zend-framework-components for more details.
"Integrate" means you want to put your app running on CodeIgniter withing ZendFramework. So basically you changed nothing and there's no much sense of doing so.
You perhaps could consider porting your app from CI to ZF, but that will require rewriting of your code. But I'd first try to find out what the bottleneck in your app really is and ensure that you will benefit from the switch

How to debug joomla components while developing them

I am writing my first joomla component and while I'm getting the hang of how joomla works, I don't know how I can effectively debug and run tests on my component before installing it in joomla. So my question is: How do you go about writing a joomla component. What parts should I write first and how do I test them?
Example: A component that gets information from database and displays it. How can I write the database part (model) and test it to see if it works as expected, without having to write the rest of the component (view and controller)?
First you need to understand how to setup your machine for development. You don't need a complete component to install it on Joomla!
This is by no means a complete answer, just a few directions which you can follow:
1. Developing - Understand how Joomla! works: as a beginner before going to much harder material, it's important to get your component to work first (starting isn't easy). Learn how to use the Joomla! Platform / Framework to build your components, check code in the core components.
2. Unit Testing - After you have a working component, if you want to test parts of it, do some search on the topic Unit Testing / PHPUnit. The article How to use PHPUnit in Joomla helped me a lot on how to test a method from a controller / model I've built.
3. Debugging your code - learn how to use a debugger in your IDE (like XDebug or Zend Debugger).
4. System Tests - in the end you may want to automate some tasks you do manually - have a look at Selenium WebDriver
A couple of resources:
Joomla! Official Documentation
Learn the Art of Joomla!® from master developer Andrew Eddie
Joomla! Programming - By Mark Dexter, Louis Landry

Unit tests to develop Joomla components

I'm developing components for Joomla! and want to know if there is a framework that can be used in a simple way to perform unit tests for these components.
Thanks for your attention.
Greetings!
PHPUnit is probably the first framework that comes to mind when thinking about unit testing in PHP. As far as I see, Joomla itself is already using it.
Some useful links:
http://docs.joomla.org/How_to_create_a_continuous_integration (a bit broader than unit test only).
http://forum.joomla.org/viewtopic.php?p=2177431
http://docs.joomla.org/Running_Automated_Tests_for_Version_1.6
Hope that helps,

Which unit testing framework do you use for Symfony?

Which unit testing framework do you use for Symfony?
Lime or PHPUnit? What are the pros and cons of using them?
In my opinion, here are a few things that come to my mind :
PHPUnit is more integrated with other tools, like, for instance,
Selenium (PHPUnit can use it to open true real browsers to test your site)
phpUnderControl for continuous-integration
PHPUnit works well with Xdebug, to generate code-coverage reports
PHPUnit is more widely used ; which probably means more support
But note I don't work with symfony, nor lime...
Still, I've never heards anyone speak about it, except for those working with symfony -- that not a good thing, for the day you'll have to work with another framework (yes, this happens ^^ )
One thing that's not in PHPUnit :
"false" browser (being able to do HTTP Requests to the application, without using Selenium to open a real browser)
But some frameworks (Zend Framework does, with it's Zend_Test component) integrate with PHPUnit (or use it), while allowing injection of data into the MVC and fetching of the response, without having to issue any HTTP Request.
I don't know if symfony allows that, but that's a nice thing with ZF/PHPUnit ^^
(Yes, not a symfony-specific answer ; but of the things I said must still be valid with that framework)
Lime is a much more simple testing framework, which can be a good or a bad thing depending on how you want to use it.
The symfony library itself uses its own testing framework, Lime, to test its code base. From the symfony book:
It is based on the Test::More Perl
library, and is TAP compliant, which
means that the result of tests is
displayed as specified in the Test
Anything Protocol, designed for better
readability of test output.
I cannot vouch for the statement that the lime framework is "more lightweight" than other PHP testing frameworks as the symfony docs claim, but I do really like that it's built right into your symfony project and works well with the symfony command line tools without any additional configuration. One thing that is especially cool is that the lime tests within symfony are set to run within your "test" environment which has it's own database, symfony cache (which gets cleared out during each test session), and environment variables. This comes in handy when you want to do functional testing (checking server response and your html output in your modules/actions, versus basic unit testing). I also like that lime is super easy to pick up and understand since it's so simple. You also have the ability to put your tests into YAML configuration file rather than write the tests by hand.
Pascal is entirely right that PHPUnit is much more widely used and you'd be able to use it in non-symfony projects. There is even a plugin for it, PHPUnit symfony plugin. My best advice would be to use lime if you just wanted to jump right into writing simple tests while you develop your symfony app. But, if you have the time and hope to use these testing skills outside of the symfony world, or bring in pre-existing PHPUnit tests into your symfony code, it'd be worth your time to check out the plugin and give it a spin.

Categories