E
E
Enma2021-12-20 12:40:37
PHPUnit
Enma, 2021-12-20 12:40:37

How to name tests for Laravel? Annotation or prefix "test"?

Actually, what is the correct name for functions for tests, or how do you call them in your company?

according to PSR, I have to call functions in camelCase, but at the same time, Laravel itself (just like Symfony) generates snake_case through make

public function test_example()
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }

Well, as for the "test",
What do you think is more correct?
/**
     * @test
     */
    public function some_example()
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }

or
public function test_some_example()
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }

As I was told, not all versions of UnitTest can correctly support the @test annotation in dockblocks, but to be honest, I have never seen this, in some legacy code, if only or am I looking in the wrong place?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Gordinskiy, 2021-12-20
@DmitriyGordinskiy

I prefer prefix. Simply because it does not require a separate line in the docblock, which is already growing due to argument descriptions, data providers, and a human-readable test name.
Names in snake_case are preferable because long method names in camelCase are much harder to read.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question