Skip to content

Version 4 Migration

Mat Lipe edited this page Jul 2, 2024 · 17 revisions

Version 4 has diverged from the WordPress core upstream. While the majority of functionality from WP core was maintained, some rarely used functionality was removed. Going forward, updates to the WP core upstream will not be merged in unless a specific feature is desired, in which case the single feature will be manually ported into this project.

Migrating From Version 3

The data directory no longer exists.

This library no longer includes the testing data from WP core.

If you are using items from the data directory, you will want to copy them into your local test suite and update the paths using them.

Some test images have been preserved and are now available via the DIR_TEST_IMAGES constant. You may migrate uses of DIR_TESTDATA . '/images to DIR_TEST_IMAGES.

Trac Functionality Has Been Removed

  • The multisite.xml config has been removed.
  • All methods related to "trac" or "tickets" have been removed from WP_UnitTestCase_Base.
  • The \TracTickets class has been removed.

PHPUnit 5 & 6 Is No longer Supported

Use PHPUnit 7 or above.

Minimum Required WP Core Version Now 6.1

No code was changed to update the minimum so it is possible it may work on older versions. We are no longer going to actively support versions before 6.1.

WP_UnitTestCase_Base removed

This class was only a proxy for WP_UnitTestCase which added a superfluous layer of complexity with no logic. Now using WP_UnitTestCase directly.

Random Utility Methods Removed from WP_UnitTestCase

  • The file related methods were moved to a new \Lipe\WP_Unit\Utils\Files class.
  • The remove_add_uploads methods were moved to a new \Lipe\WP_Unit\Traits\RemoveUploaded trait.

Removed Methods

  1. prepareTemplate
  2. temp_filename
  3. unlink
  4. rmdir
  5. delete_folders
  6. prepareTemplate
  7. scandir
  8. _microtime_to_float
  9. _make_attachment
  10. update_post_modified
  11. text_array_to_dataprovider
  12. skipOnAutomatedBranches
  13. wpTearDownAfterClass
  14. wpSetUpBeforeClass

Cleanup Methods Moved To New \Lipe\WP_Unit\Helpers\Cleanup Class

Instead of cluttering up the WP_UnitTestCase_Base with a bunch of internal methods, they have been moved to a new \Lipe\WP_Unit\Helpers\Cleanup class.

  1. reset__SERVER
  2. reset_post_statuses
  3. reset_taxonomies
  4. reset_post_types
  5. reset_lazyload_queue
  6. clean_up_global_scope
  7. flush_cache
  8. unregister_all_meta_keys
  9. set_permalink_structure -> Moved to \Lipe\WP_Unit\Utils\Requests::set_permalink_structure
  10. delete_user

Database Methods Moved to New \Lipe\WP_Unit\Helpers\DatabaseTransactions Class.

  1. commit_transaction
  2. start_transaction
  3. All _ methods called by commit and start.

Killed Deprecated_TestCase_Base trait.

The Deprecated_TestCase_Base class was filled with methods and properties which were previously deprecated and left intact for backwards compatibility only. The trait in its entirely has been removed.

These methods and properties are no longer available on the WP_UnitTestCase_Base class with no replacement.

You can see everything this trait contained here.

expectDoingItWrong Now Supports Multiple

If a _doint_it_wrong function is called more than once for the same function, you now must call expectDoingItWrong the same number of times.

Legacy Args Removed From Factory Classes

The create_object method used to have 3 arguments on some factory classes which were shimmed in for backward compatibility. Now only the first array $args argument exists and the shims have been removed. Merge arguments 2 and 3 into the array to retain functionality.

Deprecated Methods Removed From WP_Http_Remote_Post_TestCase

The following methods were moved to \Lipe\WP_Unit\Utils\Requests a while back and have now been removed from the WP_Http_Remote_Post_TestCase class.

  1. format_json_response -> Requests::json_response
  2. format_html_response -> Requests::html_response

The mock_sent property has been removed in favor of using $this->get_all_sent() to retrieve the results from \WP_Http_Unit_Test_Transport::get_mocks()