Change History (7)

We'll need to consider only setting up these fixtures when WP_RUN_CORE_TESTS is true, or to introduce a means of plugins/themes that use the test suite to opt in to these fixtures, otherwise this has a high chance of breaking existing plugin/theme tests that count the number of users on the site.

The patch above is a quick and dirty proof of concept that the approach outlined in the ticket could work, and that it would not require too many changes.

But it brings a few things to light:

I imagine the fixture creation to happen in a class, which is accessible in the same way in WP_UnitTestCase as the factory. So to use a shared user fixture in a test, you could to self::fixtures()->user->get_contributor() or similar.

Currently a lot of tests are opaque because there is already a user in the database. This could be made more transparent by using something like self::fixtures()->user->get_count() when counting users returned by queries for example.

There are a lot of user fixture creations in tests related to roles. So the test just needs a users with a particular role, often to check access rights. The shared fixtures could speed up tests significantly by just pulling a user object from memory.

We would need to fill out all user fields with dummy data, so that tests that need things like the nice name or similar could work.

I do think this is probably worth integrating into the test suite, but I'm curious to hear more feedback on this.