laravel-best-practices
laravel-best-practices copied to clipboard
Test method naming convention
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)
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.
There's a PR on laravel's repo that they're using snake case as their convention for methods names in tests.
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.