Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7799547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:20:44+00:00 2026-06-02T00:20:44+00:00

I want to use Test Driven Development as much as possible — it’s a

  • 0

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 Response object.

I want to be able to unit test a controller in isolation.

How do you do it?

Is the answer to create a controller as a Plain Old PHP Object, register it as a service and use Dependency Injection to pass a new Response object (or a Response factory) into it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:20:46+00:00Added an answer on June 2, 2026 at 12:20 am

    Normally, your controller plugs together different objects and connects them in the correct order. Maybe he calls a repository, reads some objects and returns them through the render method. Maybe he calls some other Handlers/Managers who do stuff.

    This means that a controller is a high level component. More often than not this indicates that functional tests are in order instead of unit tests. You should not aim to get 100% code coverage with your unit tests. Maybe you can think of it that way: If you unit test everything the controller calls (model, validation, form, repository), what could go wrong? Most of the time it’s something you only observe when using all the real classes involved when in production.

    I want also like to point out that TDD does not mean that everything has to be unit-tested. It’s ok to have some functional tests for the high-level code. As said, if you test the low-level components with unit-tests you should only test how they are working together which you cannot test with mocks because you tell the mocks what the return value is.

    If your controller does more than plugging parts of the system together you should think about refactoring the stuff into more low-level classes you can test with unit-tests.

    So my suggestion would be to use functional tests to test your controllers and use unit-tests to test your models and your business logic stuff.

    If you struggle with functional tests, you can read the following:

    • http://symfony.com/doc/current/book/testing.html#functional-tests
    • http://blog.sznapka.pl/fully-isolated-tests-in-symfony2/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm starting a new project and I want to use Test Driven Development, but
I want to create a rails app using Test-Driven Development (TDD), so i wrote
I want to use php in console mode and create an environment to test
I want to use prosody or maybe another xmpp server to test my xmpp
For a unit test I want to use the Range attribute from NUnit to
I have a string of test like this: <customtag>hey</customtag> I want to use a
I want to Unit Test my application which use MSMQ but i found no
I want to unit test a RESTful interface written with Apache CXF. I use
I use the latest oauth-plugin with Rails 3.1. I want to test my OAuth2
I just finished a tutorial for test driven development in c# with Nunit. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.