Make WordPress Core

Opened 8 months ago

Closed 8 months ago

Last modified 8 months ago

#59999 closed enhancement (fixed)

Enhancement: Allow to overwrite `WP_UnitTestCase_Base::factory()` method.

Reported by: hugod's profile hugod Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.5 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

What?

This is a enhancement request in order to overwrite WP_UnitTestCase_Base::factory() static method in child classes of WP_UnitTestCase_Base.

Why?

To be able to overwrite WP_UnitTest_Factory.
As an example, as third party plugin could write its own factory extending WP_UnitTest_Factory for testing purposes.
And to benefit from WP_UnitTestCase_Base features, its test case would also extend it.
But overwriting WP_UnitTestCase_Base::factory() has no effect since it's called with the self keyword instead of the static keyword which has late static binding (see here and here).

Change History (4)

This ticket was mentioned in PR #5723 on WordPress/wordpress-develop by @hugod.


8 months ago
#1

  • Keywords has-patch has-unit-tests added

## What?
Remove self keyword in favor of static in WP_UnitTestCase_Base so factory() can be easily ovewriten.

Trac ticket: #59999

#2 @SergeyBiryukov
8 months ago

  • Milestone changed from Awaiting Review to 6.5

#3 @SergeyBiryukov
8 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 57149:

Build/Test Tools: Allow overriding the WP_UnitTestCase_Base::factory() method.

This allows third-party plugins to write their own factory extending WP_UnitTest_Factory for testing purposes, as well as benefit from WP_UnitTestCase_Base features.

Follow-up to [35186], [35225], [35242].

Props hugod.
Fixes #59999.

@SergeyBiryukov commented on PR #5723:


8 months ago
#4

Thanks for the PR! Merged in r57149.

Note: See TracTickets for help on using tickets.