Unit test/functionnal test in Symfony : how to test if a route in a controller does what I want

Viewed 35

I am totally a newbie in unit testing. I have this Symfony route (which is totally dumb, just for the exemple) :

    /**
     * @Route("/change-label/{question}", name="admin_question_change_label")
     */

    public function changeQuestionLabel(Question $question, EntityManagerInterface $em) {

        $question->setLabel('Test');

        $em->flush();

        $this->render('home/index.html.twig');

    }

What I want to do is to test automatically if this route actually changes the label property of any given Question object. I'd like to write a test like : "take a Question in the db, and if the Question's label, after i called the route 'admin_question_change_intitule' is 'Test', then that's ok."

Here's the pseudo code version :

public function testLabelChanged(): void
    {
        
        //take a question in the DB
        
        //call the route admin_question_change_intitule and pass it the question
        
        //if the question label is now 'Test', that's ok
    }

But I absolutely don't know what kind of test to write (unit or functional), and how to write it properly, or even if unit/functional tests are meant to do that. I have the feeling that unit tests are there just to test response status code, or validations, things like that, and not meant for larger tests.

Could you guide me and show me how to do that ?

0 Answers
Related