Opened 8 years ago
Closed 8 years ago
#41658 closed defect (bug) (fixed)
Renaming unit test files with underscore in their names.
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Build/Test Tools | Keywords: | |
Focuses: | Cc: |
Description
The following list of Core phpunit tests have underscores in their name, which is against WP's file naming convention (which we enforce in our own repo, so I cannot import them).
trunk/tests/phpunit/tests/filesystem/find_folder.php trunk/tests/phpunit/tests/hooks/add_filter.php trunk/tests/phpunit/tests/hooks/apply_filters.php trunk/tests/phpunit/tests/hooks/do_action.php trunk/tests/phpunit/tests/hooks/do_all_hook.php trunk/tests/phpunit/tests/hooks/has_filter.php trunk/tests/phpunit/tests/hooks/has_filters.php trunk/tests/phpunit/tests/hooks/preinit_hooks.php trunk/tests/phpunit/tests/hooks/remove_all_filters.php trunk/tests/phpunit/tests/hooks/remove_filter.php trunk/tests/phpunit/tests/image/editor_gd.php trunk/tests/phpunit/tests/image/editor_imagick.php trunk/tests/phpunit/tests/image/intermediate_size.php trunk/tests/phpunit/tests/image/resize_gd.php trunk/tests/phpunit/tests/image/resize_imagick.php trunk/tests/phpunit/tests/image/site_icon.php
Would it be possible to have them renamed with hyphens instead of underscores?
Attachments (2)
Change History (22)
#2
in reply to:
↑ 1
@
8 years ago
Replying to Mte90:
I think that they are an exception because they are all name of functions of WordPress.
Don't think that's a valid enough reason. :)
Especially when we explicitly say the following for classes:
Class file names should be based on the class name with class- prepended and the underscores in the class name replaced with hyphens, for example WP_Error becomes: class-wp-error.php
This ticket was mentioned in Slack in #core-docs by mte90. View the logs.
8 years ago
#5
follow-up:
↓ 10
@
8 years ago
Yeah, we can do this. We have plenty of other files with a similar purpose (ie, the entire content of the functions folder) that manage to convey their purpose without using underscores.
There doesn't appear to be any particular standard for naming test files, but it looks like camelCase is the most common, so I'm cool with using that.
#6
follow-up:
↓ 9
@
8 years ago
- Keywords needs-patch good-first-bug added
Any objections to making this a good-first-bug
?
#7
@
8 years ago
- Summary changed from Renaming unit tests with underscore in their names. to Renaming unit test files with underscore in their names.
#8
@
8 years ago
Patch created from a git repo, but I'm not convinced that it's going to be SVN-friendly.
#9
in reply to:
↑ 6
;
follow-up:
↓ 12
@
8 years ago
- Keywords needs-patch good-first-bug removed
- Milestone changed from Awaiting Review to 4.9
Replying to welcher:
Any objections to making this a
good-first-bug
?
SVN doesn't properly reflect file copying/renaming in patches, so this can only be done on commit.
#10
in reply to:
↑ 5
;
follow-up:
↓ 11
@
8 years ago
Replying to pento:
There doesn't appear to be any particular standard for naming test files, but it looks like camelCase is the most common, so I'm cool with using that.
There is now: https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/#naming
These new docs changes are based on "PHP Unit testing" #coe chats from ~18 months ago
- https://make.wordpress.org/core/2016/02/12/php-unit-test-discussion-feb-12-recap/
- https://wordpress.slack.com/archives/C02RQBWTW/p1456515743002360
- Writing Tests - Naming
- Tests should be organized in such a way that they’re easy to find and easy to run in isolation.
- Generally the test file path has taken the form
/tests/phpunit/tests/{component}/{functionInCamelCase}.php
- Generally a file’s test class has taken the form
Tests_{Component}_{FunctionInCamelCase}
- Test method names should take the format
test_{{description_of_what_is_expected}}
. For example,test_termmeta_cache_should_be_primed_by_default
.- Sometimes it’s handy to have things like
/tests/phpunit/tests/query/orderby.php
, which is not about a function name but instead about a part of the query infrastructure
#11
in reply to:
↑ 10
@
8 years ago
Replying to netweb:
There is now: https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/#naming
😍 Awesome!
#12
in reply to:
↑ 9
@
8 years ago
Replying to SergeyBiryukov:
Replying to welcher:
Any objections to making this a
good-first-bug
?
SVN doesn't properly reflect file copying/renaming in patches, so this can only be done on commit.
Indeed. That's why I couldn't provide one when I opened the ticket.
#15
@
8 years ago
Side note: I could've done it manually, but writing a command to do it for me was much more interesting, even if it took twice as long.
for i in `find . -name *_*`; do svn mv $i `echo $i | sed -e 's/_\([a-z]\)/\U\1/g'`; done
I think that they are an exception because they are all name of functions of WordPress.