laravel-best-practices icon indicating copy to clipboard operation
laravel-best-practices copied to clipboard

Test method naming convention

Open chris-ruskai opened this issue 5 years ago • 3 comments

Currently:

Camel case prefixed with test. testGuestCannotSeeArticle()

Proposed:

Descriptive names delimited by underscore

Example:

<?php

    /** @test **/
   public function guests_cannot_see_article(){
       //Do Something.
   }

?>

Reasoning:

Laravel's own tutorials don't even follow the camel case standard. https://laracasts.com/series/lets-build-a-forum-with-laravel/episodes/2 https://laracasts.com/series/phpunit-testing-in-laravel/episodes/2 (This one describes both but shows why underscored version is preferred in Laravel)

chris-ruskai avatar Mar 15 '19 13:03 chris-ruskai

We should really use camelCase for all method names because it's PSR compliant.

In the docs they use camelCase. I saw a page in the docs where snake_case was used and created a PR which was accepted by Taylor Otwell right away. Also, books written by Taylor Otwell, Jeffrey Way, and other well-known authors use camelCase in unit test examples.

alexeymezenin avatar Aug 30 '19 20:08 alexeymezenin

There's a PR on laravel's repo that they're using snake case as their convention for methods names in tests.

otezz avatar Jul 10 '21 15:07 otezz

camel case is so much harder to read when function names are long - as is the case with tests. Seems its a standard now to use snake case for tests.

andrewmclagan avatar Oct 11 '21 04:10 andrewmclagan