alexeymezenin / laravel-best-practices

Laravel best practices
11.34k stars 2.38k forks source link

Test method naming convention #28

Open chris-ruskai opened 5 years ago

chris-ruskai commented 5 years ago

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)

alexeymezenin commented 5 years ago

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.

otezz commented 3 years ago

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

andrewmclagan commented 3 years ago

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.