-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Font Library] Update PHPUnit tests per Core coding standards and pra…
…ctices (#58502) * Rename test classes. Renamed test classes per WordPress Core's Test Classes coding standards: For a test covering the entire class: Tests_[GroupName]_[ClassName] For a test covering a class' method: Tests_[GroupName]_[ClassName]_[MethodName] For a function: Tests_[GroupName]_[FunctionName] See https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#test-classes. * Update covers tag * Use set_up_before_class() instead of __construct(). Test classes should not have a constructor. Instead, use the set_up_before_class() fixture method to perform tasks that pre-setup all tests within the test class. * Use assertSame() instead of assertEquals(). This is an ongoing effort in Core. Reasoning is shared in the 6.5 Trac ticket: >The assertEquals() test method does not check that the types >of the expected and actual values match. This can hide subtle >bugs especially when the values are falsey. https://core.trac.wordpress.org/ticket/59655 * Rename test file to match func, class, or method. Per the WordPress Core coding standards, test files should be named according to the function, class, or method under test within its test class. Function under test: wpFunctioName.php Class under test: wpClassName.php Method under test: wpClassName/methodName.php See https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization. * Update dataProvider usage, formatting, and docs. Updates: * Refactors repetitive tests into a dataProvider. * Data provider's docblock. * Adds a brief explanation to each dataset (helps for understanding when a dataset fails). * Adds each argument name with a dataset. * Documents each argument in the test method's docblock. * Add assertion failure messages. When there are more than 1 assertion in a test method, a failure message helps to identify which assertion failed. Once an assertion fails, any other assertions after it in the same test method will not run. Thus, the message helps to know which one of the assertions failed. This can help with debugging process. * Reorder resets / cleanup. Resets are things like deleting posts, removing a filter/action, etc. These need to occur _before_ an assertion. Why? If a reset is after an assertion and any of the assertions before it fail, the test method bails out and the reset does not happen. To ensure resets happen, they need to be located in either: * tear_down() fixture. * just after invoking the thing under test but before the assertion(s). * Put expected as first arg in each assert. Per the PHPUnit handbook: assertSomething( expected, actual, message ); * Add fonts and font-library group annotation. All of the test classes now have these groups: * @group fonts * @group font-library These annotations allow for specific groups of tests to be run, which is helping in local development. Co-authored-by: hellofromtonya <hellofromtonya@git.wordpress.org> Co-authored-by: creativecoder <grantmkin@git.wordpress.org>
- Loading branch information
1 parent
6d75b0f
commit 4177183
Showing
11 changed files
with
516 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.