Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#41658 closed defect (bug) (fixed)

Renaming unit test files with underscore in their names.

Reported by: stephdau's profile stephdau Owned by: pento's profile pento
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)

41658.diff (3.5 KB) - added by GaryJ 8 years ago.
Rename test files to avoid using underscores
41658.2.diff (77.5 KB) - added by GaryJ 8 years ago.
Use "svn mv" to remove underscores from test file names.

Download all attachments as: .zip

Change History (22)

#1 follow-up: @Mte90
8 years ago

I think that they are an exception because they are all name of functions of WordPress.

#2 in reply to: ↑ 1 @stephdau
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

#3 @Mte90
8 years ago

They are functions not classes but probably is missing that part in the docs :-)

This ticket was mentioned in Slack in #core-docs by mte90. View the logs.


8 years ago

#5 follow-up: @pento
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: @welcher
8 years ago

  • Keywords needs-patch good-first-bug added

Any objections to making this a good-first-bug?

#7 @johnbillion
8 years ago

  • Summary changed from Renaming unit tests with underscore in their names. to Renaming unit test files with underscore in their names.

@GaryJ
8 years ago

Rename test files to avoid using underscores

#8 @GaryJ
8 years ago

Patch created from a git repo, but I'm not convinced that it's going to be SVN-friendly.

@GaryJ
8 years ago

Use "svn mv" to remove underscores from test file names.

#9 in reply to: ↑ 6 ; follow-up: @SergeyBiryukov
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: @netweb
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

  • 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

#12 in reply to: ↑ 9 @stephdau
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.

#13 @pento
8 years ago

  • Owner set to pento
  • Status changed from new to assigned

#14 @pento
8 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 41261:

Tests: Rename tests with underscore in the name

There were a handful of files with an underscore in the name, which violated our naming scheme, and caused problems for anyone how enforced the scheme on their own systems.

This commit renames all of the files to the correct camelCase scheme.

Fixes #41658.

#15 @pento
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

#16 @pento
8 years ago

PPS: *_* is an emoticon that expresses how I feel about writing sed expressions.

#17 @ocean90
8 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

phpunit.xml.dist needs to be updated as well.

#18 @pento
8 years ago

In 41262:

Tests: Rename ignored tests in phpunit.xml.dist.

Some of the files renamed in [41261] are listed in phpunit.xml.dist, as they need to be ignore in PHP 5.2.

This followup commit changes phpunit.xml.dist to match their new names.

See #41658.

#19 @pento
8 years ago

In 41263:

Tests: Rename ignored tests in multisite.xml.

For bonus :yolo: :friday:, this repeats [41262] for multisite.xml, which duplicates the ignored file list from phpunit.xml.dist.

See #41658.

#20 @SergeyBiryukov
8 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.