From f3a268f58c7e5cbf0a5ae7125483663892606c4f Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Mon, 23 Sep 2019 18:54:16 +0000 Subject: [PATCH] Build/Test tools: Ensure the `create_and_get()` factory method returns the appropriate WP_Error when creating a term fails. Fixes: #47952 git-svn-id: https://develop.svn.wordpress.org/trunk@46262 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/factory/class-wp-unittest-factory-for-term.php | 5 +++++ .../includes/factory/class-wp-unittest-factory-for-thing.php | 5 +++++ 2 files changed, 10 insertions(+) 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 ); }