From 262929004dad7a77cd88985441ddb39dc6f7cfc9 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 15 Aug 2014 15:40:48 +0000 Subject: [PATCH] Avoid undefined index notices in WP_UnitTestCase::_restore_hooks(). props kevinlangleyjr. fixes #29123. git-svn-id: https://develop.svn.wordpress.org/trunk@29503 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/testcase.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index ba66439798..1e8ea11bc6 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -67,10 +67,11 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { } /** - * Saves the action and filter-related globals so they can be restored later + * Saves the action and filter-related globals so they can be restored later. * * Stores $merged_filters, $wp_actions, $wp_current_filter, and $wp_filter - * on a class variable so they can be restored on tearDown() using _restore_hooks() + * on a class variable so they can be restored on tearDown() using _restore_hooks(). + * * @global array $merged_filters * @global array $wp_actions * @global array $wp_current_filter @@ -86,8 +87,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { /** * Restores the hook-related globals to their state at setUp() - * - * so that future tests aren't affected by hooks set during this last test + * so that future tests aren't affected by hooks set during this last test. * * @global array $merged_filters * @global array $wp_actions @@ -95,10 +95,12 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { * @global array $wp_filter * @return void */ - protected function _restore_hooks(){ + protected function _restore_hooks() { $globals = array( 'merged_filters', 'wp_actions', 'wp_current_filter', 'wp_filter' ); foreach ( $globals as $key ) { - $GLOBALS[ $key ] = self::$hooks_saved[ $key ]; + if ( isset( self::$hooks_saved[ $key ] ) ) { + $GLOBALS[ $key ] = self::$hooks_saved[ $key ]; + } } }