Skip to content

Tests/admin/wpListTable: split the test class (Trac 53010)#6235

Open
jrfnl wants to merge 4 commits intoWordPress:trunkfrom
jrfnl:trac-53010/split-test-classes
Open

Tests/admin/wpListTable: split the test class (Trac 53010)#6235
jrfnl wants to merge 4 commits intoWordPress:trunkfrom
jrfnl:trac-53010/split-test-classes

Conversation

@jrfnl
Copy link
Copy Markdown
Member

@jrfnl jrfnl commented Mar 7, 2024

Tests/admin/wpListTable: create a testcase for tests for WP_List_Table

Most tests testing the WP_List_Table class will need the same set up/tear down fixtures, so moving those fixtures from the actual test class to a separate abstract TestCase class will allow for expanding the tests more easily.

While doing this, we ran the tests in isolation using the --filter CLI argument and discovered that there was a previously unrecognized presumption in the fixtures that the $hook_suffix global would always be set.

This presumption proved incorrect as was demonstrated by the Undefined global variable $hook_suffix warning being thrown when running the tests.

This warning has been fixed now in the new Admin_WpListTable_TestCase by adding some additional defensive coding and making sure that the global state is always brought back to its original state, including if that original state means that the $hook_suffix global variable was not set.

Tests/admin/wpListTable: split off tests for the get_column_info() method to separate test class

This will allow the test class to be compatible with PHPUnit 11 using the new Admin_WpListTable_TestCase class as introduced in the previous commit.

Includes removing method level @covers tags in favour of class level @covers tags to allow for supporting PHPUnit 11 attributes instead of annotations.

Tests/admin/wpListTable: split off tests for the get_views_links() method to separate test class

This will allow the test class to be compatible with PHPUnit 11 using the new Admin_WpListTable_TestCase class as introduced in the previous commit.

Includes removing method level @covers tags in favour of class level @covers tags to allow for supporting PHPUnit 11 attributes instead of annotations.

Tests/admin/wpListTable: rename the original test class to be more descriptive for the remaining tests

The remaining tests in the original test class all cover the magic methods and those are very closely related, so it is perfectly fine for those tests to be grouped together in one test class.

This commit, however, does rename the test class to use the new naming conventions, both for the class name as well as the file name.
It also includes removing method level @covers tags in favour of class level @covers tags to allow for supporting PHPUnit 11 attributes instead of annotations.

This will allow the test class to be compatible with PHPUnit 11.

Trac ticket: https://core.trac.wordpress.org/ticket/53010


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 7, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jrf.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 7, 2024

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

jrfnl and others added 4 commits March 7, 2024 14:39
Most tests test testing the `WP_List_Table` class will need the same set up/tear down fixtures, so moving those fixtures from the actual test class to a separate abstract `TestCase` class will allow for expanding the tests more easily.

While doing this, we ran the tests in isolation using the `--filter` CLI argument and discovered that there was a previously unrecognized presumption in the fixtures that the `$hook_suffix` global would always be set.

This presumption proved incorrect as was demonstrated by the `Undefined global variable $hook_suffix` warning being thrown when running the tests.

This warning has been fixed now in the new `Admin_WpListTable_TestCase` by adding some additional defensive coding and making sure that the global state is always brought back to its original state, including if that original state means that the `$hook_suffix` global variable was not set.

Co-authored-by: carolinan <poena@git.wordpress.org>
Co-authored-by: afercia <afercia@git.wordpress.org>
…thod to separate test class

This will allow the test class to be compatible with PHPUnit 11 using the new `Admin_WpListTable_TestCase` class as introduced in the previous commit.

Includes removing method level `@covers` tags in favour of class level `@covers` tags to allow for supporting PHPUnit 11 attributes instead of annotations.

Co-authored-by: carolinan <poena@git.wordpress.org>
Co-authored-by: afercia <afercia@git.wordpress.org>
…thod to separate test class

This will allow the test class to be compatible with PHPUnit 11 using the new `Admin_WpListTable_TestCase` class as introduced in the previous commit.

Includes removing method level `@covers` tags in favour of class level `@covers` tags to allow for supporting PHPUnit 11 attributes instead of annotations.

Co-authored-by: carolinan <poena@git.wordpress.org>
Co-authored-by: afercia <afercia@git.wordpress.org>
…scriptive for the remaining tests

The remaining tests in the original test class all cover the magic methods and those are very closely related, so it is perfectly fine for those tests to be grouped together in one test class.

This commit, however, does rename the test class to use the new naming conventions, both for the class name as well as the file name.
It also includes removing method level `@covers` tags in favour of class level `@covers` tags to allow for supporting PHPUnit 11 attributes instead of annotations.

This will allow the test class to be compatible with PHPUnit 11.

Co-authored-by: carolinan <poena@git.wordpress.org>
Co-authored-by: afercia <afercia@git.wordpress.org>
@jrfnl jrfnl force-pushed the trac-53010/split-test-classes branch from 251633d to 931ec26 Compare March 7, 2024 13:40
@jrfnl jrfnl added the props-bot Adding this label triggers the Props Bot workflow for a PR. label Mar 7, 2024
@github-actions github-actions Bot removed the props-bot Adding this label triggers the Props Bot workflow for a PR. label Mar 7, 2024
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.

1 participant