Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 927
Mateusz Kubiczek Avatar asked Dec 09 '22 19:12

Mateusz Kubiczek


2 Answers

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)

like image 94
Pascal MARTIN Avatar answered Dec 13 '22 22:12

Pascal MARTIN


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.

like image 30
stereoscott Avatar answered Dec 13 '22 21:12

stereoscott