In recent versions WP_UnitTestCase
has included a $factory
property.
For example:
$post = $this->factory->post->create();
Where can I find documentation on this useful feature?
In recent versions WP_UnitTestCase
has included a $factory
property.
For example:
$post = $this->factory->post->create();
Where can I find documentation on this useful feature?
You must be logged in to post a comment.
As far as I know, there is no documentation for it at present. The official source is here.
I have also written a tutorial on unit testing WordPress plugins, which gives some detail about this feature.
I think I’ll mention this to the WordPress docs team. Maybe we can get this stuff into the plugin and theme handbooks.
Update (June 20, 2015): You can also create your own custom factories!
Update (September 27, 2016): In WordPress 4.4 the tests were updated to provide a static
factory()
method for accessing the factories, although thefactory
property is still provided via a magic getter.The source code at
https://github.com/rnagle/wordpress-unit-tests/blob/master/includes/factory.php
seems to be the best place to look at the moment