diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php index 1a8720af08..5e03f077b6 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php @@ -85,6 +85,11 @@ class WP_UnitTest_Factory_For_Term extends WP_UnitTest_Factory_For_Thing { */ public function create_and_get( $args = array(), $generation_definitions = null ) { $term_id = $this->create( $args, $generation_definitions ); + + if ( is_wp_error( $term_id ) ) { + return $term_id; + } + $taxonomy = isset( $args['taxonomy'] ) ? $args['taxonomy'] : $this->taxonomy; return get_term( $term_id, $taxonomy ); } diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php index b526098194..2ae24a1f95 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php @@ -79,6 +79,11 @@ abstract class WP_UnitTest_Factory_For_Thing { */ public function create_and_get( $args = array(), $generation_definitions = null ) { $object_id = $this->create( $args, $generation_definitions ); + + if ( is_wp_error( $object_id ) ) { + return $object_id; + } + return $this->get_object_by_id( $object_id ); }