[wp-trac] [WordPress Trac] #37630: WP_UnitTest_Factory_For_Attachment method for 'create' is not implemented
WordPress Trac
noreply at wordpress.org
Wed Aug 10 19:54:57 UTC 2016
#37630: WP_UnitTest_Factory_For_Attachment method for 'create' is not implemented
------------------------------+-----------------------------
Reporter: bcole808 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Build/Test Tools | Version: trunk
Severity: normal | Keywords:
Focuses: |
------------------------------+-----------------------------
With most of the unit test factories, it is possible to create test
objects like this:
{{{
$this->factory->post->create();
$this->factory->user->create();
$this->factory->comment->create();
}}}
However, if you try to use the Attachment factory in the same way, it will
cause an error like this:
{{{
$this->factory->attachment->create();
// strpos() expects parameter 1 to be string, array given
// ...../wp-includes/post.php:256
}}}
I found that the cause of this error is because the method signature in
the Attachment factory to create objects differs from that of the other
factories:
{{{
// WP_UnitTest_Factory_For_Thing
abstract function create_object( $args );
// WP_UnitTest_Factory_For_Attachment
function create_object( $file, $parent = 0, $args = array() )
}}}
And so the parameters end up being incorrect when using Create.
One possible solution could be to implement the Create method (and
possibly others, such as create_and_get, create_many, etc) so that they
accept the different parameters required by the Attachment factory. (I
have attached a patch with a possible implementation of Create)
Another possible solution could be to re-factor the Attachment factory so
it uses the same method signature as it's parent class, but that would be
more complex as tests currently rely on it as-is.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/37630>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list