Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test method naming convention #28

Open
chris-ruskai opened this issue Mar 15, 2019 · 3 comments
Open

Test method naming convention #28

chris-ruskai opened this issue Mar 15, 2019 · 3 comments

Comments

@chris-ruskai
Copy link

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
Copy link
Owner

alexeymezenin commented Aug 30, 2019

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
Copy link

otezz commented Jul 10, 2021

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

@andrewmclagan
Copy link

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.

JohnnyWalkerDigital added a commit to JohnnyWalkerDigital/laravel-best-practices that referenced this issue May 19, 2023
Update naming convention to match official Laravel documentation. These best practices are currently out-of-step with modern Laravel standards.

 * Laravel [officially changed to snake_case](laravel/laravel#5574) for test case methods in version 8.0. 
 * [Official Laravel documentation](https://laravel.com/docs/10.x/testing) uses snake_case. 
 * [Laracast videos](https://laracasts.com/series/phpunit-testing-in-laravel/episodes/2) use snake_case. 
 * The [previous discussion's](alexeymezenin#28) conclusions on this matter are no longer correct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants