Skip to content

Streamline the tests code style #296

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

Merged
merged 1 commit into from
Jul 2, 2021

Conversation

oliverklee
Copy link
Collaborator

  • calls the assert methods statically
  • use @test annotations instead of the test method name prefix

Also add PHP CS Fixer rules to automate these changes.

'php_unit_namespaced' => ['target' => '5.7'],
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_test_annotation' => ['style' => 'annotation'],
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use

Suggested change
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'php_unit_test_case_static_method_calls' => ['call_type' => 'this'],

and leave the assertions as-is?

I think most people are used to calling assertions using $this and it’s also what the phpunit documentation does.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I talked to Sebastian Bergmann about this. He says calling the assert methods statically and non-statically both is valid (as PHP allows calling static methods non-statically), and it comes down to a matter of preference. He himself prefers the non-static calls because he likes doing calls statically only when this is technically necessary. I, on the other hand, prefer to keep things consistent: Always call static methods statically, and call non-static methods in a non-static way.

- calls the assert methods statically
- use `@test` annotations instead of the `test` method name prefix

Also add PHP CS Fixer rules to automate these changes.
@oliverklee oliverklee force-pushed the cleanup/tests-formatting branch from 70105d2 to 2ff8961 Compare July 2, 2021 17:10
@sabberworm sabberworm merged commit 77ff8b3 into MyIntervals:master Jul 2, 2021
@oliverklee oliverklee deleted the cleanup/tests-formatting branch July 2, 2021 19:49
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

Successfully merging this pull request may close these issues.

2 participants