testingphpunitsymfonybehatphpspec

Testing Symfony3 best practices


I would like to know which is the best technology for testing Symfony apps. My idea is to test all the Application layers, starting with the Database (repository and queries), the services , Controllers and Views.

I check about this but i'm not sure which direction to follow. I found out some tool like Phpspec and Behat but i'm not sure they fit my need and which one is the best... What do you guys suggest?


Solution

  • This is what we've been doing at work last 4 years.

    1. Use Behat for testing the behaviour of the app. We mainly cover how GUI related features (twig, templates, browser, file upload, client side validation, API request&response etc) behave however if you wish you can also cover how the app functionality behaves like such as (DB CRUD operations, testing emailing features, commands, queuing systems such as RabbitMQ, Beanstalk etc.) so you're not limited at all.
    2. Use PhpSpec for testing the functionality of the app or a part of a feature or whole. We cover services, util classes, listeners so on.
    3. Do not test controllers because we keep them as "thin" as possible as we follow "thin controller, fat services" approach.

    So in general, Behat is pretty powerful to cover most of the cases so we have more behat tests than PhpSpec. You can use any appropriate testing tool such as PhpUnit so you're free to test others.