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

PHPCS: Exclude PHPUnit tests from file and class name sniffs (for Core parity) #43131

Merged
merged 1 commit into from
Aug 11, 2022

Conversation

hellofromtonya
Copy link
Contributor

@hellofromtonya hellofromtonya commented Aug 10, 2022

What?

Use Core's file and class name sniffs exclusions for the PHPUnit tests.

Why?

To reduce the effort of backporting tests to Core by increasing parity to WordPress Coding Standards.

Test Classes and files in Core require the following:

Test class names should reflect the filepath, with underscores replacing directory separators and TitleCase replacing camelCase. Thus, the class Tests_Comment_GetCommentClass(), which contains tests for the get_comment_class() function, is located in tests/comment/getCommentClass.php.

So a test file is named as: group/funcName.php or group/className.php.

Core's tests include the same exclusions in its phpcs.xml.dist file.

How?

Testing Instructions

Before applying the patch:

  1. Rename the class-wp-webfonts-test.php file to wpWebfonts.php.
  2. Rename its class from WP_Webfonts_Test to Tests_Webfonts_WpWebfonts.
  3. In terminal, run the linter on this file: npm run lint:php phpunit/wpWebfonts.php.

Results: WordPress.Files.FileName.NotHyphenatedLowercase linting error.
Screen Shot 2022-08-10 at 4 04 28 PM

After applying the patch:
Rerun step 3 above. Results: No linting errors.
Screen Shot 2022-08-10 at 4 07 05 PM

@hellofromtonya hellofromtonya self-assigned this Aug 10, 2022
@hellofromtonya hellofromtonya added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label Aug 10, 2022
@hellofromtonya hellofromtonya force-pushed the fix/test-filename-core-parity branch from 911dfce to a8504c9 Compare August 10, 2022 21:08
Copy link
Contributor

@anton-vlasenko anton-vlasenko left a comment

Choose a reason for hiding this comment

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

I've followed the testing instructions.
I confirm that the PR works (no linting errors after applying the patch).
LGTM!

@hellofromtonya hellofromtonya merged commit 3372b59 into trunk Aug 11, 2022
@hellofromtonya hellofromtonya deleted the fix/test-filename-core-parity branch August 11, 2022 16:19
@hellofromtonya
Copy link
Contributor Author

@anton-vlasenko Thank you for testing and reviewing!

@github-actions github-actions bot added this to the Gutenberg 14.0 milestone Aug 11, 2022
hellofromtonya pushed a commit that referenced this pull request Aug 18, 2022
PHPCS: Exclude PHPUnit tests from file and class name sniffs (for Core parity)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants