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
Related
I am new in PrestaShop and I need to create custom module, with XML files parsing and database operations. I would like to create unit test for this module, because I don't want to test it 'by hand'. Could you provide me any advices, methods or articles on the Web about the patterns how to do it well? I can't find good tutorial using web search engine.
I did write a blog post about testing prestashop with Mink and Behat (Cucumber equivalent) which you can read here - http://xavierriley.co.uk/blog/2012/10/12/test-driving-prestashop-with-behat/
There's also this pull request on Github for adding unit tests to the project - https://github.com/PrestaShop/PrestaShop/pull/70
The tooling for testing things like this in PHP doesn't seem to be as mature as the Ruby/Java equivalents so don't get your hopes up, but that should be a start.
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,
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.
I am a newbie in PHP Frameworks and would like to share/discuss some experience with you guys. Getting straight to the point, what I understand till now (from a newby stand of point is this):
CodeIgniter + Doctrine + Twigg = Symfony:
Zend + Doctrine + Twigg = Symfony
Symfony 2, uses php5.3 (I realy like namespace stuff remind me .Net)
but it lucks of tutorials right now (only partial jobeet translation to ver2)
I enjoy CI community and noumerous tutorials, plus using Doctrine + Twigg I could achive the same with Symfony.
Zend is more enterprise with lots of tutorials, but more difficult to grasp than CI.
So the question is should I start with CI + Doctrine or learn directly Symfony2?
Am I correct with the above assumptions?
Start with CodeIgniter if you are new to frameworks. Both Symfony and ZF have a greater learning curve and if you're not familiar with some concepts you might get fustrated in the beginning with the more complex frameworks .
I would suggest you to go with Symfony 2 since it has got lots of good stuff built around it. Take a look at this article http://www.phparch.com/2010/02/symfony-2-benchmarks/.
Hope this link is very useful on learning Symfony 2. It's a tutorials based on days (21) teaching you how to create a calendar website. Good luck.
http://symfony.com/blog/do-you-know-jobeet
More:
http://symfony2easy.blogspot.com/
http://www.dobervich.com/2011/03/03/symfony2-blog-application-tutorial-part-i-project-setup/, http://www.dobervich.com/2011/03/05/symfony2-blog-application-tutorial-part-ii-the-data-model/, http://www.dobervich.com/2011/03/09/symfony2-blog-application-tutorial-part-iii-routing-controllers-and-templates/
it really adds up to what your requirements are.
Symfony is great, though my only bash on it is that it requires PHP 5.3, which is great, but make sure your host has 5.3 support. Also the issue of using CLI bugs me.
CodeIgniter 2 on the other hand requires 5.1.6, which is good for me as my host is still on 5.2; I also like how small CI was compared to Zend or Symfony. Now like you i like some of symfony's components and i use 2 of them (swift mailer & twig) on my CI install. doesnt mean you should just junk ci and go symfony. CI is built to be a stepping stone framework that you can build on. Symfony to me is a full-fledged framework with everything and the kitchen sink.
having said all that, not all frameworks are created equal. I use CI for one project and Kohana for another. Kohana offered me something i liked that CI didnt do and thats fine.
I think you should look at the different frameworks out there, some are full featured, some are bare-bones and allow you to grow with your needs.
You may quick start with Cygnite PHP Framework. Simple yet powerful tool to build your next project. It gives you exceptional performance. Check benchmark results:
Performance benchmark results
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.