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

Snake or camel casing for phpunit tests #3302

Closed
BackEndTea opened this issue Dec 6, 2017 · 6 comments · Fixed by #3886
Closed

Snake or camel casing for phpunit tests #3302

BackEndTea opened this issue Dec 6, 2017 · 6 comments · Fixed by #3886

Comments

@BackEndTea
Copy link
Contributor

My proposal is a fixer that enforces either

public function test_it_does_a_test() {}

or

public function testItDoesATest() {}

for PHPUnit tests.

Ive seen the discussion in #1044, but i feel that reducing the scope of a fixer like this to only PHPUnit tests makes it safe to use.
Any helper functions or dataproviders and the like would not be affected by the fixer, only the tests (either prefixed with test or having a doc block containing @test.

The fixer would only have to adjust the function names it finds, and function names in any @depends tags in doc blocks.

If there is any desire for a fixer like this i'm willing to shoot a PR this way.

@keradus
Copy link
Member

keradus commented Dec 6, 2017

is there any big community using underscore convension for tests ?

@SpacePossum SpacePossum changed the title [Feature Request] Snake or camel casing for phpunit tests Snake or camel casing for phpunit tests Jun 7, 2018
@Slamdunk
Copy link
Contributor

Slamdunk commented Jun 7, 2018

is there any big community using underscore convension for tests ?

I don't know, but I used camelCase since ever (maybe 10 years) and snake_case since this week, and can be much more readable if the method names are longer than 100 chars, which is a good practice if you have a complex domain with thousand edge cases for every single feature/spec.

@keradus
Copy link
Member

keradus commented Jun 7, 2018

you are using it globally, or just for test method names?
if later, use proper reporter that do this for you, eg testdox

@Slamdunk
Copy link
Contributor

Slamdunk commented Jun 7, 2018

Just test method names.
Testdox is only useful when running tests: I need it to be useful also when reading them.

@keradus
Copy link
Member

keradus commented Jun 7, 2018

why do you consider long name inside src as readable, but in tests not?

@Slamdunk
Copy link
Contributor

Slamdunk commented Jun 8, 2018

There is a fundamental difference between the two environments: in src methods name are composed solely of a verb and a noun because a method shall have a single responsability and a simple way of acting; in tests for most of the edge cases we wrote entire phrases explaining what the test code can't explain well or quickly.

keradus added a commit that referenced this issue Aug 22, 2018
This PR was squashed before being merged into the 2.13-dev branch (closes #3886).

Discussion
----------

Add PhpUnitMethodCasingFixer

Closes #3302
```diff
 class MyTest extends \PhpUnit\FrameWork\TestCase
 {
-    public function test_my_code() {}
+    public function testMyCode() {}
 }
```

- [x] Implement base fixer
- [x] Take care of `@depends`
- [x] Run after `PhpUnitTestAnnotationFixer`
- [x] Deprecate `PhpUnitTestAnnotationFixer` *case* config

Commits
-------

b87f254 Add PhpUnitMethodCasingFixer
@keradus keradus closed this as completed Aug 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants