Skip to:

Opened 7 years ago

Closed 6 years ago

Last modified 4 years ago

#7620 closed enhancement (fixed)

Update shared fixture architecture for WP 4.4+

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


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 (7)

#1 @boonebgorges
7 years 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
7 years 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
7 years ago

In 11737:

Use static factory method throughout PHPUnit tests.

See #7620.

#4 @boonebgorges
7 years 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

See #7620.

#5 @boonebgorges
7 years 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
6 years 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.

#7 @architect7
4 years ago

WP 4.4's cannot be inherited with user cleanup between tests, because
all test methods are static.
The deletion process only runs after the main test suite has been unlinked from
certain actions.
To run necessary cleanup tasks in our own delete_user()
method, toy must ensure that it's the method is called in every case.

And Speaking of Architecture, we do have a client of ours that is a real life Architect they carry out Link: Architecture drawings in Primrose Hill Check them out.

Note: See TracTickets for help on using tickets.