I have a fairly ugly controller method I would like to refactor / extract. I can only test this in a integration type test which kind of signals a code smell.The method processes the form and needs to do one of 5 things, depending on which button was pressedif submitted and valid (button 1) => update some values on the entity and re-render the formif submitted and valid (button 2) => perform another controller action that shows a pdf print of the entityif submitted and valid (button 3) => save entity and redirectif not submitted or not valid => render form (plus errors)In code it looks kind of like thisprotected function processForm(Request $request, MyEntity $entity){    $form = $this->createForm(new MyEntityType, $entity);    if ($form->handleRequest($request)->isValid()) {        $alteredEntity = SomeClass:performStuffOnEntity($entity);        if ($form->get('button1')->isClicked()) {            $form = $this->createForm(                new MyEntityType, $alteredEntity            );        }        else if ($form->get('button2')->isClicked()) {            return $this->pdfPreview($alteredEntity);        }        else if ($form->get('button3')->isClicked()) {            return $this->persistAndRedirectToEntity(                $alteredEntity            );        }    }    return $this->render(        'MyBundle:MyEntity:new.html.twig', array(            'form' => $form->createView(),    ));}Actually there are two buttons like button1, I left one out for brevity of the example.Idea 1: I have tried to extract this into a EntityFormWizard of some sort but this ended up as a cluttered Object with too many dependencies (Router, Templating, Form) which was also a pain to test.Idea 2: Using FormEvents I wanted to extract at least the altering of the entity depending on which button was pressed into a FormEventListener, but the only place where I can alter the Entity is the FormEvents::PRE_SET_DATA event, but in there I have problems figuring out which button was clicked.So the question: Do I have to live with my integration test for this behavior or is there a way to extract it and test it with a unit test?
Symfony2: Extract method from controller, form events, remove conditional
php;unit testing