Make WordPress Core

Opened 3 years ago

Closed 2 years ago

#53997 closed task (blessed) (duplicate)

Add some unit tests for the WP_Upgrader class

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Upgrade/Install Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

As part of the work on #51857 and #22316, it would be ideal to have unit tests for the new functionality, but there are currently no tests for the Upgrade/Install component.

Let's add some basic tests, starting with the WP_Upgrader class, maybe Plugin_Upgrader and Theme_Upgrader too.

There are some existing tests for WP_Filesystem methods, as well as for the REST API plugins controller, which may or may not be helpful as a starting point.

Change History (9)

#2 @audrasjb
3 years ago

  • Milestone changed from 5.9 to 6.0

As we're going closer to 5.9 beta 1, I'm moving this ticket to the next milestone :)

This ticket was mentioned in PR #2463 on WordPress/wordpress-develop by costdev.


3 years ago
#3

  • Keywords has-patch has-unit-tests added; needs-unit-tests removed

This PR adds unit tests for the WP_Upgrader class.

This is a work-in-progress that would benefit from feedback on whether/how to test certain functionality in the WP_Upgrader class.

To check coverage:

{{{sh
# Checkout the PR.
gh pr checkout https://github.com/WordPress/wordpress-develop/pull/2463

# Navigate to your wordpress-develop root directory.
cd /var/www/html/wordpress-develop

# Create the coverage directory.
mkdir -p artifacts/coverage/53997

# Run the tests with coverage enabled.
XDEBUG_MODE=coverage vendor/bin/phpunit --filter Tests_Admin_IncludesWpUpgrader --coverage-html artifacts/coverage/53997
}}}

Then navigate to http://localhost/wordpress-develop/artifacts/coverage/53997/wp-admin/includes/class-wp-upgrader.php.html. Note: The URL before /artifacts may be different on your system.

Ticket: https://core.trac.wordpress.org/ticket/53997

#4 @costdev
3 years ago

PR 1751 on #54245 uses getMockBuilder().

PR 2463 above uses WP_Upgrader directly and aims to achieve 100% (or as near as possible) line/branch coverage for WP_Upgrader.

#54245 notes that there is accidental coverage of WP_Upgrader elsewhere in the test suite, though a single test class that covers each line/branch and in doing so, demonstrates how to hit each line/branch for future path coverage improvements, would be ideal IMO.

It would be good to get some input on the preferred approach for Core.

#5 @costdev
3 years ago

  • Milestone changed from 6.0 to 6.1

With 6.0 RC1 starting soon, I'm moving this to the 6.1 milestone.

afragen commented on PR #2463:


3 years ago
#6

Curious how many times it's necessary to creates a ReflectionMethod or ReflectionProperty before something like this is a good idea?

https://github.com/WordPress/wp-plugin-dependencies/blob/trunk/tests/phpunit/tests/admin/wpPluginDependencies.php

costdev commented on PR #2463:


3 years ago
#7

Yep, the make_prop_accessible() helper method exists in various test classes. I've used it before myself, but haven't refactored this class yet.

This ticket was mentioned in Slack in #core-auto-updates by costdev. View the logs.


2 years ago

#9 @costdev
2 years ago

  • Milestone 6.1 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Per the discussion in the bug scrub, I'm closing this ticket as a duplicate of #54245 as the PR there supersedes this one.

Note: See TracTickets for help on using tickets.