Make WordPress Core

Opened 22 months ago

Last modified 22 months ago

#56740 new enhancement

set_up_before_class() / wpSetUpBeforeClass() are inconsistent and confusing

Reported by: iandunn's profile iandunn Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.4
Component: Build/Test Tools Keywords:
Focuses: Cc:


There was some discussion in #55918 about standardizing on either set_up_before_class()/set_up_after_class() or wpSetUpBeforeClass()/wpSetUpAfterClass(). That would bring consistency, and help reduce the confusion that exists around those functions. That applies to the tear down functions as well.

See comment:7:ticket:55918 (and replies to it)

The wp... variants were introduced in r35186.

If a change is made here (and probably even if one isn't), it'd be good to update the handbook page to explain which functions folks should use, and any caveats.

Change History (2)

This ticket was mentioned in Slack in #core-test by iandunn. View the logs.

22 months ago

#2 @SergeyBiryukov
22 months ago

Some context from #55918:

  • wpSetUpBeforeClass() / wpTearDownAfterClass() should not be confused with the native PHPUnit methods that need to be replaced with WordPress' snake_case counterparts, as the tests would not pass across all supported PHP and PHPUnit versions otherwise:
    • setUpBeforeClass() (native PHPUnit method) → set_up_before_class() (WP method)
    • tearDownAfterClass() (native PHPUnit method) → tear_down_after_class() (WP method)
  • wpSetUpBeforeClass() / wpTearDownAfterClass() are used much more often in the test suite, though it should be possible to standardize on set_up_before_class() / tear_down_after_class() instead if that's preferred.
  • The main differences from set_up_before_class() / tear_down_after_class():
    • wpSetUpBeforeClass() receives the $factory argument for ease of use.
    • Both wpSetUpBeforeClass() and wpTearDownAfterClass() don't need to call self::commit_transaction().
  • At a glance, in the current test suite:
    • wpSetUpBeforeClass() / wpTearDownAfterClass() are used when the $factory argument is utilized.
    • set_up_before_class() / tear_down_after_class() are used when the $factory argument is not needed, for example to include some files.
Note: See TracTickets for help on using tickets.