How can I unit test a Symfony2 controller?

前端 未结 4 955
暖寄归人
暖寄归人 2021-01-31 16:42

I want to use Test Driven Development as much as possible — it\'s a great way of working.

I am troubled by the fact that Symfony2 controllers create and return a new

4条回答
  •  梦毁少年i
    2021-01-31 17:38

    Unit Testing

    Refactor your controllers to be services: http://symfony.com/doc/current/cookbook/controller/service.html

    Then you can easily unit test them.

    Functional Testing

    Of course (as already mentioned by others) you can use the WebTestCase as described here: http://symfony.com/doc/current/book/testing.html#functional-tests

提交回复
热议问题