Skip to:
Content

BuddyPress.org

#7620 closed enhancement (fixed)

Update shared fixture architecture for WP 4.4+

Reported by: boonebgorges Owned by: netweb
Milestone: 3.0 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords:
Cc:

Description

WordPress 4.4 saw some changes in the way shared fixtures are handled. The summary:

  1. The factory should be fetched using self::factory() rather than $this->factory. This allows better consistency in iterators across all tests.
  2. Shared fixtures should be created in wpSetUpBeforeClass() rather than setUpBeforeClass(), and should use the $factory object passed to the method. (This also helps to keep incrementors synced.)
  3. There's no longer a need to clean up core data (posts, users, etc) in tearDownAfterClass() - WP does it automatically, using _delete_all_data(). At the very least, we can take advantage of this. We might also consider implementing our own version of the same thing.

Change History (6)

#1 @boonebgorges
23 months ago

In 11734:

Ensure that BP_UnitTestCase calls WP's setUpBeforeClass().

WordPress 4.4 introduced wpSetUpBeforeClass(), but in order for
it to be invoked, we have to call WP's setUpBeforeClass() method when
we override it.

See #7620.

#2 @boonebgorges
23 months ago

In 11736:

Implement factory() method for BP_UnitTestCase.

This method, present in WP since 4.4, allows static test methods to use
the same factory object as non-static methods. This in turn ensures that
iterators are kept consistent across a test run.

See #7620.

#3 @boonebgorges
23 months ago

In 11737:

Use static factory method throughout PHPUnit tests.

See #7620.

#4 @boonebgorges
23 months ago

In 11739:

Ensure that shared user fixtures are fully cleaned up.

It's not possible to inherit WP 4.4's user cleanup between tests, because
the the deletion routine runs after the core test suite has unhooked
certain actions (such as BP's that are hooked to delete_user). So
we are forced to run necessary cleanup tasks in our own delete_user()
method, and ensure that it's this method that is called in every case
where we're cleaning up after statically generated shared fixtures.
Otherwise leftover content in the activity table can leak to other
tests.

See #7620.

#5 @boonebgorges
23 months ago

The quirks in our own API and the way that WP handle shared fixtures may mean that it's not possible to inherit the cleanup routines (wpTearDownAfterClass()) that WP has in place. We can still look into mass-deleting our own content, similar to _delete_all_data(), but this needs more attention that I can't devote at the moment.

#6 @DJPaul
20 months ago

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

Since there was work done against this, I'm going to mark it complete as we can track progress.
Future improvements can be documented and implemented as/when a contributor is interested.

Note: See TracTickets for help on using tickets.